summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2013-09-07 18:00:41 (EDT)
committerGerrit Code Review @ Eclipse.org2013-09-17 06:33:11 (EDT)
commit200d8310230a2fa66d7c688c4a77e9e0a53f37e2 (patch)
tree84741120125ccd4dd77db0714b444cb0b135a579
parente2254bc8b6afccf1670ac58b4f369e7e2805719c (diff)
downloadorg.eclipse.etrice-200d8310230a2fa66d7c688c4a77e9e0a53f37e2.zip
org.eclipse.etrice-200d8310230a2fa66d7c688c4a77e9e0a53f37e2.tar.gz
org.eclipse.etrice-200d8310230a2fa66d7c688c4a77e9e0a53f37e2.tar.bz2
[ui] Bug 348214 - diagram update on room file rename + diagram reconnectrefs/changes/05/16205/4
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/plugin.xml7
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/DiagramAccess.java2
-rw-r--r--plugins/org.eclipse.etrice.ui.common/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.etrice.ui.common/plugin.xml21
-rw-r--r--plugins/org.eclipse.etrice.ui.common/schema/org.eclipse.etrice.ui.common.refactoring.rename.exsd106
-rw-r--r--plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/DiagramAccessBase.java6
-rw-r--r--plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/commands/ChangeDiagramInputJob.java251
-rw-r--r--plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/RoomDiagramEditor.java30
-rw-r--r--plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/refactoring/DiagramRenameParticipant.java319
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/plugin.xml7
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java14
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateDiagramCommand.java25
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/DiagramRefreshBehavior.java8
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java1
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DiagramUpdateFeature.java44
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java72
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassUpdate.java2
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/CommonUpdateFeature.java5
18 files changed, 881 insertions, 40 deletions
diff --git a/plugins/org.eclipse.etrice.ui.behavior/plugin.xml b/plugins/org.eclipse.etrice.ui.behavior/plugin.xml
index 0273761..50446ae 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/plugin.xml
+++ b/plugins/org.eclipse.etrice.ui.behavior/plugin.xml
@@ -61,5 +61,12 @@
uriExtension="behavior">
</resourceServiceProvider>
</extension>
+ <extension
+ point="org.eclipse.etrice.ui.common.refactoring.rename">
+ <participant
+ diagram_extension="behavior"
+ editor_id="org.eclipse.etrice.ui.behavior.editor.BehaviorEditor">
+ </participant>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/DiagramAccess.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/DiagramAccess.java
index dff38b3..e0103a1 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/DiagramAccess.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/DiagramAccess.java
@@ -33,7 +33,7 @@ public class DiagramAccess extends DiagramAccessBase {
* @see org.eclipse.etrice.ui.common.DiagramAccessBase#getDiagramName(org.eclipse.etrice.core.room.StructureClass)
*/
@Override
- protected String getDiagramName(StructureClass sc) {
+ public String getDiagramName(StructureClass sc) {
return "Behavior of "+sc.getName();
}
diff --git a/plugins/org.eclipse.etrice.ui.common/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.ui.common/META-INF/MANIFEST.MF
index 5df72f3..f6ba312 100644
--- a/plugins/org.eclipse.etrice.ui.common/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.ui.common/META-INF/MANIFEST.MF
@@ -6,7 +6,6 @@ Bundle-Version: 0.4.0.qualifier
Bundle-Vendor: Eclipse eTrice (Incubation)
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.etrice.core.room.ui;bundle-version="0.4.0",
- org.eclipse.core.databinding;bundle-version="1.3.100",
org.eclipse.emf.transaction;bundle-version="1.4.0",
org.eclipse.graphiti;bundle-version="0.8.0",
org.eclipse.ui.ide;bundle-version="3.6.0",
diff --git a/plugins/org.eclipse.etrice.ui.common/plugin.xml b/plugins/org.eclipse.etrice.ui.common/plugin.xml
index d1da795..41f8b59 100644
--- a/plugins/org.eclipse.etrice.ui.common/plugin.xml
+++ b/plugins/org.eclipse.etrice.ui.common/plugin.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
+ <extension-point id="org.eclipse.etrice.ui.common.refactoring.rename" name="Diagram Rename Participant" schema="schema/org.eclipse.etrice.ui.common.refactoring.rename.exsd"/>
<extension
point="org.eclipse.ui.startup">
<startup
@@ -21,5 +22,25 @@
class="org.eclipse.etrice.ui.common.preferences.PreferenceInitializer">
</initializer>
</extension>
+ <extension
+ point="org.eclipse.ltk.core.refactoring.renameParticipants">
+ <renameParticipant
+ class="org.eclipse.etrice.ui.common.refactoring.DiagramRenameParticipant"
+ id="org.eclipse.etrice.ui.common.renameParticipant"
+ name="eTrice Diagram Rename Participant">
+ <enablement>
+ <with
+ variable="element">
+ <adapt
+ type="org.eclipse.core.resources.IFile">
+ <test
+ property="org.eclipse.core.resources.extension"
+ value="room">
+ </test>
+ </adapt>
+ </with>
+ </enablement>
+ </renameParticipant>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.etrice.ui.common/schema/org.eclipse.etrice.ui.common.refactoring.rename.exsd b/plugins/org.eclipse.etrice.ui.common/schema/org.eclipse.etrice.ui.common.refactoring.rename.exsd
new file mode 100644
index 0000000..f15dd8d
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.common/schema/org.eclipse.etrice.ui.common.refactoring.rename.exsd
@@ -0,0 +1,106 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.etrice.ui.common" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.etrice.ui.common" id="org.eclipse.etrice.ui.common.refactoring.rename" name="Diagram Rename Participant"/>
+ </appinfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <choice>
+ <element ref="participant"/>
+ </choice>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="participant">
+ <complexType>
+ <attribute name="diagram_extension" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="editor_id" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/DiagramAccessBase.java b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/DiagramAccessBase.java
index 8c5ba79..f0cefd7 100644
--- a/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/DiagramAccessBase.java
+++ b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/DiagramAccessBase.java
@@ -48,7 +48,7 @@ import org.eclipse.ui.part.FileEditorInput;
*/
public abstract class DiagramAccessBase {
- private static final String DIAGRAMS_FOLDER_NAME = "diagrams";
+ public static final String DIAGRAMS_FOLDER_NAME = "diagrams";
/**
*
@@ -211,10 +211,10 @@ public abstract class DiagramAccessBase {
return input;
}
- abstract protected String getDiagramName(StructureClass sc);
+ public abstract String getDiagramName(StructureClass sc);
+ abstract protected String getFileExtension();
abstract protected String getDiagramTypeId();
abstract protected String getEditorId();
- abstract protected String getFileExtension();
abstract protected Command getInitialCommand(StructureClass ac, Diagram diagram, TransactionalEditingDomain editingDomain);
abstract protected Command getUpdateCommand(Diagram diagram, TransactionalEditingDomain editingDomain);
} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/commands/ChangeDiagramInputJob.java b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/commands/ChangeDiagramInputJob.java
new file mode 100644
index 0000000..bea2a2d
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/commands/ChangeDiagramInputJob.java
@@ -0,0 +1,251 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.common.commands;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.core.room.RoomModel;
+import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.core.ui.RoomUiModule;
+import org.eclipse.etrice.ui.common.editor.RoomDiagramEditor;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+import org.eclipse.ui.dialogs.FilteredResourcesSelectionDialog;
+import org.eclipse.ui.part.FileEditorInput;
+
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+
+public class ChangeDiagramInputJob extends Job {
+
+ @Inject
+ private ILabelProvider roomLabelProvider;
+
+ private Diagram diagram;
+ private RoomDiagramEditor editor;
+ private boolean close, saveOnClose, reOpen;
+
+ private IFile roomFile;
+ private StructureClass sc;
+
+ public ChangeDiagramInputJob(String name, RoomDiagramEditor editor) {
+ super(name);
+ this.editor = editor;
+
+ Injector injector = RoomUiModule.getInjector();
+ injector.injectMembers(this);
+
+ diagram = editor.getDiagramTypeProvider().getDiagram();
+ close = saveOnClose = reOpen = true;
+ }
+
+ public ChangeDiagramInputJob(String name, RoomDiagramEditor editor, boolean close, boolean saveOnClose, boolean reOpen) {
+ this(name, editor);
+ this.close = close;
+ this.saveOnClose = saveOnClose;
+ this.reOpen = reOpen;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+
+ URI diagramURI = diagram.eResource().getURI().trimFragment();
+ final IFile diagramFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(diagramURI.toPlatformString(false)));
+ IContainer diagramFolder = diagramFile.getParent();
+
+ // find room files in parent model folder
+ final IContainer modelFolder = diagramFolder.getParent();
+ Display.getDefault().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ roomFile = selectRoomFile(modelFolder);
+ }
+ });
+ if(roomFile == null)
+ return Status.OK_STATUS;
+
+ URI newRoomURI = URI.createPlatformResourceURI(roomFile.getFullPath().toString(), false);
+ ResourceSet rs = new ResourceSetImpl();
+ Resource roomRes = rs.getResource(newRoomURI, true);
+ EObject rootEObject = roomRes.getContents().iterator().next();
+ if(!(rootEObject instanceof RoomModel))
+ return Status.OK_STATUS;
+
+ // select a structure class
+ final RoomModel roomModel = (RoomModel) rootEObject;
+ Display.getDefault().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ sc = selectSc(roomModel);
+ }
+ });
+ if(sc == null)
+ return Status.OK_STATUS;
+
+ // close diagram to avoid exception and bad update (graphiti bug ?)
+ Runnable closeDiagramRunnable = new Runnable() {
+
+ @Override
+ public void run() {
+ IWorkbenchWindow workbench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ workbench.getActivePage().closeEditor(editor, saveOnClose);
+ }
+ };
+ if(close)
+ Display.getDefault().syncExec(closeDiagramRunnable);
+
+ // new
+ String newScName = sc.getName();
+ String newDiagramName = roomModel.getName()+"."+newScName+"."+diagramURI.fileExtension();
+ IPath newDiagramPath = diagramFile.getFullPath().removeLastSegments(1).append(newDiagramName);
+ URI newDiagramURI = URI.createPlatformResourceURI(newDiagramPath.toString(), false);
+
+ // old
+ EObject oldDiagramSc = diagram.getLink().getBusinessObjects().iterator().next();
+ URI oldScURI = EcoreUtil.getURI(oldDiagramSc);
+ String oldScName = oldScURI.fragment().substring(oldScURI.fragment().indexOf(':') + 1).trim();
+ URI oldRoomURI = oldScURI.trimFragment();
+
+ // rename diagram
+ if(!diagramURI.equals(newDiagramURI))
+ try {
+ diagramFile.move(newDiagramPath, false, monitor);
+ }
+ catch (CoreException e) {
+ showError(e.getMessage());
+ e.printStackTrace();
+ return Status.CANCEL_STATUS;
+ }
+
+ // change uri and name to old one from diagram
+ roomRes.setURI(oldRoomURI);
+ sc.setName(oldScName);
+
+ // resolve cross references
+ Resource diagramRes = rs.getResource(newDiagramURI, true);
+ EcoreUtil.resolveAll(diagramRes);
+
+ // undo
+ roomRes.setURI(newRoomURI);
+ sc.setName(newScName);
+
+ // save only diagram to change cross references and file name
+ try {
+ diagramRes.save(null);
+ } catch (IOException e) {
+ showError(e.getMessage());
+ e.printStackTrace();
+ return Status.CANCEL_STATUS;
+ }
+
+ // reopen diagram
+ final IFile newDiagramFile = ResourcesPlugin.getWorkspace().getRoot().getFile(newDiagramPath);
+ Runnable openDiagramRunnable = new Runnable() {
+
+ @Override
+ public void run() {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IEditorDescriptor desc = PlatformUI.getWorkbench().
+ getEditorRegistry().getDefaultEditor(newDiagramFile.getName());
+ try {
+ page.openEditor(new FileEditorInput(newDiagramFile), desc.getId());
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+ }
+ };
+ if(reOpen)
+ Display.getDefault().asyncExec(openDiagramRunnable);
+
+ return Status.OK_STATUS;
+ }
+
+ private void showError(final String message){
+ Display.getDefault().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ MessageDialog.openError(Display.getDefault().getActiveShell(), "Operation Failed", message);
+ }
+ });
+ }
+
+ private IFile selectRoomFile(IContainer container){
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ FilteredResourcesSelectionDialog dialog = new FilteredResourcesSelectionDialog(shell, false, container, IResource.FILE);
+
+ // TODO: show only room files that are direct children of model folder (depth 1)
+ dialog.setMessage("Select a ROOM file");
+ dialog.setInitialPattern(".room");
+
+ if(dialog.open() == Window.OK)
+ return (IFile) dialog.getFirstResult();
+
+ return null;
+ }
+
+ private StructureClass selectSc(RoomModel model){
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, roomLabelProvider);
+ dialog.setMultipleSelection(false);
+ dialog.setMessage("Select a new ROOM class");
+ dialog.setFilter("*");
+ dialog.setElements(getElements(model).toArray());
+
+ if(dialog.open()==Window.OK)
+ return (StructureClass) dialog.getFirstResult();
+
+ return null;
+ }
+
+ protected List<StructureClass> getElements(RoomModel model){
+ List<StructureClass> elements = new ArrayList<StructureClass>();
+ elements.addAll(model.getActorClasses());
+ elements.addAll(model.getSubSystemClasses());
+ elements.addAll(model.getSystems());
+
+ return elements;
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/RoomDiagramEditor.java b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/RoomDiagramEditor.java
index 3836754..df5581b 100644
--- a/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/RoomDiagramEditor.java
+++ b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/RoomDiagramEditor.java
@@ -31,8 +31,11 @@ import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.core.ui.RoomUiModule;
import org.eclipse.etrice.core.ui.editor.RoomEditor;
import org.eclipse.etrice.ui.common.Activator;
+import org.eclipse.etrice.ui.common.commands.ChangeDiagramInputJob;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.ui.editor.DiagramEditor;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.TrayDialog;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
@@ -65,11 +68,15 @@ public abstract class RoomDiagramEditor extends DiagramEditor {
private ModificationTrackingEnabler mte = new ModificationTrackingEnabler();
+ private boolean showLostDiagramInputDialog = true;
+
public RoomDiagramEditor() {
super();
Injector injector = RoomUiModule.getInjector();
injector.injectMembers(this);
+
+ TrayDialog.setDialogHelpAvailable(false);
}
@Override
@@ -182,7 +189,7 @@ public abstract class RoomDiagramEditor extends DiagramEditor {
public void setFocus() {
boolean dirtyAlready = isDirty();
- // inside this call auto refresh will happen iff (and turn the editor dirty)
+ // inside this call auto refresh will happen if (and turn the editor dirty)
super.setFocus();
if(superClassListener.isChangeInSuperClass())
@@ -190,6 +197,26 @@ public abstract class RoomDiagramEditor extends DiagramEditor {
if (!dirtyAlready && isDirty())
doSave(null);
+
+ Diagram diagram = getDiagramTypeProvider().getDiagram();
+ EObject diagramBo = diagram.getLink().getBusinessObjects().iterator().next();
+ if(diagramBo == null || diagramBo.eIsProxy())
+ handleMissingDiagramBo(diagram);
+ }
+
+ protected void handleMissingDiagramBo(Diagram diagram){
+ if(!showLostDiagramInputDialog)
+ return;
+
+ // show only once
+ showLostDiagramInputDialog = false;
+ MessageDialog dialog = new MessageDialog(getGraphicalControl().getShell(),
+ "Diagram out-dated", null, "Diagram input lost. Cannot find ROOM file or class for "+diagram.getName(),
+ MessageDialog.ERROR, new String[] { "OK", "Reconnect Diagram" }, 0);
+ int result = dialog.open();
+
+ if(result == 1)
+ new ChangeDiagramInputJob("Change input for "+diagram.getName(), this).schedule();
}
/**
@@ -217,7 +244,6 @@ public abstract class RoomDiagramEditor extends DiagramEditor {
return false;
}
-
/**
* Check whether the given room editor has a super class
* @param editor
diff --git a/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/refactoring/DiagramRenameParticipant.java b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/refactoring/DiagramRenameParticipant.java
new file mode 100644
index 0000000..c5da6c5
--- /dev/null
+++ b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/refactoring/DiagramRenameParticipant.java
@@ -0,0 +1,319 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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
+ *
+ * CONTRIBUTORS:
+ * Juergen Haug (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.common.refactoring;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.etrice.ui.common.DiagramAccessBase;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.FileStatusContext;
+import org.eclipse.ltk.core.refactoring.NullChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
+import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
+import org.eclipse.ltk.core.refactoring.resource.ResourceChange;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+
+public class DiagramRenameParticipant extends RenameParticipant {
+
+ private URI roomURI;
+ private List<IFile> diagramFiles;
+
+ private static String[] diagramExtensions;
+ private static String[] diagramEditorsIds;
+
+ static {
+ IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.etrice.ui.common.refactoring.rename");
+ diagramExtensions = new String[elements.length];
+ diagramEditorsIds = new String[elements.length];
+ for(int i=0;i<elements.length;i++){
+ diagramExtensions[i] = elements[i].getAttribute("diagram_extension");
+ diagramEditorsIds[i] = elements[i].getAttribute("editor_id");
+ }
+ }
+
+ public DiagramRenameParticipant(){
+ this.diagramFiles = new ArrayList<IFile>();
+ }
+
+ @Override
+ protected boolean initialize(Object element) {
+ IFile roomFile = (IFile) element;
+ IFolder diagramFolder = roomFile.getParent().getFolder(new Path(DiagramAccessBase.DIAGRAMS_FOLDER_NAME));
+
+ // find all diagrams in diagram folder
+ final List<IFile> allDiagrams = new ArrayList<IFile>();
+ IResourceProxyVisitor visitor = new IResourceProxyVisitor() {
+
+ @Override
+ public boolean visit(IResourceProxy proxy) throws CoreException {
+ for(String extension : diagramExtensions)
+ if(proxy.getName().endsWith(extension))
+ allDiagrams.add((IFile) proxy.requestResource());
+
+ return true;
+ }
+ };
+ try {
+ diagramFolder.accept(visitor, IResource.DEPTH_ONE, IResource.FILE);
+ }
+ catch (CoreException e) {
+ e.printStackTrace();
+ }
+
+ // select diagrams that point to roomFile
+ roomURI = URI.createPlatformResourceURI(roomFile.getFullPath().toString(), false);
+ ResourceSet rs = new ResourceSetImpl();
+ for(IFile diagramFile : allDiagrams){
+ URI diagramURI = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), false);
+ Resource res = rs.getResource(diagramURI, true);
+ EObject obj = res.getContents().iterator().next();
+ if(obj instanceof Diagram){
+ Diagram diagram = (Diagram) obj;
+ if(diagram.getLink().getBusinessObjects().isEmpty())
+ continue;
+ URI boURI = EcoreUtil.getURI(diagram.getLink().getBusinessObjects().iterator().next());
+ if(roomURI.equals(boURI.trimFragment()))
+ diagramFiles.add(diagramFile);
+ }
+ }
+
+ return !diagramFiles.isEmpty();
+ }
+
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public RefactoringStatus checkConditions(IProgressMonitor pm,
+ CheckConditionsContext context) throws OperationCanceledException {
+
+ // collect open diagrams
+ final RefactoringStatus status = RefactoringStatus.create(Status.OK_STATUS);
+ final List<IFile> toIgnore = new ArrayList<IFile>();
+ Runnable runnable = new Runnable() {
+
+ @Override
+ public void run() {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ for(IFile diagramFile : diagramFiles)
+ if(isDiagramEditorOpen(diagramFile, page))
+ toIgnore.add(diagramFile);
+ }
+ };
+ Display.getDefault().syncExec(runnable);
+
+ /* Issues:
+ * - after renaming open diagram causes exception and bad update (graphiti bug ?)
+ * - saving diagram here can cause deadlock somehow
+ */
+
+ // print warning and ignore
+ for(IFile diagramFile : toIgnore){
+ diagramFiles.remove(diagramFile);
+ status.addWarning("Cannot update open diagram " + diagramFile.getName(), new FileStatusContext(diagramFile, null));
+ }
+
+ return status;
+ }
+
+ @Override
+ public Change createChange(IProgressMonitor pm) throws CoreException,
+ OperationCanceledException {
+
+ if(diagramFiles.isEmpty())
+ return new NullChange();
+
+ URI oldURI = roomURI;
+ String newFileName = getArguments().getNewName();
+ URI newURI = oldURI.trimSegments(1).appendSegment(newFileName);
+
+ ResourceSet rs = new ResourceSetImpl();
+ rs.getResource(oldURI, true);
+ CompositeChange compositeChange = new DiagramCompositeChange(oldURI, newURI, rs);
+
+ for(IFile diagramFile : diagramFiles){
+ URI diagramURI = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), false);
+ Resource diagramRes = rs.getResource(diagramURI, true);
+ compositeChange.add(new DiagramUpdateChange(diagramRes));
+ }
+
+ return compositeChange;
+
+ }
+
+ /**
+ * has to be executed in ui thread
+ */
+ private boolean isDiagramEditorOpen(IFile input, IWorkbenchPage page){
+ IEditorInput editorInput = new FileEditorInput(input);
+ for(String editorId : diagramEditorsIds){
+ IEditorReference[] editorRefs = page.findEditors(editorInput, editorId, IWorkbenchPage.MATCH_ID|IWorkbenchPage.MATCH_INPUT);
+ if (editorRefs.length > 0)
+ return true;
+ }
+
+ return false;
+ }
+
+ private class DiagramCompositeChange extends CompositeChange{
+
+ private URI oldURI, newURI;
+ private ResourceSet rs;
+
+ public DiagramCompositeChange(URI oldURI, URI newURI, ResourceSet rs) {
+ super("Update Diagrams");
+ this.oldURI = oldURI;
+ this.newURI = newURI;
+ this.rs = rs;
+ }
+
+ public DiagramCompositeChange(URI oldURI, URI newURI, ResourceSet rs, Change[] childUndos) {
+ super("Update Diagrams", childUndos);
+ this.oldURI = oldURI;
+ this.newURI = newURI;
+ this.rs = rs;
+ }
+
+ @Override
+ public Change perform(IProgressMonitor pm) throws CoreException {
+ Resource roomRes = rs.getResources().get(0);
+
+ // resolve all cross references
+ EcoreUtil.resolveAll(rs);
+
+ // change uri of room objects
+ roomRes.setURI(newURI);
+
+ // perform child changes (and create undo changes):
+ // save only diagrams to change cross references
+ Change undoChange = super.perform(pm);
+
+ return undoChange;
+ }
+
+
+ @Override
+ protected Change createUndoChange(Change[] childUndos) {
+ return new DiagramCompositeChange(newURI, oldURI, rs, childUndos);
+ }
+
+
+ @Override
+ protected boolean internalContinueOnCancel() {
+ return true;
+ }
+
+ }
+
+ /**
+ * does diagramRes.save(null);
+ */
+ private class DiagramUpdateChange extends ResourceChange{
+
+ Resource diagramRes;
+
+ public DiagramUpdateChange(Resource diagramRes){
+ super();
+ this.diagramRes = diagramRes;
+
+ setValidationMethod(VALIDATE_NOT_DIRTY);
+ }
+
+ @Override
+ public RefactoringStatus isValid(IProgressMonitor pm)
+ throws CoreException, OperationCanceledException {
+
+ // ResourceChange valid ?
+ final RefactoringStatus status = super.isValid(pm);
+ if(status.hasFatalError())
+ return status;
+
+ // diagram open ?
+ Runnable runnable = new Runnable() {
+
+ @Override
+ public void run() {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ if(isDiagramEditorOpen((IFile) getModifiedResource(), page))
+ status.addFatalError("Diagram " + diagramRes.getURI().lastSegment() + " is open");
+ }
+ };
+ Display.getDefault().syncExec(runnable);
+
+ // resource still loaded ?
+ if(!diagramRes.isLoaded())
+ status.addFatalError("Expired");
+
+ return status;
+ }
+
+ @Override
+ protected IResource getModifiedResource() {
+ IPath path = new Path(diagramRes.getURI().toPlatformString(false));
+ return ResourcesPlugin.getWorkspace().getRoot().findMember(path);
+ }
+
+ @Override
+ public String getName() {
+ return "Update references";
+ }
+
+ @Override
+ public Change perform(IProgressMonitor pm) throws CoreException {
+ // save diagram resource to change cross references
+ try {
+ diagramRes.save(null);
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new CoreException(Status.CANCEL_STATUS);
+ }
+
+ return new DiagramUpdateChange(diagramRes);
+ }
+
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.ui.structure/plugin.xml b/plugins/org.eclipse.etrice.ui.structure/plugin.xml
index c524391..0a42237 100644
--- a/plugins/org.eclipse.etrice.ui.structure/plugin.xml
+++ b/plugins/org.eclipse.etrice.ui.structure/plugin.xml
@@ -61,5 +61,12 @@
uriExtension="structure">
</resourceServiceProvider>
</extension>
+ <extension
+ point="org.eclipse.etrice.ui.common.refactoring.rename">
+ <participant
+ diagram_extension="structure"
+ editor_id="org.eclipse.etrice.ui.structure.editor.StructureEditor">
+ </participant>
+ </extension>
</plugin>
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 5612f25..5f27da2 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
@@ -27,7 +27,7 @@ import org.eclipse.etrice.core.room.StructureClass;
public class DiagramAccess extends DiagramAccessBase {
- protected String getDiagramName(StructureClass sc) {
+ public String getDiagramName(StructureClass sc) {
return "Structure of "+sc.getName();
}
@@ -43,24 +43,20 @@ public class DiagramAccess extends DiagramAccessBase {
return ".structure";
}
- protected Command getInitialCommand(StructureClass ac, Diagram diagram, TransactionalEditingDomain editingDomain) {
+ protected Command getInitialCommand(StructureClass sc, Diagram diagram, TransactionalEditingDomain editingDomain) {
IDiagramTypeProvider dtp = GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram, DiagramTypeProvider.PROVIDER_ID); //$NON-NLS-1$
IFeatureProvider featureProvider = dtp.getFeatureProvider();
- return new UpdateDiagramCommand(ac, diagram, editingDomain, featureProvider);
+ return new UpdateDiagramCommand(diagram, sc, editingDomain, featureProvider);
}
- /* (non-Javadoc)
- * @see org.eclipse.etrice.ui.common.DiagramAccessBase#getUpdateCommand(org.eclipse.graphiti.mm.pictograms.Diagram, org.eclipse.emf.transaction.TransactionalEditingDomain)
- */
@Override
protected Command getUpdateCommand(Diagram diagram, TransactionalEditingDomain editingDomain) {
IDiagramTypeProvider dtp = GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram, DiagramTypeProvider.PROVIDER_ID); //$NON-NLS-1$
IFeatureProvider featureProvider = dtp.getFeatureProvider();
- StructureClass sc = (StructureClass) featureProvider.getBusinessObjectForPictogramElement(diagram);
- UpdateDiagramCommand cmd = new UpdateDiagramCommand(sc, diagram, editingDomain, featureProvider);
+ UpdateDiagramCommand cmd = new UpdateDiagramCommand(diagram, editingDomain, featureProvider);
if (cmd.updateNeeded())
return cmd;
-
+
return null;
}
}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateDiagramCommand.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateDiagramCommand.java
index ef4e036..528b896 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateDiagramCommand.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/commands/UpdateDiagramCommand.java
@@ -29,25 +29,32 @@ public class UpdateDiagramCommand extends RecordingCommand {
private Diagram diagram;
private IFeatureProvider featureProvider;
- private StructureClass sc;
+ private StructureClass linkedSc;
- public UpdateDiagramCommand(StructureClass sc, Diagram diagram, TransactionalEditingDomain domain, IFeatureProvider featureProvider) {
+ public UpdateDiagramCommand(Diagram diagram, TransactionalEditingDomain domain, IFeatureProvider featureProvider) {
super(domain);
- this.sc = sc;
this.diagram = diagram;
this.featureProvider = featureProvider;
+ this.linkedSc = null;
+ }
+
+ public UpdateDiagramCommand(Diagram diagram, StructureClass linkedSc, TransactionalEditingDomain domain, IFeatureProvider featureProvider) {
+ this(diagram, domain, featureProvider);
+ this.linkedSc = linkedSc;
}
@Override
protected void doExecute() {
- if(diagram.getLink() == null)
- featureProvider.link(diagram, sc);
+ if(linkedSc != null)
+ featureProvider.link(diagram, linkedSc);
+
+ Object diagramBo = featureProvider.getBusinessObjectForPictogramElement(diagram);
IUpdateContext context;
- if(sc instanceof ActorClass && ((ActorClass)sc).getBase() != null)
- context = new PositionUpdateContext(diagram, new SuperDiagramPositionProvider(sc));
- else if(DiagramUtil.findScShape(diagram) == null)
- context = new PositionUpdateContext(diagram, new DefaultPositionProvider(sc));
+ if(diagramBo instanceof ActorClass && ((ActorClass)diagramBo).getBase() != null)
+ context = new PositionUpdateContext(diagram, new SuperDiagramPositionProvider((ActorClass)diagramBo));
+ else if(diagramBo instanceof StructureClass && DiagramUtil.findScShape(diagram) == null)
+ context = new PositionUpdateContext(diagram, new DefaultPositionProvider((StructureClass)diagramBo));
else
context = new UpdateContext(diagram);
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/DiagramRefreshBehavior.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/DiagramRefreshBehavior.java
index fd5b8d9..df877f5 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/DiagramRefreshBehavior.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/DiagramRefreshBehavior.java
@@ -42,9 +42,13 @@ public class DiagramRefreshBehavior extends DefaultRefreshBehavior {
autoUpdate(new PositionUpdateContext(diagram, new SuperDiagramPositionProvider(sc)));
else
autoUpdate(new UpdateContext(diagram));
-
}
}
+
+ @Override
+ protected void handleAutoUpdateAtReset() {
+ super.handleAutoUpdateAtReset();
+ }
public void autoUpdate(IUpdateContext updateCtx) {
IDiagramTypeProvider diagramTypeProvider = diagramBehavior.getDiagramTypeProvider();
@@ -52,5 +56,7 @@ public class DiagramRefreshBehavior extends DefaultRefreshBehavior {
featureProvider.updateIfPossible(updateCtx);
refresh();
}
+
+
}
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 8a7809f..c4ffc82 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
@@ -68,6 +68,7 @@ public class StructureEditor extends RoomDiagramEditor {
protected DiagramBehavior createDiagramBehavior() {
final StructureEditor editor = this;
return new DiagramBehavior(this) {
+ @Override
protected DefaultRefreshBehavior createRefreshBehavior() {
return new DiagramRefreshBehavior(editor);
}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DiagramUpdateFeature.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DiagramUpdateFeature.java
index 989a350..9b566ea 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DiagramUpdateFeature.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DiagramUpdateFeature.java
@@ -14,8 +14,10 @@ package org.eclipse.etrice.ui.structure.support;
import java.util.ArrayList;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.ui.structure.DiagramAccess;
import org.eclipse.etrice.ui.structure.support.context.DeleteContext;
import org.eclipse.etrice.ui.structure.support.context.PositionUpdateContext;
import org.eclipse.etrice.ui.structure.support.provider.IPositionProvider;
@@ -32,6 +34,7 @@ import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
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.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
public class DiagramUpdateFeature extends AbstractUpdateFeature {
@@ -42,19 +45,32 @@ public class DiagramUpdateFeature extends AbstractUpdateFeature {
@Override
public boolean canUpdate(IUpdateContext context) {
+ Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
+ if(!(bo instanceof EObject) || ((EObject) bo).eIsProxy())
+ return false;
+
return true;
}
@Override
public IReason updateNeeded(IUpdateContext context) {
- StructureClass sc = (StructureClass) getBusinessObjectForPictogramElement(getDiagram());
-
- if(sc instanceof ActorClass && ((ActorClass)sc).getBase() != null)
- return new Reason(true);
- if(updateConnectionsNeeded(getDiagram()))
- return new Reason(true);
- if(updateNeeded(getDiagram()))
- return new Reason(true);
+ PictogramElement pe = context.getPictogramElement();
+ Object bo = getBusinessObjectForPictogramElement(pe);
+ if(bo instanceof EObject){
+ EObject eBo = (EObject)bo;
+ if (eBo.eIsProxy())
+ return Reason.createTrueReason("Deleted from model");
+
+ StructureClass sc = (StructureClass) bo;
+ if(sc instanceof ActorClass && ((ActorClass)sc).getBase() != null)
+ return new Reason(true);
+ if(updateConnectionsNeeded(getDiagram()))
+ return new Reason(true);
+ if(updateNeeded(getDiagram()))
+ return new Reason(true);
+ if(!new DiagramAccess().getDiagramName(sc).equals(getDiagram().getName()))
+ return new Reason(true);
+ }
return new Reason(false);
}
@@ -106,7 +122,9 @@ public class DiagramUpdateFeature extends AbstractUpdateFeature {
@Override
public boolean update(IUpdateContext context) {
- StructureClass sc = (StructureClass) getBusinessObjectForPictogramElement(getDiagram());
+ PictogramElement pe = context.getPictogramElement();
+ Object bo = getBusinessObjectForPictogramElement(pe);
+ StructureClass sc = (StructureClass) bo;
ContainerShape scShape = DiagramUtil.findScShape(getDiagram());
IPositionProvider positionProvider = null;
if(context instanceof PositionUpdateContext)
@@ -114,7 +132,7 @@ public class DiagramUpdateFeature extends AbstractUpdateFeature {
if(scShape == null)
scShape = createStructureClass(sc, positionProvider);
-
+
boolean doneChanges = updateConnections(getDiagram());
if (updateIfNeeded(getDiagram()))
@@ -131,6 +149,12 @@ public class DiagramUpdateFeature extends AbstractUpdateFeature {
doneChanges |= getFeatureProvider().updateIfPossible(ctx).toBoolean();
}
+ String diagramName = new DiagramAccess().getDiagramName(sc);
+ if(!diagramName.equals(getDiagram().getName())){
+ getDiagram().setName(new DiagramAccess().getDiagramName(sc));
+ doneChanges = true;
+ }
+
return doneChanges;
}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java
index 8ef16fe..ee25219 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java
@@ -12,12 +12,15 @@
package org.eclipse.etrice.ui.structure.support;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.InterfaceItem;
import org.eclipse.etrice.core.room.Port;
import org.eclipse.etrice.core.room.StructureClass;
+import org.eclipse.etrice.ui.common.commands.ChangeDiagramInputJob;
+import org.eclipse.etrice.ui.common.editor.RoomDiagramEditor;
import org.eclipse.etrice.ui.common.support.DeleteWithoutConfirmFeature;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IAddFeature;
@@ -28,12 +31,15 @@ import org.eclipse.graphiti.features.IRemoveFeature;
import org.eclipse.graphiti.features.IResizeShapeFeature;
import org.eclipse.graphiti.features.IUpdateFeature;
import org.eclipse.graphiti.features.context.IAddContext;
+import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.features.context.ICustomContext;
import org.eclipse.graphiti.features.context.IDeleteContext;
import org.eclipse.graphiti.features.context.ILayoutContext;
+import org.eclipse.graphiti.features.context.IPictogramElementContext;
import org.eclipse.graphiti.features.context.IRemoveContext;
import org.eclipse.graphiti.features.context.IResizeShapeContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
+import org.eclipse.graphiti.features.context.impl.CustomContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
import org.eclipse.graphiti.features.custom.ICustomFeature;
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
@@ -46,10 +52,14 @@ import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.platform.IPlatformImageConstants;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.services.IPeCreateService;
+import org.eclipse.graphiti.tb.ContextButtonEntry;
import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
+import org.eclipse.graphiti.tb.IContextButtonEntry;
+import org.eclipse.graphiti.tb.IContextButtonPadData;
import org.eclipse.graphiti.tb.IToolBehaviorProvider;
import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
import org.eclipse.graphiti.util.ColorConstant;
@@ -117,7 +127,7 @@ public class StructureClassSupport {
rect.setForeground(manageColor(LINE_COLOR));
rect.setBackground(manageColor(BACKGROUND));
rect.setTransparency(0.5);
- rect.setLineWidth(LINE_WIDTH);
+ rect.setLineVisible(false);
gaService.setLocationAndSize(rect, MARGIN, MARGIN, width, height);
// then unfilled opaque
rect = gaService.createRectangle(invisibleRectangle);
@@ -243,6 +253,46 @@ public class StructureClassSupport {
}
}
+ private class ReconnectToModel extends AbstractCustomFeature {
+
+ public ReconnectToModel(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public void execute(ICustomContext context) {
+ RoomDiagramEditor editor = (RoomDiagramEditor) getDiagramBehavior().getDiagramContainer();
+
+ Job job = new ChangeDiagramInputJob("blub", editor);
+ job.setUser(true);
+ job.schedule();
+ }
+
+ @Override
+ public boolean canExecute(ICustomContext context) {
+ return true;
+ }
+
+ @Override
+ public String getName() {
+ return "Reconnect Diagram to Model";
+ }
+
+
+
+ @Override
+ public boolean hasDoneChanges() {
+ return false;
+ }
+
+ @Override
+ public boolean isAvailable(IContext context) {
+ Object bo = fp.getBusinessObjectForPictogramElement(getDiagram());
+
+ return bo instanceof EObject && ((EObject)bo).eIsProxy();
+ }
+ }
+
private class ResizeFeature extends DefaultResizeShapeFeature{
public ResizeFeature(IFeatureProvider fp) {
@@ -374,7 +424,7 @@ public class StructureClassSupport {
@Override
public ICustomFeature[] getCustomFeatures(ICustomContext context) {
return new ICustomFeature[] {
- new OpenBehaviorDiagram(fp)};
+ new OpenBehaviorDiagram(fp), new ReconnectToModel(fp)};
}
@Override
@@ -413,9 +463,25 @@ public class StructureClassSupport {
GraphicsAlgorithm invisible = pe.getGraphicsAlgorithm();
GraphicsAlgorithm rectangle =
- invisible.getGraphicsAlgorithmChildren().get(0);
+ invisible.getGraphicsAlgorithmChildren().get(1);
return rectangle;
}
+
+ @Override
+ public IContextButtonPadData getContextButtonPad(
+ IPictogramElementContext context) {
+ IContextButtonPadData data = super.getContextButtonPad(context);
+
+ ICustomContext customContext = new CustomContext();
+ ICustomFeature reconnectToModel = afp.getCustomFeatures(customContext)[1];
+ if(reconnectToModel.isAvailable(customContext)){
+ IContextButtonEntry entry = new ContextButtonEntry(reconnectToModel, customContext);
+ entry.setIconId(IPlatformImageConstants.IMG_ECLIPSE_QUICKASSIST);
+ data.getDomainSpecificContextButtons().add(entry);
+ }
+
+ return data;
+ }
}
private FeatureProvider afp;
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassUpdate.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassUpdate.java
index 1ec65c9..8c48ad4 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassUpdate.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassUpdate.java
@@ -172,7 +172,7 @@ public class StructureClassUpdate extends ShapeUpdateFeature {
@Override
protected IReason updateNeeded(EObject bo, IUpdateContext context) {
- return Reason.createTrueReason();
+ return Reason.createFalseReason();
}
private Map<EObject,Connection> addConnectionsInitial(List<? extends EObject> toAdd, ConnectionProvider cp){
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/CommonUpdateFeature.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/CommonUpdateFeature.java
index ff6fdc1..2298f7f 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/CommonUpdateFeature.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/feature/CommonUpdateFeature.java
@@ -40,6 +40,11 @@ public abstract class CommonUpdateFeature extends AbstractUpdateFeature {
@Override
public final boolean canUpdate(IUpdateContext context) {
+ // disable update if diagram is disconnected from model
+ Object diagramBo = getBusinessObjectForPictogramElement(getDiagram());
+ if(diagramBo instanceof EObject && ((EObject) diagramBo).eIsProxy())
+ return false;
+
Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement());
if (bo instanceof EObject){
EObject eBo = (EObject)bo;