1 11 package org.eclipse.pde.internal.ui.editor.schema; 12 import org.eclipse.core.runtime.IAdaptable; 13 import org.eclipse.jface.viewers.*; 14 import org.eclipse.ui.*; 15 import org.eclipse.jface.action.*; 16 import org.eclipse.ui.views.properties.*; 17 import org.eclipse.pde.internal.ui.*; 18 19 20 public class SchemaPropertySheet extends PropertySheetPage { 21 private Action cloneAction; 22 protected ISelection currentSelection; 23 private IWorkbenchPart part; 24 public SchemaPropertySheet() { 25 makeSchemaActions(); 26 } 27 public void disableActions() { 28 cloneAction.setEnabled(false); 29 } 30 public void fillLocalToolBar(IToolBarManager toolBarManager) { 31 toolBarManager.add(new Separator()); 32 toolBarManager.add(cloneAction); 33 } 34 public IPropertySheetEntry getSelectedEntry() { 35 if(!currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) 36 return (IPropertySheetEntry) ((IStructuredSelection)currentSelection).getFirstElement(); 37 return null; 38 } 39 protected void handleClone() { 40 Object input = null; 41 if (currentSelection instanceof IStructuredSelection) { 42 input = ((IStructuredSelection) currentSelection).getFirstElement(); 43 } 44 IPropertySource source = null; 45 if (input instanceof IAdaptable) { 46 source = (IPropertySource) ((IAdaptable) input) 47 .getAdapter(IPropertySource.class); 48 } 49 if (source instanceof ICloneablePropertySource) { 50 Object newInput = ((ICloneablePropertySource) source).doClone(); 51 if (newInput != null) { 52 selectionChanged(part, new StructuredSelection(newInput)); 53 } 54 } 55 } 56 public void makeContributions(IMenuManager menuManager, 57 IToolBarManager toolBarManager, IStatusLineManager statusLineManager) { 58 super.makeContributions(menuManager, toolBarManager, statusLineManager); 59 fillLocalToolBar(toolBarManager); 60 } 61 protected void makeSchemaActions() { 62 cloneAction = new Action(PDEUIMessages.SchemaPropertySheet_clone_label) { 63 public void run() { 64 handleClone(); 65 } 66 }; 67 cloneAction.setImageDescriptor(PDEPluginImages.DESC_CLONE_ATT); 68 cloneAction 69 .setDisabledImageDescriptor(PDEPluginImages.DESC_CLONE_ATT_DISABLED); 70 cloneAction.setToolTipText(PDEUIMessages.SchemaPropertySheet_clone_tooltip); 71 cloneAction.setEnabled(false); 72 } 73 public void selectionChanged(IWorkbenchPart part, ISelection sel) { 74 super.selectionChanged(part, sel); 75 this.part = part; 76 currentSelection = sel; 77 updateActions(); 78 } 79 protected void updateActions() { 80 Object input = null; 81 if (currentSelection instanceof IStructuredSelection) { 82 input = ((IStructuredSelection) currentSelection).getFirstElement(); 83 } 84 IPropertySource source = null; 85 if (input instanceof IAdaptable) { 86 source = (IPropertySource) ((IAdaptable) input) 87 .getAdapter(IPropertySource.class); 88 } 89 updateActions(source); 90 } 91 protected void updateActions(IPropertySource source) { 92 if (source instanceof ICloneablePropertySource) { 93 cloneAction.setEnabled(((ICloneablePropertySource) source) 94 .isCloneable()); 95 } else 96 cloneAction.setEnabled(false); 97 } 98 } 99 | Popular Tags |