1 11 package org.eclipse.ui.internal.dialogs; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.jface.dialogs.MessageDialog; 16 import org.eclipse.jface.preference.PreferenceManager; 17 import org.eclipse.jface.viewers.ISelection; 18 import org.eclipse.jface.viewers.StructuredSelection; 19 import org.eclipse.osgi.util.NLS; 20 import org.eclipse.swt.widgets.Shell; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.internal.IWorkbenchHelpContextIds; 23 import org.eclipse.ui.internal.WorkbenchMessages; 24 import org.eclipse.ui.internal.util.Util; 25 import org.eclipse.ui.model.IWorkbenchAdapter; 26 27 32 public class PropertyDialog extends FilteredPreferenceDialog { 33 private ISelection selection; 34 35 private static String lastPropertyId = null; 37 38 49 public static PropertyDialog createDialogOn(Shell shell, 50 final String propertyPageId, Object element) { 51 52 PropertyPageManager pageManager = new PropertyPageManager(); 53 String title = ""; 55 if (element == null) { 56 return null; 57 } 58 PropertyPageContributorManager.getManager().contribute(pageManager, 61 element); 62 Iterator pages = pageManager.getElements(PreferenceManager.PRE_ORDER) 64 .iterator(); 65 String name = getName(element); 66 if (!pages.hasNext()) { 67 MessageDialog.openInformation(shell, 68 WorkbenchMessages.PropertyDialog_messageTitle, NLS.bind( 69 WorkbenchMessages.PropertyDialog_noPropertyMessage, 70 name)); 71 return null; 72 } 73 title = NLS 74 .bind(WorkbenchMessages.PropertyDialog_propertyMessage, name); 75 PropertyDialog propertyDialog = new PropertyDialog(shell, pageManager, 76 new StructuredSelection(element)); 77 78 if (propertyPageId != null) { 79 propertyDialog.setSelectedNode(propertyPageId); 80 } 81 propertyDialog.create(); 82 83 propertyDialog.getShell().setText(title); 84 PlatformUI.getWorkbench().getHelpSystem().setHelp( 85 propertyDialog.getShell(), 86 IWorkbenchHelpContextIds.PROPERTY_DIALOG); 87 88 return propertyDialog; 89 90 } 91 92 99 private static String getName(Object element) { 100 IWorkbenchAdapter adapter = (IWorkbenchAdapter)Util.getAdapter(element, IWorkbenchAdapter.class); 101 if (adapter != null) { 102 return adapter.getLabel(element); 103 } 104 return ""; } 106 107 114 public PropertyDialog(Shell parentShell, PreferenceManager mng, 115 ISelection selection) { 116 super(parentShell, mng); 117 setSelection(selection); 118 } 119 120 125 public ISelection getSelection() { 126 return selection; 127 } 128 129 135 public void setSelection(ISelection newSelection) { 136 selection = newSelection; 137 } 138 139 142 protected String getSelectedNodePreference() { 143 return lastPropertyId; 144 } 145 146 149 protected void setSelectedNodePreference(String pageId) { 150 lastPropertyId = pageId; 151 } 152 153 } 154 | Popular Tags |