Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
WizNavigable |
|
| 4.666666666666667;4.667 |
1 | /* $Id: WizNavigable.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 | * tfmorris | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 1996-2006 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 java.util.ArrayList; | |
42 | import java.util.List; | |
43 | ||
44 | import javax.swing.JPanel; | |
45 | ||
46 | import org.apache.log4j.Logger; | |
47 | import org.argouml.cognitive.ui.WizStepChoice; | |
48 | import org.argouml.i18n.Translator; | |
49 | import org.argouml.model.Model; | |
50 | ||
51 | /** | |
52 | * A non-modal wizard to help the user change navigability | |
53 | * of an association. | |
54 | */ | |
55 | public class WizNavigable extends UMLWizard { | |
56 | /** | |
57 | * Logger. | |
58 | */ | |
59 | 0 | private static final Logger LOG = Logger.getLogger(WizNavigable.class); |
60 | ||
61 | 0 | private String instructions = |
62 | Translator.localize("critics.WizNavigable-ins"); | |
63 | 0 | private String option0 = |
64 | Translator.localize("critics.WizNavigable-option1"); | |
65 | 0 | private String option1 = |
66 | Translator.localize("critics.WizNavigable-option2"); | |
67 | 0 | private String option2 = |
68 | Translator.localize("critics.WizNavigable-option3"); | |
69 | ||
70 | 0 | private WizStepChoice step1 = null; |
71 | ||
72 | /** | |
73 | * The constructor. | |
74 | * | |
75 | */ | |
76 | 0 | public WizNavigable() { } |
77 | ||
78 | /** | |
79 | * @return the options | |
80 | */ | |
81 | public List<String> getOptions() { | |
82 | 0 | List<String> result = new ArrayList<String>(); |
83 | 0 | Object asc = getModelElement(); |
84 | 0 | Object ae0 = |
85 | new ArrayList(Model.getFacade().getConnections(asc)).get(0); | |
86 | 0 | Object ae1 = |
87 | new ArrayList(Model.getFacade().getConnections(asc)).get(1); | |
88 | 0 | Object cls0 = Model.getFacade().getType(ae0); |
89 | 0 | Object cls1 = Model.getFacade().getType(ae1); |
90 | ||
91 | 0 | if (cls0 != null && !"".equals(Model.getFacade().getName(cls0))) { |
92 | 0 | option0 = Translator.localize("critics.WizNavigable-option4") |
93 | + Model.getFacade().getName(cls0); | |
94 | } | |
95 | ||
96 | 0 | if (cls1 != null && !"".equals(Model.getFacade().getName(cls1))) { |
97 | 0 | option1 = Translator.localize("critics.WizNavigable-option5") |
98 | + Model.getFacade().getName(cls1); | |
99 | } | |
100 | ||
101 | 0 | result.add(option0); |
102 | 0 | result.add(option1); |
103 | 0 | result.add(option2); |
104 | 0 | return result; |
105 | } | |
106 | ||
107 | /** | |
108 | * @param s the instructions | |
109 | */ | |
110 | 0 | public void setInstructions(String s) { instructions = s; } |
111 | ||
112 | /* | |
113 | * @see org.argouml.cognitive.ui.Wizard#makePanel(int) | |
114 | */ | |
115 | public JPanel makePanel(int newStep) { | |
116 | 0 | switch (newStep) { |
117 | case 1: | |
118 | 0 | if (step1 == null) { |
119 | 0 | step1 = new WizStepChoice(this, instructions, getOptions()); |
120 | 0 | step1.setTarget(getToDoItem()); |
121 | } | |
122 | 0 | return step1; |
123 | } | |
124 | 0 | return null; |
125 | } | |
126 | ||
127 | /* | |
128 | * @see org.argouml.cognitive.ui.Wizard#doAction(int) | |
129 | */ | |
130 | public void doAction(int oldStep) { | |
131 | 0 | LOG.debug("doAction " + oldStep); |
132 | 0 | switch (oldStep) { |
133 | case 1: | |
134 | 0 | int choice = -1; |
135 | 0 | if (step1 != null) { |
136 | 0 | choice = step1.getSelectedIndex(); |
137 | } | |
138 | 0 | if (choice == -1) { |
139 | 0 | throw new Error("nothing selected, should not get here"); |
140 | } | |
141 | try { | |
142 | 0 | Object asc = getModelElement(); |
143 | 0 | Object ae0 = |
144 | new ArrayList(Model.getFacade().getConnections(asc)).get(0); | |
145 | 0 | Object ae1 = |
146 | new ArrayList(Model.getFacade().getConnections(asc)).get(1); | |
147 | 0 | Model.getCoreHelper().setNavigable(ae0, |
148 | choice == 0 || choice == 2); | |
149 | 0 | Model.getCoreHelper().setNavigable(ae1, |
150 | choice == 1 || choice == 2); | |
151 | 0 | } catch (Exception pve) { |
152 | 0 | LOG.error("could not set navigablity", pve); |
153 | 0 | } |
154 | } | |
155 | 0 | } |
156 | ||
157 | /* | |
158 | * @see org.argouml.cognitive.ui.Wizard#canFinish() | |
159 | */ | |
160 | @Override | |
161 | public boolean canFinish() { | |
162 | 0 | if (!super.canFinish()) { |
163 | 0 | return false; |
164 | } | |
165 | 0 | if (getStep() == 0) { |
166 | 0 | return true; |
167 | } | |
168 | 0 | if (getStep() == 1 && step1 != null && step1.getSelectedIndex() != -1) { |
169 | 0 | return true; |
170 | } | |
171 | 0 | return false; |
172 | } | |
173 | ||
174 | /** | |
175 | * The UID. | |
176 | */ | |
177 | private static final long serialVersionUID = 2571165058454693999L; | |
178 | } /* end class WizNavigable */ |