Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2011-06-15 03:45:54 -0400
committerHenrik Rentz-Reichert2011-06-15 03:45:54 -0400
commitfa4664b19551aa4de662cf07a7f5a039f69ba646 (patch)
treea08ede7b2a6fe36a6a3414eb7ff825733b70fc74 /plugins/org.eclipse.etrice.ui.structure
parenta095f3601e18573f3c59bdd19f177ec9c7bfa554 (diff)
downloadorg.eclipse.etrice-fa4664b19551aa4de662cf07a7f5a039f69ba646.tar.gz
org.eclipse.etrice-fa4664b19551aa4de662cf07a7f5a039f69ba646.tar.xz
org.eclipse.etrice-fa4664b19551aa4de662cf07a7f5a039f69ba646.zip
[ui.structure/common] factored out common code
Diffstat (limited to 'plugins/org.eclipse.etrice.ui.structure')
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java4
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramTypeProvider.java14
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ProviderDispatcher.java2
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateCommand.java54
-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.java148
6 files changed, 9 insertions, 234 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 328907a14..2861cad51 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
@@ -16,8 +16,8 @@ package org.eclipse.etrice.ui.structure;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.etrice.ui.common.DiagramAccessBase;
+import org.eclipse.etrice.ui.common.commands.UpdateCommand;
import org.eclipse.etrice.ui.structure.commands.PopulateDiagramCommand;
-import org.eclipse.etrice.ui.structure.commands.UpdateCommand;
import org.eclipse.etrice.ui.structure.editor.StructureEditor;
import org.eclipse.graphiti.mm.pictograms.Diagram;
@@ -50,7 +50,7 @@ public class DiagramAccess extends DiagramAccessBase {
*/
@Override
protected Command getUpdateCommand(Diagram diagram, TransactionalEditingDomain editingDomain) {
- UpdateCommand cmd = new UpdateCommand(diagram, editingDomain);
+ UpdateCommand cmd = new UpdateCommand(diagram, editingDomain, DiagramTypeProvider.PROVIDER_ID);
if (cmd.updateNeeded())
return cmd;
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramTypeProvider.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramTypeProvider.java
index ebdf9da9d..5f414d141 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramTypeProvider.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramTypeProvider.java
@@ -12,22 +12,20 @@
package org.eclipse.etrice.ui.structure;
-import org.eclipse.core.runtime.preferences.DefaultScope;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.etrice.core.ui.RoomUiModule;
import org.eclipse.graphiti.dt.AbstractDiagramTypeProvider;
-import org.eclipse.graphiti.internal.GraphitiPlugin;
-import org.eclipse.graphiti.internal.pref.GFPreferences;
import org.eclipse.graphiti.tb.IToolBehaviorProvider;
import org.eclipse.xtext.scoping.IScopeProvider;
import com.google.inject.Inject;
import com.google.inject.Injector;
-@SuppressWarnings("restriction")
+//@SuppressWarnings("restriction")
public class DiagramTypeProvider extends AbstractDiagramTypeProvider {
private static final boolean USE_AUTO_UPDATE = true;
+
+ public static final String PROVIDER_ID = "org.eclipse.etrice.ui.structure.diagramTypeProvider";
private IToolBehaviorProvider[] toolBehaviorProviders;
private ProviderDispatcher dispatcher;
@@ -44,9 +42,9 @@ public class DiagramTypeProvider extends AbstractDiagramTypeProvider {
dispatcher = new ProviderDispatcher(this);
setFeatureProvider(dispatcher.getFeatureProvider());
- IEclipsePreferences node = new DefaultScope().getNode(GraphitiPlugin.PLUGIN_ID);
- if (node!=null)
- node.putBoolean(GFPreferences.RECURSIVE_CHECK_FOR_UPDATE_ACTIVE, true);
+// IEclipsePreferences node = new DefaultScope().getNode(GraphitiPlugin.PLUGIN_ID);
+// if (node!=null)
+// node.putBoolean(GFPreferences.RECURSIVE_CHECK_FOR_UPDATE_ACTIVE, true);
}
@Override
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ProviderDispatcher.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ProviderDispatcher.java
index 6f978e306..3a0a5368c 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ProviderDispatcher.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/ProviderDispatcher.java
@@ -16,8 +16,8 @@ import java.util.Arrays;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.naming.RoomFragmentProvider;
+import org.eclipse.etrice.ui.common.support.AutoUpdateFeature;
import org.eclipse.etrice.ui.structure.support.ActorContainerRefSupport;
-import org.eclipse.etrice.ui.structure.support.AutoUpdateFeature;
import org.eclipse.etrice.ui.structure.support.BindingSupport;
import org.eclipse.etrice.ui.structure.support.LayerConnectionSupport;
import org.eclipse.etrice.ui.structure.support.PortSupport;
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
deleted file mode 100644
index 3f1e685e4..000000000
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateCommand.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *******************************************************************************/
-
-package org.eclipse.etrice.ui.structure.commands;
-
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.etrice.ui.behavior.DiagramTypeProvider;
-import org.eclipse.etrice.ui.structure.support.AutoUpdateFeature;
-import org.eclipse.graphiti.dt.IDiagramTypeProvider;
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.context.impl.UpdateContext;
-import org.eclipse.graphiti.mm.pictograms.Diagram;
-import org.eclipse.graphiti.ui.services.GraphitiUi;
-
-/**
- * @author Henrik Rentz-Reichert - initial contribution and API
- *
- */
-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() {
- UpdateContext context = new UpdateContext(diagram);
- 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 904de7ba2..9b3411909 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
@@ -20,7 +20,6 @@ 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 {
@@ -47,24 +46,4 @@ public class StructureEditor extends RoomDiagramEditor {
return null;
}
-
- /* (non-Javadoc)
- * @see org.eclipse.graphiti.ui.internal.editor.DiagramEditorInternal#createPartControl(org.eclipse.swt.widgets.Composite)
- */
- @SuppressWarnings("restriction")
- @Override
- public void createPartControl(Composite parent) {
- // TODO Auto-generated method stub
- super.createPartControl(parent);
-
- /* 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
deleted file mode 100644
index c843de8cf..000000000
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/AutoUpdateFeature.java
+++ /dev/null
@@ -1,148 +0,0 @@
-package org.eclipse.etrice.ui.structure.support;
-
-import java.util.ArrayList;
-
-import org.eclipse.graphiti.features.IFeatureProvider;
-import org.eclipse.graphiti.features.IReason;
-import org.eclipse.graphiti.features.IUpdateFeature;
-import org.eclipse.graphiti.features.context.IUpdateContext;
-import org.eclipse.graphiti.features.context.impl.UpdateContext;
-import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
-import org.eclipse.graphiti.features.impl.Reason;
-import org.eclipse.graphiti.mm.pictograms.Connection;
-import org.eclipse.graphiti.mm.pictograms.ContainerShape;
-import org.eclipse.graphiti.mm.pictograms.Diagram;
-import org.eclipse.graphiti.mm.pictograms.Shape;
-
-/**
- * @author Henrik Rentz-Reichert - initial contribution and API
- *
- */
-public class AutoUpdateFeature extends AbstractUpdateFeature {
-
- public AutoUpdateFeature(IFeatureProvider fp) {
- super(fp);
- }
-
- @Override
- public boolean canUpdate(IUpdateContext context) {
- return true;
- }
-
- @Override
- public IReason updateNeeded(IUpdateContext context) {
- 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
- public boolean update(IUpdateContext context) {
- boolean doneChanges = updateConnections(getDiagram());
-
- if (updateIfNeeded(getDiagram()))
- doneChanges = true;
-
- return doneChanges;
- }
-
- /**
- * This just removes dangling connections (bindings and layer connections).
- * New ones are added by the structure class support.
- *
- * @param diagram
- * @return
- */
- private boolean updateConnections(Diagram diagram) {
- boolean doneChanges = false;
-
- ArrayList<Connection> connections = new ArrayList<Connection>(diagram.getConnections());
- for (Connection conn : connections) {
- UpdateContext context = new UpdateContext(conn);
- IUpdateFeature updateFeature = getFeatureProvider().getUpdateFeature(context);
- if (updateFeature.canUpdate(context))
- if (updateFeature.updateNeeded(context).toBoolean())
- if (updateFeature.update(context))
- doneChanges = true;
- }
- return doneChanges;
- }
-
- /**
- * @param diagram
- * @return
- */
- private boolean updateIfNeeded(ContainerShape container) {
- boolean doneChanges = false;
-
- // first recursion because ref ports might be needed for bindings
- // we need to make a copy since children might be removed
- ArrayList<Shape> children = new ArrayList<Shape>(container.getChildren());
- for (Shape child : children) {
- if (child instanceof ContainerShape)
- if (updateIfNeeded((ContainerShape) child))
- 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