1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.vectomatic.svg.edit.client.command;
19
20 import java.util.List;
21
22 import org.vectomatic.svg.edit.client.SvgrealApp;
23 import org.vectomatic.svg.edit.client.engine.SVGModel;
24 import org.vectomatic.svg.edit.client.event.SelectionChangedProcessor;
25 import org.vectomatic.svg.edit.client.gxt.widget.CommandFactoryMenuItem;
26 import org.vectomatic.svg.edit.client.model.ModelConstants;
27 import org.vectomatic.svg.edit.client.model.svg.SVGElementModel;
28 import org.vectomatic.svg.edit.client.model.svg.SVGNamedElementModel;
29
30 import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
31 import com.extjs.gxt.ui.client.util.Format;
32 import com.google.gwt.core.client.GWT;
33
34
35
36
37
38 public class RemoveElementsCommandFactory extends CommandFactoryBase implements SelectionChangedProcessor<SVGElementModel> {
39 @SuppressWarnings("serial")
40 public static final IFactoryInstantiator<RemoveElementsCommandFactory> INSTANTIATOR = new FactoryInstantiatorBase<RemoveElementsCommandFactory>(ModelConstants.INSTANCE.removeElementsCmdFactory(), ModelConstants.INSTANCE.removeElementsCmdFactoryDesc()) {
41 @Override
42 public RemoveElementsCommandFactory create() {
43 return new RemoveElementsCommandFactory();
44 }
45 };
46
47 @Override
48 public IFactoryInstantiator<?> getInstantiator() {
49 return INSTANTIATOR;
50 }
51
52 @Override
53 public void start(Object requester) {
54 GWT.log("RemoveElementsCommandFactory.start(" + requester + ")");
55 SVGModel svgModel = SvgrealApp.getApp().getActiveModel();
56 if (requester instanceof SVGModel || requester instanceof CommandFactoryMenuItem) {
57
58
59 createCommand(svgModel);
60 return;
61 }
62 super.start(requester);
63
64
65
66 if (svgModel != null) {
67 svgModel.getSelectionModel().deselectAll();
68 }
69
70
71 updateStatus(ModelConstants.INSTANCE.removeElementsCmdFactory1());
72 }
73
74 @Override
75 public boolean processSelectionChanged(SelectionChangedEvent<SVGElementModel> se) {
76 List<SVGElementModel> models = se.getSelection();
77 GWT.log("RemoveElementsCommandFactory.processSelectionChanged: " + models);
78 if (models.size() > 0) {
79 createCommand(models.get(0).getOwner());
80 return true;
81 }
82 return false;
83 }
84
85 private void createCommand(SVGModel svgModel) {
86 GWT.log("RemoveElementsCommandFactory.createCommand(" + svgModel + ")");
87 if (svgModel != null) {
88 List<SVGElementModel> models = svgModel.getSelectionModel().getSelectedItems();
89
90 models.remove(svgModel.getViewBox());
91 if (models.size() > 0) {
92 GenericRemoveCommand command = new GenericRemoveCommand(this, models, Format.substitute(ModelConstants.INSTANCE.removeCmd(), SVGNamedElementModel.getNames(models)));
93 command.commit();
94 svgModel.getCommandStore().addCommand(command);
95 }
96 }
97 }
98 }