From ea49a638875848683c765a1b74a90a490a7fd84e Mon Sep 17 00:00:00 2001 From: Ansgar Radermacher Date: Fri, 23 Oct 2015 17:32:50 +0200 Subject: 480513 - [Property view] Enhance EditionDialog --- .../views/properties/creation/EditionDialog.java | 61 ++++++++++++++++++++++ .../views/properties/messages/Messages.java | 2 + .../views/properties/messages/messages.properties | 1 + 3 files changed, 64 insertions(+) (limited to 'plugins/views/properties') diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/creation/EditionDialog.java b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/creation/EditionDialog.java index 1bb01240284..297fb3246cb 100644 --- a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/creation/EditionDialog.java +++ b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/creation/EditionDialog.java @@ -13,6 +13,7 @@ *****************************************************************************/ package org.eclipse.papyrus.views.properties.creation; +import java.io.IOException; import java.text.Collator; import java.util.Collections; import java.util.Comparator; @@ -24,14 +25,17 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.eclipse.emf.common.util.URI; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.papyrus.views.properties.Activator; +import org.eclipse.papyrus.views.properties.contexts.Context; import org.eclipse.papyrus.views.properties.contexts.Section; import org.eclipse.papyrus.views.properties.contexts.Tab; import org.eclipse.papyrus.views.properties.contexts.View; import org.eclipse.papyrus.views.properties.messages.Messages; +import org.eclipse.papyrus.views.properties.runtime.ConfigurationManager; import org.eclipse.papyrus.views.properties.runtime.DefaultDisplayEngine; import org.eclipse.papyrus.views.properties.runtime.DisplayEngine; import org.eclipse.papyrus.views.properties.xwt.XWTSection; @@ -137,6 +141,63 @@ public class EditionDialog extends SelectionDialog { this.views = views; } + /** + * Provide information about context and view, as well as the element for which the dialog + * should be provided. It will call setViews in turn. + * + * @param contextName The name of the context + * @param contextURI The URI of the context, tries to load context, if it has not been done yet + * @param viewName The name of the view + */ + public void setViewData(String contextName, String viewName) { + setViewData(contextName, null, viewName); + } + + /** + * Provide information about context and view, as well as the element for which the dialog + * should be provided. + * + * @param contextName The name of the context + * @param contextURI The URI of the context. If the context is not available yet, the function uses this URI to load it. + * @param viewName The name of the view + */ + public void setViewData(String contextName, URI contextURI, String viewName) { + + Context context = ConfigurationManager.getInstance().getContext(contextName); + if ((context == null) && (contextURI != null)) { + // might not have been loaded yet + loadFromURI(contextURI); + context = ConfigurationManager.getInstance().getContext(contextName); + } + + Set views = new HashSet(); + + if (context != null) { + for (View view : context.getViews()) { + if (view.getName().equals(viewName)) { + views.add(view); + break; + } + } + } + if (views.isEmpty()) { + throw new RuntimeException (String.format(Messages.EditionDialog_CanNotFindview, viewName)); + } + setViews(views); + } + + /** + * Load the passed context into the configuration manager. + */ + protected void loadFromURI(URI uri) { + try { + ConfigurationManager.getInstance().addContext(uri); + } + catch (IOException io) { + Activator.log.error(io); + } + } + private void display() { DisplayEngine display = new DefaultDisplayEngine(); diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/messages/Messages.java b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/messages/Messages.java index d2f5ecfba1b..25bc1e6244c 100644 --- a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/messages/Messages.java +++ b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/messages/Messages.java @@ -24,6 +24,8 @@ public class Messages extends NLS { public static String EcorePropertyEditorFactory_CreateANew; + public static String EditionDialog_CanNotFindview; + public static String EditionDialog_CreateANewElement; public static String Preferences_ConflictWarning1; diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/messages/messages.properties b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/messages/messages.properties index 151b75538e6..05ade3033ad 100644 --- a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/messages/messages.properties +++ b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/messages/messages.properties @@ -1,4 +1,5 @@ EcorePropertyEditorFactory_CreateANew=Create a new +EditionDialog_CanNotFindview=Can not find view <%s> EditionDialog_CreateANewElement=Create a new Element Preferences_ConflictWarning1=Warning : When two sections with the same ID are displayed in the same property view, only the first of them is displayed. The following conflicts may occur : \n\n Preferences_ConflictWarning2=\nPlease note that if these sections apply to different elements, there won't be any conflict. Do you wish to continue ? -- cgit v1.2.3