Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnsgar Radermacher2013-11-12 12:29:53 +0000
committerAnsgar Radermacher2013-11-12 15:14:46 +0000
commitdf5da14c366b7629438398d638df97c9df0f028f (patch)
treef9c1a667262b81747db15362ac09e875c76f298c /extraplugins/codegen
parent5e133bb518cd90ad8fbfbe364489f1ac2b19d1f7 (diff)
downloadorg.eclipse.papyrus-df5da14c366b7629438398d638df97c9df0f028f.tar.gz
org.eclipse.papyrus-df5da14c366b7629438398d638df97c9df0f028f.tar.xz
org.eclipse.papyrus-df5da14c366b7629438398d638df97c9df0f028f.zip
- Bug 421525 - [CDT integration] it should be possible to open a CDT editor by default on the right
Diffstat (limited to 'extraplugins/codegen')
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/editor/PapyrusCDTEditor.java20
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/factory/PapyrusCDTEditorFactory.java24
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/handler/PapyrusCDTEditorHandler.java37
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/preferences/CDTPreferenceConstants.java6
-rw-r--r--extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/preferences/CDTPreferenceInitializer.java2
5 files changed, 65 insertions, 24 deletions
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/editor/PapyrusCDTEditor.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/editor/PapyrusCDTEditor.java
index 589a5aefb3f..c7ffe414fae 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/editor/PapyrusCDTEditor.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/editor/PapyrusCDTEditor.java
@@ -91,6 +91,8 @@ public class PapyrusCDTEditor extends CEditor {
protected RevealCurrentOperation reveal;
+ protected Adapter gotoListener;
+
/**
*
* Constructor.
@@ -100,6 +102,7 @@ public class PapyrusCDTEditor extends CEditor {
*/
public PapyrusCDTEditor(final ServicesRegistry registry, final TextEditorModel papyrusTextInstance) {
super();
+ gotoListener = null;
this.registry = registry;
this.papyrusTextInstance = papyrusTextInstance;
try {
@@ -146,10 +149,10 @@ public class PapyrusCDTEditor extends CEditor {
actionBars.updateActionBars();
}
- papyrusTextInstance.eAdapters().add(new Adapter() {
+ gotoListener = new Adapter() {
+ // assure that gotoElement is called, if the element in the model gets updated
public void notifyChanged(Notification notification) {
- // TODO Auto-generated method stub
if (notification.getEventType() == Notification.SET) {
if (notification.getNewValue() instanceof NamedElement) {
gotoElement((NamedElement) notification.getNewValue());
@@ -168,8 +171,8 @@ public class PapyrusCDTEditor extends CEditor {
public boolean isAdapterForType(Object type) {
return false;
}
-
- });
+ };
+ papyrusTextInstance.eAdapters().add(gotoListener);
if (papyrusTextInstance.getSelectedObject() instanceof NamedElement) {
gotoElement((NamedElement) papyrusTextInstance.getSelectedObject());
@@ -297,7 +300,8 @@ public class PapyrusCDTEditor extends CEditor {
viewer.setSelectedRange(range.getStartPos(), range.getLength());
return;
}
- catch (CoreException e) {
+ catch (CoreException e) {
+ Activator.log.error(e);
}
}
}
@@ -357,7 +361,10 @@ public class PapyrusCDTEditor extends CEditor {
public void dispose() {
saveAndDirtyService.removeIsaveablePart(this);
-
+ if (gotoListener != null) {
+ papyrusTextInstance.eAdapters().remove(gotoListener);
+ }
+
//we remove the listener
StyledText st = getSourceViewer().getTextWidget();
st.removeFocusListener(focusListener);
@@ -385,3 +392,4 @@ public class PapyrusCDTEditor extends CEditor {
protected IEditorInput m_input;
}
+ \ No newline at end of file
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/factory/PapyrusCDTEditorFactory.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/factory/PapyrusCDTEditorFactory.java
index f9929aa6d74..7ce74ed98f3 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/factory/PapyrusCDTEditorFactory.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/factory/PapyrusCDTEditorFactory.java
@@ -20,7 +20,6 @@ import org.eclipse.papyrus.infra.core.multidiagram.actionbarcontributor.ActionBa
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IEditorModel;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.texteditor.cdt.Activator;
import org.eclipse.papyrus.texteditor.cdt.editor.PapyrusCDTEditor;
import org.eclipse.papyrus.texteditor.model.texteditormodel.TextEditorModel;
@@ -49,7 +48,7 @@ public class PapyrusCDTEditorFactory extends AbstractEditorFactory {
* @return A model implementing the IPageModel
*/
public IPageModel createIPageModel(Object pageIdentifier) {
- return new TextEditorModelDelegate(pageIdentifier, getServiceRegistry());
+ return new TextEditorModelDelegate(pageIdentifier);
}
/**
@@ -71,12 +70,6 @@ public class PapyrusCDTEditorFactory extends AbstractEditorFactory {
*/
class TextEditorModelDelegate implements IEditorModel {
-
- /**
- * The servicesRegistry provided at creation.
- */
- private ServicesRegistry servicesRegistry;
-
/**
* The created editor.
*/
@@ -85,15 +78,14 @@ public class PapyrusCDTEditorFactory extends AbstractEditorFactory {
/**
* The raw model stored in the SashProvider.
*/
- private TextEditorModel rawModel;
+ private TextEditorModel rawEditorModel;
/**
*
* Constructor.
*/
- public TextEditorModelDelegate(Object pageIdentifier, ServicesRegistry servicesRegistry) {
- rawModel = (TextEditorModel)pageIdentifier;
- this.servicesRegistry = servicesRegistry;
+ public TextEditorModelDelegate(Object pageIdentifier) {
+ rawEditorModel = (TextEditorModel)pageIdentifier;
}
/**
@@ -110,8 +102,8 @@ public class PapyrusCDTEditorFactory extends AbstractEditorFactory {
// Constructor<?> c = getDiagramClass().getConstructor(ServicesRegistry.class, TextEditorModel.class);
// editor = (IEditorPart)c.newInstance(servicesRegistry, rawModel);
- //we use this way when there is only one editor type
- editor = new PapyrusCDTEditor(servicesRegistry, rawModel);
+ //we use this way when there is only one editor type
+ editor = new PapyrusCDTEditor(getServiceRegistry(), rawEditorModel);
return editor;
} catch (Exception e) {
@@ -144,7 +136,7 @@ public class PapyrusCDTEditorFactory extends AbstractEditorFactory {
// ServicesRegistry serviceRegistry = getServicesRegistry();
ActionBarContributorRegistry registry;
try {
- registry = servicesRegistry.getService(ActionBarContributorRegistry.class);
+ registry = getServiceRegistry().getService(ActionBarContributorRegistry.class);
} catch (ServiceException e) {
// Service not found
Activator.log.error(e);
@@ -199,7 +191,7 @@ public class PapyrusCDTEditorFactory extends AbstractEditorFactory {
*
*/
public String getTabTitle() {
- return rawModel.getName();
+ return rawEditorModel.getName();
}
}
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/handler/PapyrusCDTEditorHandler.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/handler/PapyrusCDTEditorHandler.java
index e8b66fb154f..a6991ddac9c 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/handler/PapyrusCDTEditorHandler.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/handler/PapyrusCDTEditorHandler.java
@@ -34,6 +34,11 @@ import org.eclipse.papyrus.acceleo.ui.handlers.CmdHandler;
import org.eclipse.papyrus.commands.CheckedOperationHistory;
import org.eclipse.papyrus.infra.core.resource.NotFoundException;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.ISashWindowsContentProvider;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.DiSashModelManager;
+import org.eclipse.papyrus.infra.core.sasheditor.editor.ISashWindowsContainer;
+import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef;
+import org.eclipse.papyrus.infra.core.sashwindows.di.TabFolder;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
@@ -43,6 +48,7 @@ import org.eclipse.papyrus.texteditor.cdt.editor.PapyrusCDTEditor;
import org.eclipse.papyrus.texteditor.cdt.modelresource.TextEditorModelSharedResource;
import org.eclipse.papyrus.texteditor.model.texteditormodel.TextEditorModel;
import org.eclipse.papyrus.texteditor.model.texteditormodel.TextEditorModelFactory;
+import org.eclipse.swt.SWT;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.DataType;
@@ -149,7 +155,7 @@ public class PapyrusCDTEditorHandler extends CmdHandler {
public void doExecute(final ServicesRegistry serviceRegistry) throws ServiceException, NotFoundException {
// Get the page manager allowing to add/open an editor.
IPageManager pageMngr = ServiceUtils.getInstance().getIPageManager(serviceRegistry);
-
+
Classifier classifierToEdit = getClassifierToEdit();
TextEditorModel editorModel = getEditorModel(serviceRegistry, classifierToEdit);
@@ -166,6 +172,16 @@ public class PapyrusCDTEditorHandler extends CmdHandler {
else {
pageMngr.openPage(editorModel);
}
+
+ // move page to the RIGHT
+ DiSashModelManager modelMngr = ServiceUtils.getInstance().getService(DiSashModelManager.class, serviceRegistry);
+ ISashWindowsContentProvider sashContentProvider = modelMngr.getISashWindowsContentProvider();
+ Object rootModel = sashContentProvider.getRootModel();
+ if (rootModel instanceof TabFolder) {
+ ISashWindowsContainer sashContainer = ServiceUtils.getInstance().getISashWindowsContainer(serviceRegistry);
+ int index = lookupIndex((TabFolder) rootModel, editorModel);
+ sashContentProvider.createFolder(sashContainer.getSelectedTabFolderModel(), index, sashContainer.getSelectedTabFolderModel(), SWT.RIGHT);
+ }
}
/**
@@ -221,4 +237,23 @@ public class PapyrusCDTEditorHandler extends CmdHandler {
ServiceUtils.getInstance().getModelSet(serviceRegistry).getModelChecked(TextEditorModelSharedResource.MODEL_ID);
return model.getTextEditorModel(classifierToEdit);
}
+
+ /**
+ * Recursively search in sash models for a FolderModel.
+ * Return the first encountered folder.
+ *
+ * @param panelModel
+ * @return
+ */
+ public static int lookupIndex(TabFolder folder, Object model) {
+
+ int index = 0;
+ for (PageRef pr : folder.getChildren()) {
+ if (pr.getPageIdentifier() == model) {
+ return index;
+ }
+ index++;
+ }
+ return -1;
+ }
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/preferences/CDTPreferenceConstants.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/preferences/CDTPreferenceConstants.java
index bbd1cd272e1..64721b9a8a1 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/preferences/CDTPreferenceConstants.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/preferences/CDTPreferenceConstants.java
@@ -19,11 +19,15 @@ package org.eclipse.papyrus.texteditor.cdt.preferences;
public class CDTPreferenceConstants {
/**
+ * Default option for opening the editor at a specified location. Store uses directly the SWT constants
+ */
+ public static final String P_OPEN_LOCATION = "openLocation"; //$NON-NLS-1$
+
+ /**
* For attributes, the default "aggregation kind" value is "none". When this option is set
* it will be treated as composite
*/
public static final String P_SYNC_PERMANENTLY = "syncPermanently"; //$NON-NLS-1$
public static final String P_SYNC_ALL_FILES = "syncAllFiles"; //$NON-NLS-1$
-
}
diff --git a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/preferences/CDTPreferenceInitializer.java b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/preferences/CDTPreferenceInitializer.java
index a033b351b6b..fa1745ba456 100644
--- a/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/preferences/CDTPreferenceInitializer.java
+++ b/extraplugins/codegen/org.eclipse.papyrus.texteditor.cdt/src/org/eclipse/papyrus/texteditor/cdt/preferences/CDTPreferenceInitializer.java
@@ -17,6 +17,7 @@ package org.eclipse.papyrus.texteditor.cdt.preferences;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.papyrus.texteditor.cdt.Activator;
+import org.eclipse.swt.SWT;
/**
* Class used to initialize default preference values.
@@ -30,6 +31,7 @@ public class CDTPreferenceInitializer extends AbstractPreferenceInitializer {
*/
public void initializeDefaultPreferences() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
+ store.setDefault(CDTPreferenceConstants.P_OPEN_LOCATION, SWT.RIGHT);
store.setDefault(CDTPreferenceConstants.P_SYNC_ALL_FILES, false);
store.setDefault(CDTPreferenceConstants.P_SYNC_PERMANENTLY, false);
}

Back to the top