|
Lines 13-18
Link Here
|
| 13 |
import java.util.Iterator; |
13 |
import java.util.Iterator; |
| 14 |
|
14 |
|
| 15 |
import org.eclipse.core.runtime.IAdaptable; |
15 |
import org.eclipse.core.runtime.IAdaptable; |
|
|
16 |
import org.eclipse.core.runtime.Platform; |
| 16 |
import org.eclipse.jface.dialogs.MessageDialog; |
17 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 17 |
import org.eclipse.jface.preference.PreferenceManager; |
18 |
import org.eclipse.jface.preference.PreferenceManager; |
| 18 |
import org.eclipse.jface.viewers.ISelection; |
19 |
import org.eclipse.jface.viewers.ISelection; |
|
Lines 30-54
Link Here
|
| 30 |
* type. |
31 |
* type. |
| 31 |
*/ |
32 |
*/ |
| 32 |
public class PropertyDialog extends FilteredPreferenceDialog { |
33 |
public class PropertyDialog extends FilteredPreferenceDialog { |
| 33 |
private ISelection selection; |
34 |
private ISelection selection; |
| 34 |
|
35 |
|
| 35 |
//The id of the last page that was selected |
36 |
// The id of the last page that was selected |
| 36 |
private static String lastPropertyId = null; |
37 |
private static String lastPropertyId = null; |
| 37 |
|
38 |
|
| 38 |
|
39 |
/** |
| 39 |
/** |
40 |
* Create a new property dialog. |
| 40 |
* Create a new property dialog. |
41 |
* |
| 41 |
* |
42 |
* @param shell |
| 42 |
* @param shell the parent shell |
43 |
* the parent shell |
| 43 |
* @param propertyPageId the property page id |
44 |
* @param propertyPageId |
| 44 |
* @param element the adaptable element |
45 |
* the property page id |
| 45 |
* @return the property dialog |
46 |
* @param element |
| 46 |
*/ |
47 |
* the adaptable element |
| 47 |
public static PropertyDialog createDialogOn(Shell shell,final String propertyPageId, IAdaptable element){ |
48 |
* @return the property dialog |
|
|
49 |
*/ |
| 50 |
public static PropertyDialog createDialogOn(Shell shell, |
| 51 |
final String propertyPageId, Object element) { |
| 48 |
|
52 |
|
| 49 |
PropertyPageManager pageManager = new PropertyPageManager(); |
53 |
PropertyPageManager pageManager = new PropertyPageManager(); |
| 50 |
String title = "";//$NON-NLS-1$ |
54 |
String title = "";//$NON-NLS-1$ |
| 51 |
|
55 |
|
| 52 |
if (element == null) |
56 |
if (element == null) |
| 53 |
return null; |
57 |
return null; |
| 54 |
// load pages for the selection |
58 |
// load pages for the selection |
|
Lines 60-73
Link Here
|
| 60 |
.iterator(); |
64 |
.iterator(); |
| 61 |
String name = getName(element); |
65 |
String name = getName(element); |
| 62 |
if (!pages.hasNext()) { |
66 |
if (!pages.hasNext()) { |
| 63 |
MessageDialog |
67 |
MessageDialog.openInformation(shell, |
| 64 |
.openInformation( |
68 |
WorkbenchMessages.PropertyDialog_messageTitle, NLS.bind( |
| 65 |
shell, |
69 |
WorkbenchMessages.PropertyDialog_noPropertyMessage, |
| 66 |
WorkbenchMessages.PropertyDialog_messageTitle, |
70 |
name)); |
| 67 |
NLS.bind(WorkbenchMessages.PropertyDialog_noPropertyMessage, name)); |
|
|
| 68 |
return null; |
71 |
return null; |
| 69 |
} |
72 |
} |
| 70 |
title = NLS.bind(WorkbenchMessages.PropertyDialog_propertyMessage, name ); |
73 |
title = NLS |
|
|
74 |
.bind(WorkbenchMessages.PropertyDialog_propertyMessage, name); |
| 71 |
PropertyDialog propertyDialog = new PropertyDialog(shell, pageManager, |
75 |
PropertyDialog propertyDialog = new PropertyDialog(shell, pageManager, |
| 72 |
new StructuredSelection(element)); |
76 |
new StructuredSelection(element)); |
| 73 |
|
77 |
|
|
Lines 81-148
Link Here
|
| 81 |
IWorkbenchHelpContextIds.PROPERTY_DIALOG); |
85 |
IWorkbenchHelpContextIds.PROPERTY_DIALOG); |
| 82 |
|
86 |
|
| 83 |
return propertyDialog; |
87 |
return propertyDialog; |
| 84 |
|
88 |
|
| 85 |
} |
89 |
} |
| 86 |
|
90 |
|
| 87 |
/** |
91 |
/** |
| 88 |
* Returns the name of the given element. |
92 |
* Returns the name of the given element. |
| 89 |
* |
93 |
* |
| 90 |
* @param element |
94 |
* @param element |
| 91 |
* the element |
95 |
* the element |
| 92 |
* @return the name of the element |
96 |
* @return the name of the element |
| 93 |
*/ |
97 |
*/ |
| 94 |
private static String getName(IAdaptable element) { |
98 |
private static String getName(Object element) { |
| 95 |
IWorkbenchAdapter adapter = (IWorkbenchAdapter) element |
99 |
IWorkbenchAdapter adapter = null; |
| 96 |
.getAdapter(IWorkbenchAdapter.class); |
100 |
if (element instanceof IAdaptable) { |
| 97 |
if (adapter != null) |
101 |
adapter = (IWorkbenchAdapter) ((IAdaptable) element) |
|
|
102 |
.getAdapter(IWorkbenchAdapter.class); |
| 103 |
} else { |
| 104 |
adapter = (IWorkbenchAdapter) Platform.getAdapterManager() |
| 105 |
.getAdapter(element, IWorkbenchAdapter.class); |
| 106 |
} |
| 107 |
if (adapter != null) |
| 98 |
return adapter.getLabel(element); |
108 |
return adapter.getLabel(element); |
| 99 |
return "";//$NON-NLS-1$ |
109 |
return "";//$NON-NLS-1$ |
| 100 |
} |
110 |
} |
| 101 |
|
|
|
| 102 |
/** |
| 103 |
* Create an instance of the receiver. |
| 104 |
* @param parentShell |
| 105 |
* @param mng |
| 106 |
* @param selection |
| 107 |
*/ |
| 108 |
public PropertyDialog(Shell parentShell, PreferenceManager mng, |
| 109 |
ISelection selection) { |
| 110 |
super(parentShell, mng); |
| 111 |
setSelection(selection); |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Returns selection in the "Properties" action context. |
| 116 |
* |
| 117 |
* @return the selection |
| 118 |
*/ |
| 119 |
public ISelection getSelection() { |
| 120 |
return selection; |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Sets the selection that will be used to determine target object. |
| 125 |
* |
| 126 |
* @param newSelection the new selection |
| 127 |
*/ |
| 128 |
public void setSelection(ISelection newSelection) { |
| 129 |
selection = newSelection; |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Get the name of the selected item preference |
| 134 |
*/ |
| 135 |
protected String getSelectedNodePreference() { |
| 136 |
return lastPropertyId; |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Get the name of the selected item preference |
| 141 |
*/ |
| 142 |
protected void setSelectedNodePreference(String pageId) { |
| 143 |
lastPropertyId = pageId; |
| 144 |
} |
| 145 |
|
| 146 |
|
111 |
|
|
|
112 |
/** |
| 113 |
* Create an instance of the receiver. |
| 114 |
* |
| 115 |
* @param parentShell |
| 116 |
* @param mng |
| 117 |
* @param selection |
| 118 |
*/ |
| 119 |
public PropertyDialog(Shell parentShell, PreferenceManager mng, |
| 120 |
ISelection selection) { |
| 121 |
super(parentShell, mng); |
| 122 |
setSelection(selection); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Returns selection in the "Properties" action context. |
| 127 |
* |
| 128 |
* @return the selection |
| 129 |
*/ |
| 130 |
public ISelection getSelection() { |
| 131 |
return selection; |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Sets the selection that will be used to determine target object. |
| 136 |
* |
| 137 |
* @param newSelection |
| 138 |
* the new selection |
| 139 |
*/ |
| 140 |
public void setSelection(ISelection newSelection) { |
| 141 |
selection = newSelection; |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* Get the name of the selected item preference |
| 146 |
*/ |
| 147 |
protected String getSelectedNodePreference() { |
| 148 |
return lastPropertyId; |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Get the name of the selected item preference |
| 153 |
*/ |
| 154 |
protected void setSelectedNodePreference(String pageId) { |
| 155 |
lastPropertyId = pageId; |
| 156 |
} |
| 147 |
|
157 |
|
| 148 |
} |
158 |
} |