Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2014-11-06 12:07:50 +0000
committerCamille Letavernier2014-11-06 12:16:11 +0000
commit52cfc35efacca1a3fdafce159d6720b04f59fe9e (patch)
tree68983927f8177cb92bffa3051e44748ad285eb28 /plugins/views
parent8527559c5c24f20096123c9402855083a775b4f5 (diff)
downloadorg.eclipse.papyrus-52cfc35efacca1a3fdafce159d6720b04f59fe9e.tar.gz
org.eclipse.papyrus-52cfc35efacca1a3fdafce159d6720b04f59fe9e.tar.xz
org.eclipse.papyrus-52cfc35efacca1a3fdafce159d6720b04f59fe9e.zip
450280: [Properties View] Papyrus shall provide a helper to easily embed
a properties view in a Composite https://bugs.eclipse.org/bugs/show_bug.cgi?id=450280
Diffstat (limited to 'plugins/views')
-rw-r--r--plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/EmbeddedDisplayEngine.java2
-rw-r--r--plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/util/PropertiesDisplayHelper.java140
2 files changed, 141 insertions, 1 deletions
diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/EmbeddedDisplayEngine.java b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/EmbeddedDisplayEngine.java
index d6a47f41418..8da8123e855 100644
--- a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/EmbeddedDisplayEngine.java
+++ b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/EmbeddedDisplayEngine.java
@@ -67,7 +67,7 @@ public class EmbeddedDisplayEngine extends DefaultDisplayEngine implements Selec
* @param style
* SWT.BOTTOM or SWT.TOP (Tabs' position)
*/
- public void display(Set<View> views, Composite parent, ISelection selection, int style) {
+ public void display(Set<? extends View> views, Composite parent, ISelection selection, int style) {
disposeControls();
self = new Composite(parent, SWT.NONE);
diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/util/PropertiesDisplayHelper.java b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/util/PropertiesDisplayHelper.java
new file mode 100644
index 00000000000..b73c8dedaf3
--- /dev/null
+++ b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/util/PropertiesDisplayHelper.java
@@ -0,0 +1,140 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST and others.
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.properties.util;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.infra.constraints.runtime.ConstraintEngine;
+import org.eclipse.papyrus.views.properties.contexts.View;
+import org.eclipse.papyrus.views.properties.runtime.ConfigurationManager;
+import org.eclipse.papyrus.views.properties.runtime.DisplayEngine;
+import org.eclipse.papyrus.views.properties.runtime.EmbeddedDisplayEngine;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * Helper class for displaying an embedded Properties View for
+ * a selection in a specific composite
+ *
+ *
+ * @author Camille Letavernier
+ *
+ */
+public class PropertiesDisplayHelper {
+
+ /**
+ * Displays the properties view associated to the selection in the given Composite
+ *
+ * @param selection
+ * @param parent
+ *
+ * @return The display engine used to build the view. Must be disposed by caller
+ */
+ public static DisplayEngine display(Object selection, Composite parent) {
+ return display(getDefaultConstraintEngine(), buildSelection(selection), parent);
+ }
+
+ /**
+ * Displays the properties view associated to the selection in the given Composite
+ *
+ * @param selection
+ * @param parent
+ *
+ * @return The display engine used to build the view. Must be disposed by caller
+ */
+ public static DisplayEngine display(Collection<?> selection, Composite parent) {
+ return display(getDefaultConstraintEngine(), buildSelection(selection), parent);
+ }
+
+ /**
+ * Displays the properties view associated to the selection in the given Composite
+ *
+ * The views are computed based on the given ConstraintEngine
+ *
+ * @param selection
+ * @param parent
+ * @param constraints
+ *
+ * @return The display engine used to build the view. Must be disposed by caller
+ */
+ public static DisplayEngine display(ConstraintEngine<? extends View> constraints, Object selection, Composite parent) {
+ return display(constraints, buildSelection(selection), parent);
+ }
+
+ /**
+ * Displays the properties view associated to the selection in the given Composite
+ *
+ * The views are computed based on the given ConstraintEngine
+ *
+ * @param selection
+ * @param parent
+ * @param constraints
+ *
+ * @return The display engine used to build the view. Must be disposed by caller
+ */
+ public static DisplayEngine display(ConstraintEngine<? extends View> constraints, Collection<?> selection, Composite parent) {
+ return display(constraints, buildSelection(selection), parent);
+ }
+
+ /**
+ * Displays the properties view associated to the selection in the given Composite
+ *
+ * The views are computed based on the given ConstraintEngine
+ *
+ * @param selection
+ * @param parent
+ * @param constraints
+ *
+ * @return The display engine used to build the view. Must be disposed by caller
+ */
+ public static DisplayEngine display(ConstraintEngine<? extends View> constraints, ISelection selection, Composite parent) {
+ EmbeddedDisplayEngine display = new EmbeddedDisplayEngine();
+
+ Set<? extends View> views = constraints.getDisplayUnits(selection);
+
+ Composite self = new Composite(parent, SWT.BORDER);
+ self.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
+ self.setLayout(new FillLayout());
+
+ display.display(views, self, selection, SWT.NONE);
+
+ return display;
+ }
+
+ /**
+ * Returns the default Properties View Constraint Engine
+ * Equivalent to ConfigurationManager.getInstance().getConstraintEngine()
+ *
+ * @return
+ *
+ * @see {@link ConfigurationManager#getConstraintEngine()}
+ */
+ public static ConstraintEngine<? extends View> getDefaultConstraintEngine() {
+ return ConfigurationManager.getInstance().getConstraintEngine();
+ }
+
+ private static IStructuredSelection buildSelection(Collection<?> elements) {
+ return new StructuredSelection(elements);
+ }
+
+ private static IStructuredSelection buildSelection(Object element) {
+ return new StructuredSelection(element);
+ }
+
+}

Back to the top