| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
package org.argouml.uml.diagram.ui; |
| 40 | |
|
| 41 | |
import java.awt.event.ActionEvent; |
| 42 | |
import java.util.ArrayList; |
| 43 | |
import java.util.Collection; |
| 44 | |
import java.util.List; |
| 45 | |
|
| 46 | |
import javax.swing.Action; |
| 47 | |
|
| 48 | |
import org.argouml.i18n.Translator; |
| 49 | |
import org.argouml.model.Model; |
| 50 | |
import org.tigris.gef.base.Editor; |
| 51 | |
import org.tigris.gef.base.Globals; |
| 52 | |
import org.tigris.gef.base.Selection; |
| 53 | |
import org.tigris.gef.presentation.Fig; |
| 54 | |
import org.argouml.ui.UndoableAction; |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
public class ActionCompartmentDisplay extends UndoableAction { |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | 0 | private boolean display = false; |
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
private int cType; |
| 80 | |
|
| 81 | |
private static final int COMPARTMENT_ATTRIBUTE = 1; |
| 82 | |
private static final int COMPARTMENT_OPERATION = 2; |
| 83 | |
private static final int COMPARTMENT_EXTENSIONPOINT = 4; |
| 84 | |
private static final int COMPARTMENT_ENUMLITERAL = 8; |
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | 0 | private static final UndoableAction SHOW_ATTR_COMPARTMENT = |
| 91 | |
new ActionCompartmentDisplay(true, |
| 92 | |
"action.show-attribute-compartment", COMPARTMENT_ATTRIBUTE); |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | 0 | private static final UndoableAction HIDE_ATTR_COMPARTMENT = |
| 98 | |
new ActionCompartmentDisplay(false, |
| 99 | |
"action.hide-attribute-compartment", COMPARTMENT_ATTRIBUTE); |
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | 0 | private static final UndoableAction SHOW_OPER_COMPARTMENT = |
| 105 | |
new ActionCompartmentDisplay(true, |
| 106 | |
"action.show-operation-compartment", COMPARTMENT_OPERATION); |
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | 0 | private static final UndoableAction HIDE_OPER_COMPARTMENT = |
| 112 | |
new ActionCompartmentDisplay(false, |
| 113 | |
"action.hide-operation-compartment", COMPARTMENT_OPERATION); |
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | 0 | private static final UndoableAction SHOW_EXTPOINT_COMPARTMENT = |
| 120 | |
new ActionCompartmentDisplay(true, |
| 121 | |
"action.show-extension-point-compartment", |
| 122 | |
COMPARTMENT_EXTENSIONPOINT); |
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | 0 | private static final UndoableAction HIDE_EXTPOINT_COMPARTMENT = |
| 129 | |
new ActionCompartmentDisplay(false, |
| 130 | |
"action.hide-extension-point-compartment", |
| 131 | |
COMPARTMENT_EXTENSIONPOINT); |
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | 0 | private static final UndoableAction SHOW_ALL_COMPARTMENTS = |
| 137 | |
new ActionCompartmentDisplay(true, "action.show-all-compartments", |
| 138 | |
COMPARTMENT_ATTRIBUTE |
| 139 | |
| COMPARTMENT_OPERATION |
| 140 | |
| COMPARTMENT_ENUMLITERAL); |
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | 0 | private static final UndoableAction HIDE_ALL_COMPARTMENTS = |
| 146 | |
new ActionCompartmentDisplay(false, "action.hide-all-compartments", |
| 147 | |
COMPARTMENT_ATTRIBUTE |
| 148 | |
| COMPARTMENT_OPERATION |
| 149 | |
| COMPARTMENT_ENUMLITERAL); |
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | 0 | private static final UndoableAction SHOW_ENUMLITERAL_COMPARTMENT = |
| 156 | |
new ActionCompartmentDisplay(true, |
| 157 | |
"action.show-enumeration-literal-compartment", |
| 158 | |
COMPARTMENT_ENUMLITERAL); |
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | 0 | private static final UndoableAction HIDE_ENUMLITERAL_COMPARTMENT = |
| 165 | |
new ActionCompartmentDisplay(false, |
| 166 | |
"action.hide-enumeration-literal-compartment", |
| 167 | |
COMPARTMENT_ENUMLITERAL); |
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
protected ActionCompartmentDisplay(boolean d, String c, int type) { |
| 182 | 0 | super(Translator.localize(c)); |
| 183 | 0 | display = d; |
| 184 | 0 | cType = type; |
| 185 | 0 | } |
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
public static Collection<Action> getActions() { |
| 196 | 0 | Collection<Action> actions = new ArrayList<Action>(); |
| 197 | 0 | Editor ce = Globals.curEditor(); |
| 198 | |
|
| 199 | 0 | int present = 0; |
| 200 | 0 | int visible = 0; |
| 201 | |
|
| 202 | 0 | boolean operPresent = false; |
| 203 | 0 | boolean operVisible = false; |
| 204 | |
|
| 205 | 0 | boolean attrPresent = false; |
| 206 | 0 | boolean attrVisible = false; |
| 207 | |
|
| 208 | 0 | boolean epPresent = false; |
| 209 | 0 | boolean epVisible = false; |
| 210 | |
|
| 211 | 0 | boolean enumPresent = false; |
| 212 | 0 | boolean enumVisible = false; |
| 213 | |
|
| 214 | 0 | List<Fig> figs = ce.getSelectionManager().getSelectedFigs(); |
| 215 | 0 | for (Fig f : figs) { |
| 216 | 0 | final FigCompartmentBox fcb = (FigCompartmentBox) f; |
| 217 | |
|
| 218 | 0 | final FigCompartment attributeCompartment = |
| 219 | |
fcb.getCompartment(Model.getMetaTypes().getAttribute()); |
| 220 | 0 | if (attributeCompartment != null) { |
| 221 | 0 | present++; |
| 222 | 0 | attrPresent = true; |
| 223 | 0 | attrVisible = attributeCompartment.isVisible(); |
| 224 | 0 | if (attrVisible) { |
| 225 | 0 | visible++; |
| 226 | |
} |
| 227 | |
} |
| 228 | 0 | final FigCompartment operationCompartment = |
| 229 | |
fcb.getCompartment(Model.getMetaTypes().getOperation()); |
| 230 | 0 | if (operationCompartment != null) { |
| 231 | 0 | present++; |
| 232 | 0 | operPresent = true; |
| 233 | 0 | operVisible = operationCompartment.isVisible(); |
| 234 | 0 | if (operVisible) { |
| 235 | 0 | visible++; |
| 236 | |
} |
| 237 | |
} |
| 238 | 0 | final FigCompartment epCompartment = |
| 239 | |
fcb.getCompartment(Model.getMetaTypes().getExtensionPoint()); |
| 240 | 0 | if (epCompartment != null) { |
| 241 | 0 | present++; |
| 242 | 0 | epPresent = true; |
| 243 | 0 | epVisible = epCompartment.isVisible(); |
| 244 | 0 | if (epVisible) { |
| 245 | 0 | visible++; |
| 246 | |
} |
| 247 | |
} |
| 248 | 0 | final FigCompartment elCompartment = |
| 249 | |
fcb.getCompartment(Model.getMetaTypes().getEnumerationLiteral()); |
| 250 | 0 | if (elCompartment != null) { |
| 251 | 0 | present++; |
| 252 | 0 | enumPresent = true; |
| 253 | 0 | enumVisible = elCompartment.isVisible(); |
| 254 | 0 | if (enumVisible) { |
| 255 | 0 | visible++; |
| 256 | |
} |
| 257 | |
} |
| 258 | 0 | } |
| 259 | |
|
| 260 | |
|
| 261 | 0 | if (present > 1) { |
| 262 | 0 | if (visible > 0) { |
| 263 | 0 | actions.add(HIDE_ALL_COMPARTMENTS); |
| 264 | |
} |
| 265 | 0 | if (present - visible > 0) { |
| 266 | 0 | actions.add(SHOW_ALL_COMPARTMENTS); |
| 267 | |
} |
| 268 | |
} |
| 269 | |
|
| 270 | 0 | if (attrPresent) { |
| 271 | 0 | if (attrVisible) { |
| 272 | 0 | actions.add(HIDE_ATTR_COMPARTMENT); |
| 273 | |
} else { |
| 274 | 0 | actions.add(SHOW_ATTR_COMPARTMENT); |
| 275 | |
} |
| 276 | |
} |
| 277 | |
|
| 278 | 0 | if (enumPresent) { |
| 279 | 0 | if (enumVisible) { |
| 280 | 0 | actions.add(HIDE_ENUMLITERAL_COMPARTMENT); |
| 281 | |
} else { |
| 282 | 0 | actions.add(SHOW_ENUMLITERAL_COMPARTMENT); |
| 283 | |
} |
| 284 | |
} |
| 285 | |
|
| 286 | 0 | if (operPresent) { |
| 287 | 0 | if (operVisible) { |
| 288 | 0 | actions.add(HIDE_OPER_COMPARTMENT); |
| 289 | |
} else { |
| 290 | 0 | actions.add(SHOW_OPER_COMPARTMENT); |
| 291 | |
} |
| 292 | |
} |
| 293 | |
|
| 294 | |
|
| 295 | 0 | if (epPresent) { |
| 296 | 0 | if (epVisible) { |
| 297 | 0 | actions.add(HIDE_EXTPOINT_COMPARTMENT); |
| 298 | |
} else { |
| 299 | 0 | actions.add(SHOW_EXTPOINT_COMPARTMENT); |
| 300 | |
} |
| 301 | |
} |
| 302 | |
|
| 303 | 0 | return actions; |
| 304 | |
} |
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
|
| 315 | |
|
| 316 | |
@Override |
| 317 | |
public void actionPerformed(ActionEvent ae) { |
| 318 | 0 | for (Selection sel : Globals.curEditor().getSelectionManager().getSelections()) { |
| 319 | 0 | final Fig f = sel.getContent(); |
| 320 | |
|
| 321 | |
|
| 322 | 0 | if ((cType & COMPARTMENT_ATTRIBUTE) != 0) { |
| 323 | 0 | final FigCompartmentBox fcb = (FigCompartmentBox) f; |
| 324 | 0 | fcb.showCompartment( |
| 325 | |
Model.getMetaTypes().getAttribute(), |
| 326 | |
display); |
| 327 | |
|
| 328 | |
} |
| 329 | 0 | if ((cType & COMPARTMENT_OPERATION) != 0) { |
| 330 | 0 | final FigCompartmentBox fcb = (FigCompartmentBox) f; |
| 331 | 0 | fcb.showCompartment( |
| 332 | |
Model.getMetaTypes().getOperation(), |
| 333 | |
display); |
| 334 | |
} |
| 335 | |
|
| 336 | 0 | if ((cType & COMPARTMENT_EXTENSIONPOINT) != 0) { |
| 337 | 0 | final FigCompartmentBox fcb = (FigCompartmentBox) f; |
| 338 | 0 | fcb.showCompartment( |
| 339 | |
Model.getMetaTypes().getExtensionPoint(), |
| 340 | |
display); |
| 341 | |
} |
| 342 | 0 | if ((cType & COMPARTMENT_ENUMLITERAL) != 0) { |
| 343 | 0 | final FigCompartmentBox fcb = (FigCompartmentBox) f; |
| 344 | 0 | fcb.showCompartment( |
| 345 | |
Model.getMetaTypes().getEnumerationLiteral(), |
| 346 | |
display); |
| 347 | |
} |
| 348 | 0 | } |
| 349 | 0 | } |
| 350 | |
|
| 351 | |
} |
| 352 | |
|
| 353 | |
|