Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2011-06-13 03:24:13 -0400
committerHenrik Rentz-Reichert2011-06-13 03:24:13 -0400
commit69904a6f4538ee910541c5ff4acdf030ca23eabf (patch)
treeb49ea2ac4681d8453f2dece3119777baaf661b79 /plugins
parent125013a7b13166c77542bf44e789b2ee3fc79add (diff)
downloadorg.eclipse.etrice-69904a6f4538ee910541c5ff4acdf030ca23eabf.tar.gz
org.eclipse.etrice-69904a6f4538ee910541c5ff4acdf030ca23eabf.tar.xz
org.eclipse.etrice-69904a6f4538ee910541c5ff4acdf030ca23eabf.zip
[ui.structure] fixes and improvements in auto update mechanism
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java6
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateCommand.java15
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java21
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/AutoUpdateFeature.java84
4 files changed, 104 insertions, 22 deletions
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java
index 232edbc52..328907a14 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java
@@ -50,6 +50,10 @@ public class DiagramAccess extends DiagramAccessBase {
*/
@Override
protected Command getUpdateCommand(Diagram diagram, TransactionalEditingDomain editingDomain) {
- return new UpdateCommand(diagram, editingDomain);
+ UpdateCommand cmd = new UpdateCommand(diagram, editingDomain);
+ if (cmd.updateNeeded())
+ return cmd;
+
+ return null;
}
}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateCommand.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateCommand.java
index 53fc3f257..3f1e685e4 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateCommand.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateCommand.java
@@ -25,22 +25,29 @@ import org.eclipse.graphiti.ui.services.GraphitiUi;
public class UpdateCommand extends RecordingCommand {
private Diagram diagram;
+ private AutoUpdateFeature feature;
public UpdateCommand(Diagram diag, TransactionalEditingDomain domain) {
super(domain);
this.diagram = diag;
+
+ IDiagramTypeProvider dtp = GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram, DiagramTypeProvider.PROVIDER_ID); //$NON-NLS-1$
+ IFeatureProvider featureProvider = dtp.getFeatureProvider();
+
+ feature = new AutoUpdateFeature(featureProvider);
}
+ public boolean updateNeeded() {
+ UpdateContext context = new UpdateContext(diagram);
+ return feature.updateNeeded(context).toBoolean();
+ }
+
/* (non-Javadoc)
* @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
*/
@Override
protected void doExecute() {
- IDiagramTypeProvider dtp = GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram, DiagramTypeProvider.PROVIDER_ID); //$NON-NLS-1$
- IFeatureProvider featureProvider = dtp.getFeatureProvider();
-
UpdateContext context = new UpdateContext(diagram);
- AutoUpdateFeature feature = new AutoUpdateFeature(featureProvider);
feature.update(context);
}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java
index 42c43a735..904de7ba2 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java
@@ -16,11 +16,11 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.ui.common.editor.RoomDiagramEditor;
import org.eclipse.etrice.ui.structure.Activator;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.IEditorInput;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.ui.editor.DiagramEditorInput;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
public class StructureEditor extends RoomDiagramEditor {
@@ -49,13 +49,22 @@ public class StructureEditor extends RoomDiagramEditor {
}
/* (non-Javadoc)
- * @see org.eclipse.graphiti.ui.internal.editor.DiagramEditorInternal#setInput(org.eclipse.ui.IEditorInput)
+ * @see org.eclipse.graphiti.ui.internal.editor.DiagramEditorInternal#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@SuppressWarnings("restriction")
@Override
- protected void setInput(IEditorInput input) {
- super.setInput(input);
+ public void createPartControl(Composite parent) {
+ // TODO Auto-generated method stub
+ super.createPartControl(parent);
- doSave(null);
+ /* we have to save here whether changes have been done or not to get rid of the dirty state
+ * CAUTION: save in
+ * init(IEditorSite site, IEditorInput input)
+ * or
+ * setInput(IEditorInput input)
+ * did not work correctly
+ */
+// if (AutoUpdateFeature.isLastDoneChanges())
+ doSave(null);
}
}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/AutoUpdateFeature.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/AutoUpdateFeature.java
index be50adc21..a957a91c4 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/AutoUpdateFeature.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/AutoUpdateFeature.java
@@ -20,8 +20,18 @@ import org.eclipse.graphiti.mm.pictograms.Shape;
*/
public class AutoUpdateFeature extends AbstractUpdateFeature {
+ private static boolean lastDoneChanges;
+
+ /**
+ * @return the lastDoneChanges
+ */
+ public static boolean isLastDoneChanges() {
+ return lastDoneChanges;
+ }
+
public AutoUpdateFeature(IFeatureProvider fp) {
super(fp);
+ lastDoneChanges = false;
}
@Override
@@ -31,7 +41,57 @@ public class AutoUpdateFeature extends AbstractUpdateFeature {
@Override
public IReason updateNeeded(IUpdateContext context) {
- return Reason.createFalseReason();
+ boolean needed = updateConnectionsNeeded(getDiagram());
+
+ if (updateNeeded(getDiagram()))
+ needed = true;
+
+ return new Reason(needed);
+ }
+
+ /**
+ * This just removes dangling connections (bindings and layer connections).
+ * New ones are added by the structure class support.
+ *
+ * @param diagram
+ * @return
+ */
+ private boolean updateConnectionsNeeded(Diagram diagram) {
+ boolean needed = false;
+
+ for (Connection conn : new ArrayList<Connection>(diagram.getConnections())) {
+ UpdateContext context = new UpdateContext(conn);
+ IUpdateFeature updateFeature = getFeatureProvider().getUpdateFeature(context);
+ if (updateFeature.canUpdate(context))
+ if (updateFeature.updateNeeded(context).toBoolean())
+ needed = true;
+ }
+ return needed;
+ }
+
+ /**
+ * @param diagram
+ * @return
+ */
+ private boolean updateNeeded(ContainerShape container) {
+ boolean needed = false;
+
+ for (Shape child : new ArrayList<Shape>(container.getChildren())) {
+ if (child instanceof ContainerShape)
+ if (updateNeeded((ContainerShape) child))
+ needed = true;
+ }
+
+ // avoid infinite recursion by not entering with diagram again
+ if (!(container instanceof Diagram)) {
+ UpdateContext context = new UpdateContext(container);
+ IUpdateFeature updateFeature = getFeatureProvider().getUpdateFeature(context);
+ if (updateFeature.canUpdate(context))
+ if (updateFeature.updateNeeded(context).toBoolean())
+ needed = true;
+ }
+
+ return needed;
}
@Override
@@ -41,10 +101,9 @@ public class AutoUpdateFeature extends AbstractUpdateFeature {
if (updateIfNeeded(getDiagram()))
doneChanges = true;
- if (doneChanges)
- return true;
-
- return false;
+ lastDoneChanges = doneChanges;
+
+ return doneChanges;
}
/**
@@ -85,12 +144,15 @@ public class AutoUpdateFeature extends AbstractUpdateFeature {
doneChanges = true;
}
- UpdateContext context = new UpdateContext(container);
- IUpdateFeature updateFeature = getFeatureProvider().getUpdateFeature(context);
- if (updateFeature.canUpdate(context))
- if (updateFeature.updateNeeded(context).toBoolean())
- if (updateFeature.update(context))
- doneChanges = true;
+ // avoid infinite recursion by not entering with diagram again
+ if (!(container instanceof Diagram)) {
+ UpdateContext context = new UpdateContext(container);
+ IUpdateFeature updateFeature = getFeatureProvider().getUpdateFeature(context);
+ if (updateFeature.canUpdate(context))
+ if (updateFeature.updateNeeded(context).toBoolean())
+ if (updateFeature.update(context))
+ doneChanges = true;
+ }
return doneChanges;
}

Back to the top