Author: adietish
Date: 2011-03-23 06:17:11 -0400 (Wed, 23 Mar 2011)
New Revision: 29972
Added:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CopyCVPropertySheetPageEntryHandler.java
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/plugin.xml
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/property/CVPropertySection.java
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/property/CVPropertySheetPage.java
Log:
[JBIDE-8416] implemented custom property sheet page so that elements opied (to the
clipboard) from it do not contain the label
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/plugin.xml
===================================================================
---
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/plugin.xml 2011-03-23
10:14:37 UTC (rev 29971)
+++
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/plugin.xml 2011-03-23
10:17:11 UTC (rev 29972)
@@ -324,6 +324,23 @@
</enabledWhen>
</handler>
</extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <!-- copy property sheet entry handler -->
+ <handler
+
class="org.jboss.tools.deltacloud.ui.commands.CopyCVPropertySheetPageEntryHandler"
+ commandId="org.eclipse.ui.edit.copy">
+ <activeWhen>
+ <with
+ variable="selection">
+ <iterate>
+ <instanceof
+ value="org.jboss.tools.deltacloud.ui.views.cloud.property.CVPropertySheetPage$PropertySourceContentProvider$CVPropertySheetPageEntry"
/>
+ </iterate>
+ </with>
+ </activeWhen>
+ </handler>
+ </extension>
<!-- InstanceView context menu ================================== -->
<extension point="org.eclipse.ui.menus">
<menuContribution
@@ -675,6 +692,25 @@
</extension>
+ <!-- CVPropertySheetPage context menu ================================== -->
+ <extension point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="true"
+
locationURI="popup:org.jboss.tools.deltacloud.ui.views.CVPropertySheetPage">
+ <separator
+ name="edit"
+ visible="true" />
+ </menuContribution>
+ <!-- filter images -->
+ <menuContribution
+ allPopups="true"
+
locationURI="popup:org.jboss.tools.deltacloud.ui.views.CVPropertySheetPage?after=edit">
+ <!-- image commands -->
+ <command
+ commandId="org.eclipse.ui.edit.copy"/>
+ </menuContribution>
+ </extension>
+
<!-- Commands ========================================= -->
<extension
point="org.eclipse.ui.commands">
Added:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CopyCVPropertySheetPageEntryHandler.java
===================================================================
---
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CopyCVPropertySheetPageEntryHandler.java
(rev 0)
+++
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CopyCVPropertySheetPageEntryHandler.java 2011-03-23
10:17:11 UTC (rev 29972)
@@ -0,0 +1,61 @@
+package org.jboss.tools.deltacloud.ui.commands;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.jboss.tools.deltacloud.ui.Activator;
+import org.jboss.tools.deltacloud.ui.views.cloud.property.CVPropertySheetPage;
+import
org.jboss.tools.deltacloud.ui.views.cloud.property.CVPropertySheetPage.PropertySourceContentProvider.CVPropertySheetPageEntry;
+
+/**
+ * A handler for the copy command (org.eclipse.ui.edit.copy) that copies entries
+ * in the CVPropertySheetPage to the clipboard.
+ *
+ * @author André Dietisheim
+ *
+ * @see CVPropertySheetPage
+ * @see CVPropertySheetPageEntry
+ */
+public class CopyCVPropertySheetPageEntryHandler extends AbstractHandler {
+
+ private Clipboard clipboard;
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if (selection instanceof IStructuredSelection) {
+ Object selectedObject = ((IStructuredSelection) selection).getFirstElement();
+ if (selectedObject instanceof CVPropertySheetPageEntry) {
+ CVPropertySheetPageEntry entry = (CVPropertySheetPageEntry) selectedObject;
+ Shell shell = HandlerUtil.getActiveShell(event);
+ if (shell == null) {
+ return null;
+ }
+ Clipboard clipboard = getClipboard(shell.getDisplay());
+ clipboard.setContents(
+ new Object[] { entry.getStringValue() },
+ new Transfer[] { TextTransfer.getInstance() });
+ return Status.OK_STATUS;
+ }
+ }
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ "The element to copy is not of an entry of the deltacloud property view");
+ }
+
+ private Clipboard getClipboard(Display display) {
+ if (clipboard == null) {
+ this.clipboard = new Clipboard(display);
+ }
+ return clipboard;
+ }
+}
Property changes on:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/CopyCVPropertySheetPageEntryHandler.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/property/CVPropertySection.java
===================================================================
---
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/property/CVPropertySection.java 2011-03-23
10:14:37 UTC (rev 29971)
+++
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/property/CVPropertySection.java 2011-03-23
10:17:11 UTC (rev 29972)
@@ -17,7 +17,6 @@
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.views.properties.PropertySheetPage;
import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
@@ -26,7 +25,7 @@
/**
* The Property Sheet Page.
*/
- protected PropertySheetPage page;
+ protected CVPropertySheetPage page;
/**
* @see
org.eclipse.ui.views.properties.tabbed.ISection#createControls(org.eclipse.swt.widgets.Composite,
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/property/CVPropertySheetPage.java
===================================================================
---
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/property/CVPropertySheetPage.java 2011-03-23
10:14:37 UTC (rev 29971)
+++
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/property/CVPropertySheetPage.java 2011-03-23
10:17:11 UTC (rev 29972)
@@ -12,39 +12,68 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ControlAdapter;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.views.properties.PropertySheetPage;
+import org.eclipse.ui.part.Page;
+import org.eclipse.ui.views.properties.IPropertyDescriptor;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.eclipse.ui.views.properties.IPropertySource;
import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.deltacloud.ui.views.cloud.CloudItem;
+import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
import org.jboss.tools.internal.deltacloud.ui.utils.WorkbenchUtils;
/**
+ * A custom property sheet page for deltacloud element properties.
+ *
* @Jeff Johnston
* @author André Dietisheim
*/
-public class CVPropertySheetPage extends PropertySheetPage {
+public class CVPropertySheetPage extends Page implements IPropertySheetPage {
+ public static final String ID =
"org.jboss.tools.deltacloud.ui.views.CVPropertySheetPage";
+
+ protected TreeViewer viewer;
+ protected Composite control;
+
private DeltaCloud deltaCloud;
private PropertyChangeListener cloudPropertyListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
Display.getDefault().syncExec(new Runnable() {
-
+
@Override
public void run() {
- refresh();
+ viewer.refresh();
}
});
}
};
public CVPropertySheetPage() {
- super();
- setSorter(new CVPropertySheetNonSorter());
}
@Override
@@ -59,9 +88,18 @@
}
}
- super.selectionChanged(part, selection);
+ setInput(selection);
}
+ private void setInput(ISelection selection) {
+ if (selection instanceof IStructuredSelection) {
+ Object o = ((IStructuredSelection) selection).getFirstElement();
+ if (o != null) {
+ viewer.setInput(o);
+ }
+ }
+ }
+
private void addPropertyChangeListener(DeltaCloud deltaCloud) {
if (deltaCloud != null) {
deltaCloud.addPropertyChangeListener(cloudPropertyListener);
@@ -74,4 +112,150 @@
}
}
+ @Override
+ public void dispose() {
+ removePropertyChangeListener(deltaCloud);
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ control = new Composite(parent, SWT.BORDER);
+ control.setLayout(new FillLayout());
+ this.viewer = createTreeViewer(control);
+ getSite().setSelectionProvider(viewer);
+ createContextMenu(viewer.getControl());
+ }
+
+ private TreeViewer createTreeViewer(Composite parent) {
+ final Tree tree = new Tree(parent, SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL |
SWT.V_SCROLL | SWT.NONE);
+ tree.setHeaderVisible(true);
+ tree.setLinesVisible(true);
+ tree.setFont(parent.getFont());
+
+ TreeColumn column = new TreeColumn(tree, SWT.SINGLE);
+ column.setText("Property");
+ TreeColumn column2 = new TreeColumn(tree, SWT.SINGLE);
+ column2.setText("Value");
+
+ tree.addControlListener(setTreeColumInitialSize(tree));
+
+ TreeViewer viewer = new TreeViewer(tree);
+ PropertySourceContentProvider provider = new PropertySourceContentProvider();
+ viewer.setContentProvider(provider);
+ viewer.setLabelProvider(provider);
+ return viewer;
+ }
+
+ private ControlAdapter setTreeColumInitialSize(final Tree tree) {
+ return new ControlAdapter() {
+ public void controlResized(ControlEvent e) {
+ Rectangle area = tree.getClientArea();
+ TreeColumn[] columns = tree.getColumns();
+ if (area.width > 0) {
+ columns[0].setWidth(area.width * 40 / 100);
+ columns[1].setWidth(area.width - columns[0].getWidth() - 4);
+ tree.removeControlListener(this);
+ }
+ }
+ };
+ }
+
+ private void createContextMenu(Control control) {
+ IMenuManager menuManager = UIUtils.createContextMenu(control);
+ UIUtils.registerContributionManager(UIUtils.getContextMenuId(ID), menuManager,
control);
+ }
+
+ @Override
+ public Control getControl() {
+ return control;
+ }
+
+ @Override
+ public void setActionBars(IActionBars actionBars) {
+ }
+
+ @Override
+ public void setFocus() {
+ viewer.getControl().setFocus();
+ }
+
+ public static class PropertySourceContentProvider extends LabelProvider
+ implements ITableLabelProvider, ITreeContentProvider {
+
+ protected IPropertySource input;
+
+ public static class CVPropertySheetPageEntry {
+ private IPropertyDescriptor descriptor;
+ private IPropertySource source;
+
+ private CVPropertySheetPageEntry(IPropertyDescriptor descriptor, IPropertySource
source) {
+ this.descriptor = descriptor;
+ this.source = source;
+ }
+
+ public String getLabel() {
+ return descriptor.getDisplayName();
+ }
+
+ public Object getValue() {
+ return source.getPropertyValue(descriptor.getId());
+ }
+
+ public String getStringValue() {
+ return String.valueOf(getValue());
+ }
+ }
+
+ public PropertySourceContentProvider() {
+ }
+
+ public Object[] getElements(Object inputElement) {
+ IPropertySource propertySource = UIUtils.adapt(inputElement, IPropertySource.class);
+ if (propertySource == null) {
+ return new Object[]{};
+ }
+ this.input = propertySource;
+ List<CVPropertySheetPageEntry> elements = new
ArrayList<CVPropertySheetPageEntry>();
+ for (IPropertyDescriptor descriptor : input.getPropertyDescriptors()) {
+ elements.add(new CVPropertySheetPageEntry(descriptor, input));
+ }
+ return elements.toArray();
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ return new Object[] {};
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ if (columnIndex == 0) {
+ return ((CVPropertySheetPageEntry) element).getLabel();
+ }
+ else if (columnIndex == 1 && element instanceof CVPropertySheetPageEntry) {
+ return String.valueOf(((CVPropertySheetPageEntry) element).getValue());
+ }
+ return null;
+ }
+ }
+
+ public void refresh() {
+ viewer.refresh();
+ }
}
Show replies by date