1 11 package org.eclipse.ui.dialogs; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.jface.preference.PreferenceDialog; 15 import org.eclipse.jface.viewers.ISelectionProvider; 16 import org.eclipse.jface.viewers.IStructuredSelection; 17 import org.eclipse.jface.window.IShellProvider; 18 import org.eclipse.jface.window.SameShellProvider; 19 import org.eclipse.swt.widgets.Shell; 20 import org.eclipse.ui.PlatformUI; 21 import org.eclipse.ui.actions.SelectionProviderAction; 22 import org.eclipse.ui.internal.IWorkbenchHelpContextIds; 23 import org.eclipse.ui.internal.WorkbenchMessages; 24 import org.eclipse.ui.internal.dialogs.PropertyDialog; 25 import org.eclipse.ui.internal.dialogs.PropertyPageContributorManager; 26 27 48 public class PropertyDialogAction extends SelectionProviderAction { 49 52 private IShellProvider shellProvider; 53 54 57 private String initialPageId; 58 59 60 71 public PropertyDialogAction(Shell shell, ISelectionProvider provider) { 72 this(new SameShellProvider(shell), provider); 73 } 74 75 86 public PropertyDialogAction(IShellProvider shell, ISelectionProvider provider) { 87 super(provider, WorkbenchMessages.PropertyDialog_text); 88 Assert.isNotNull(shell); 89 this.shellProvider = shell; 90 setToolTipText(WorkbenchMessages.PropertyDialog_toolTip); 91 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, 92 IWorkbenchHelpContextIds.PROPERTY_DIALOG_ACTION); 93 } 94 95 102 private boolean hasPropertyPagesFor(Object object) { 103 return PropertyPageContributorManager.getManager().hasContributorsFor(object); 104 } 105 106 121 public boolean isApplicableForSelection() { 122 if (!isEnabled()) { 123 return false; 124 } 125 return isApplicableForSelection(getStructuredSelection()); 126 } 127 128 144 public boolean isApplicableForSelection(IStructuredSelection selection) { 145 return selection.size() == 1 && hasPropertyPagesFor(selection.getFirstElement()); 146 } 147 148 149 152 public void run() { 153 154 PreferenceDialog dialog = createDialog(); 155 if (dialog != null) { 156 dialog.open(); 157 } 158 } 159 160 168 public PreferenceDialog createDialog() { 169 170 Object element = getStructuredSelection().getFirstElement(); 171 if (element == null) { 172 return null; 173 } 174 return PropertyDialog 175 .createDialogOn(shellProvider.getShell(), initialPageId, element); 176 } 177 178 179 182 public void selectionChanged(IStructuredSelection selection) { 183 setEnabled(selection.size() == 1 && selection.getFirstElement() != null); 184 } 185 } 186 | Popular Tags |