Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
WizMEName |
|
| 2.5;2.5 |
1 | /* $Id: WizMEName.java 17849 2010-01-12 19:50:34Z linus $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * mvw | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 1996-2007 The Regents of the University of California. All | |
17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
18 | // software and its documentation without fee, and without a written | |
19 | // agreement is hereby granted, provided that the above copyright notice | |
20 | // and this paragraph appear in all copies. This software program and | |
21 | // documentation are copyrighted by The Regents of the University of | |
22 | // California. The software program and documentation are supplied "AS | |
23 | // IS", without any accompanying services from The Regents. The Regents | |
24 | // does not warrant that the operation of the program will be | |
25 | // uninterrupted or error-free. The end-user understands that the program | |
26 | // was developed for research purposes and is advised not to rely | |
27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
38 | ||
39 | package org.argouml.uml.cognitive.critics; | |
40 | ||
41 | import javax.swing.JPanel; | |
42 | ||
43 | import org.apache.log4j.Logger; | |
44 | import org.argouml.cognitive.ui.WizStepTextField; | |
45 | import org.argouml.i18n.Translator; | |
46 | import org.argouml.model.Model; | |
47 | ||
48 | /** | |
49 | * A non-modal wizard to help the user change the name of a | |
50 | * MModelElement to a better name. | |
51 | * | |
52 | * @author jrobbins | |
53 | */ | |
54 | public class WizMEName extends UMLWizard { | |
55 | 900 | private static final Logger LOG = Logger.getLogger(WizMEName.class); |
56 | ||
57 | 47491 | private String instructions = Translator.localize("critics.WizMEName-ins"); |
58 | 47491 | private String label = Translator.localize("label.name"); |
59 | 47491 | private boolean mustEdit = false; |
60 | ||
61 | 47491 | private WizStepTextField step1 = null; |
62 | ||
63 | private String origSuggest; | |
64 | ||
65 | /** | |
66 | * The constructor. | |
67 | * | |
68 | */ | |
69 | 94982 | public WizMEName() { } |
70 | ||
71 | /** | |
72 | * @param s the instructions | |
73 | */ | |
74 | 47491 | public void setInstructions(String s) { instructions = s; } |
75 | ||
76 | /** | |
77 | * @param b if true, then the wizard step needs userinput, | |
78 | * i.e. it must be edited | |
79 | */ | |
80 | 0 | public void setMustEdit(boolean b) { mustEdit = b; } |
81 | ||
82 | /** | |
83 | * Create a new panel for the given step. | |
84 | * | |
85 | * @see org.argouml.cognitive.critics.Wizard#makePanel(int) | |
86 | */ | |
87 | public JPanel makePanel(int newStep) { | |
88 | 0 | switch (newStep) { |
89 | case 1: | |
90 | 0 | if (step1 == null) { |
91 | 0 | step1 = new WizStepTextField(this, instructions, |
92 | label, offerSuggestion()); | |
93 | } | |
94 | 0 | return step1; |
95 | } | |
96 | 0 | return null; |
97 | } | |
98 | ||
99 | /* | |
100 | * @see org.argouml.uml.cognitive.critics.UMLWizard#setSuggestion(java.lang.String) | |
101 | */ | |
102 | public void setSuggestion(String s) { | |
103 | 47491 | origSuggest = s; |
104 | 47491 | super.setSuggestion(s); |
105 | 47491 | } |
106 | ||
107 | ||
108 | /** | |
109 | * Return false if the user has not edited the text and they were required | |
110 | * to. | |
111 | * | |
112 | * @see org.argouml.cognitive.critics.Wizard#canGoNext() | |
113 | */ | |
114 | public boolean canGoNext() { | |
115 | 0 | if (!super.canGoNext()) return false; |
116 | 0 | if (step1 != null) { |
117 | 0 | boolean changed = origSuggest.equals(step1.getText()); |
118 | 0 | if (mustEdit && !changed) return false; |
119 | } | |
120 | 0 | return true; |
121 | } | |
122 | ||
123 | /* | |
124 | * @see org.argouml.cognitive.ui.Wizard#doAction(int) | |
125 | */ | |
126 | public void doAction(int oldStep) { | |
127 | 0 | LOG.debug("doAction " + oldStep); |
128 | 0 | switch (oldStep) { |
129 | case 1: | |
130 | 0 | String newName = getSuggestion(); |
131 | 0 | if (step1 != null) { |
132 | 0 | newName = step1.getText(); |
133 | } | |
134 | try { | |
135 | 0 | Object me = getModelElement(); |
136 | 0 | Model.getCoreHelper().setName(me, newName); |
137 | } | |
138 | 0 | catch (Exception pve) { |
139 | 0 | LOG.error("could not set name", pve); |
140 | 0 | } |
141 | break; | |
142 | } | |
143 | 0 | } |
144 | ||
145 | /** | |
146 | * @return Returns the instructions. | |
147 | */ | |
148 | protected String getInstructions() { | |
149 | 0 | return instructions; |
150 | } | |
151 | } /* end class WizMEName */ |