|
Lines 7-24
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Markus Alexander Kuppe (Versant Corp.) - https://bugs.eclipse.org/248103 |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
package org.eclipse.ui.views.properties; |
12 |
package org.eclipse.ui.views.properties; |
| 12 |
|
13 |
|
|
|
14 |
import org.eclipse.core.runtime.IStatus; |
| 15 |
import org.eclipse.core.runtime.Status; |
| 16 |
import org.eclipse.jface.action.Action; |
| 17 |
import org.eclipse.jface.action.IAction; |
| 18 |
import org.eclipse.jface.action.IMenuManager; |
| 19 |
import org.eclipse.jface.action.IToolBarManager; |
| 20 |
import org.eclipse.jface.action.Separator; |
| 13 |
import org.eclipse.jface.viewers.ISelection; |
21 |
import org.eclipse.jface.viewers.ISelection; |
| 14 |
import org.eclipse.swt.widgets.Composite; |
22 |
import org.eclipse.swt.widgets.Composite; |
|
|
23 |
import org.eclipse.ui.IMemento; |
| 15 |
import org.eclipse.ui.ISaveablePart; |
24 |
import org.eclipse.ui.ISaveablePart; |
| 16 |
import org.eclipse.ui.ISelectionListener; |
25 |
import org.eclipse.ui.ISelectionListener; |
| 17 |
import org.eclipse.ui.IViewSite; |
26 |
import org.eclipse.ui.IViewSite; |
|
|
27 |
import org.eclipse.ui.IWorkbenchActionConstants; |
| 18 |
import org.eclipse.ui.IWorkbenchPage; |
28 |
import org.eclipse.ui.IWorkbenchPage; |
| 19 |
import org.eclipse.ui.IWorkbenchPart; |
29 |
import org.eclipse.ui.IWorkbenchPart; |
| 20 |
import org.eclipse.ui.PartInitException; |
30 |
import org.eclipse.ui.PartInitException; |
|
|
31 |
import org.eclipse.ui.PlatformUI; |
| 21 |
import org.eclipse.ui.internal.views.ViewsPlugin; |
32 |
import org.eclipse.ui.internal.views.ViewsPlugin; |
|
|
33 |
import org.eclipse.ui.internal.views.properties.PropertiesMessages; |
| 22 |
import org.eclipse.ui.part.IContributedContentsView; |
34 |
import org.eclipse.ui.part.IContributedContentsView; |
| 23 |
import org.eclipse.ui.part.IPage; |
35 |
import org.eclipse.ui.part.IPage; |
| 24 |
import org.eclipse.ui.part.IPageBookViewPage; |
36 |
import org.eclipse.ui.part.IPageBookViewPage; |
|
Lines 73-78
Link Here
|
| 73 |
private ISelection bootstrapSelection; |
85 |
private ISelection bootstrapSelection; |
| 74 |
|
86 |
|
| 75 |
/** |
87 |
/** |
|
|
88 |
* The current selection of the property sheet |
| 89 |
*/ |
| 90 |
private ISelection currentSelection; |
| 91 |
|
| 92 |
/** |
| 93 |
* The current part for which this property sheets is active |
| 94 |
*/ |
| 95 |
private IWorkbenchPart currentPart; |
| 96 |
|
| 97 |
/** |
| 98 |
* Whether this property sheet instance is pinned or not |
| 99 |
*/ |
| 100 |
private IAction pinPropertySheetAction; |
| 101 |
|
| 102 |
/** |
| 103 |
* Used to identify new property sheet instances |
| 104 |
*/ |
| 105 |
//TODO create a real secondaryId in case property sheets should restore |
| 106 |
private static int SECONDARY_ID_COUNTER; |
| 107 |
|
| 108 |
/** |
| 76 |
* Creates a property sheet view. |
109 |
* Creates a property sheet view. |
| 77 |
*/ |
110 |
*/ |
| 78 |
public PropertySheet() { |
111 |
public PropertySheet() { |
|
Lines 84-101
Link Here
|
| 84 |
* Returns the default property sheet page. |
117 |
* Returns the default property sheet page. |
| 85 |
*/ |
118 |
*/ |
| 86 |
protected IPage createDefaultPage(PageBook book) { |
119 |
protected IPage createDefaultPage(PageBook book) { |
| 87 |
PropertySheetPage page = new PropertySheetPage(); |
120 |
IPageBookViewPage page = (IPageBookViewPage) ViewsPlugin.getAdapter(this, |
|
|
121 |
IPropertySheetPage.class, false); |
| 122 |
if(page == null) { |
| 123 |
page = new PropertySheetPage(); |
| 124 |
} |
| 88 |
initPage(page); |
125 |
initPage(page); |
| 89 |
page.createControl(book); |
126 |
page.createControl(book); |
| 90 |
return page; |
127 |
return page; |
| 91 |
} |
128 |
} |
| 92 |
|
129 |
|
| 93 |
/** |
130 |
/** |
| 94 |
* The <code>PropertySheet</code> implementation of this <code>IWorkbenchPart</code> |
131 |
* The <code>PropertySheet</code> implementation of this <code>IWorkbenchPart</code> |
| 95 |
* method creates a <code>PageBook</code> control with its default page showing. |
132 |
* method creates a <code>PageBook</code> control with its default page showing. |
| 96 |
*/ |
133 |
*/ |
| 97 |
public void createPartControl(Composite parent) { |
134 |
public void createPartControl(Composite parent) { |
| 98 |
super.createPartControl(parent); |
135 |
super.createPartControl(parent); |
|
|
136 |
|
| 137 |
pinPropertySheetAction = new PinPropertySheetAction(SECONDARY_ID_COUNTER); |
| 138 |
IAction newPropertySheetAction = new NewPropertySheetAction(); |
| 139 |
|
| 140 |
IMenuManager menuManager = getViewSite().getActionBars() |
| 141 |
.getMenuManager(); |
| 142 |
menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); |
| 143 |
menuManager.add(pinPropertySheetAction); |
| 144 |
menuManager.add(newPropertySheetAction); |
| 145 |
|
| 146 |
IToolBarManager toolBarManager = getViewSite().getActionBars() |
| 147 |
.getToolBarManager(); |
| 148 |
menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); |
| 149 |
toolBarManager.add(pinPropertySheetAction); |
| 150 |
toolBarManager.add(newPropertySheetAction); |
| 151 |
|
| 99 |
getSite().getPage().getWorkbenchWindow().getWorkbench().getHelpSystem() |
152 |
getSite().getPage().getWorkbenchWindow().getWorkbench().getHelpSystem() |
| 100 |
.setHelp(getPageBook(), |
153 |
.setHelp(getPageBook(), |
| 101 |
IPropertiesHelpContextIds.PROPERTY_SHEET_VIEW); |
154 |
IPropertiesHelpContextIds.PROPERTY_SHEET_VIEW); |
|
Lines 116-122
Link Here
|
| 116 |
* Method declared on PageBookView. |
169 |
* Method declared on PageBookView. |
| 117 |
*/ |
170 |
*/ |
| 118 |
protected PageRec doCreatePage(IWorkbenchPart part) { |
171 |
protected PageRec doCreatePage(IWorkbenchPart part) { |
| 119 |
// Try to get a custom property sheet page. |
172 |
// Try to get a custom property sheet page but not if the part is also a |
|
|
173 |
// PropertySheet in which case we would chain parent and child property |
| 174 |
// sheet with causes trouble if the child . |
| 175 |
if(part instanceof PropertySheet) { |
| 176 |
return null; |
| 177 |
} |
| 120 |
IPropertySheetPage page = (IPropertySheetPage) ViewsPlugin.getAdapter(part, |
178 |
IPropertySheetPage page = (IPropertySheetPage) ViewsPlugin.getAdapter(part, |
| 121 |
IPropertySheetPage.class, false); |
179 |
IPropertySheetPage.class, false); |
| 122 |
if (page != null) { |
180 |
if (page != null) { |
|
Lines 158-176
Link Here
|
| 158 |
* Method declared on IViewPart. |
216 |
* Method declared on IViewPart. |
| 159 |
*/ |
217 |
*/ |
| 160 |
public void init(IViewSite site) throws PartInitException { |
218 |
public void init(IViewSite site) throws PartInitException { |
| 161 |
site.getPage().addSelectionListener(this); |
219 |
site.getPage().addSelectionListener(this); |
| 162 |
super.init(site); |
220 |
super.init(site); |
| 163 |
} |
221 |
} |
| 164 |
|
222 |
|
| 165 |
/* (non-Javadoc) |
223 |
/* (non-Javadoc) |
|
|
224 |
* @see org.eclipse.ui.part.ViewPart#saveState(org.eclipse.ui.IMemento) |
| 225 |
*/ |
| 226 |
public void saveState(IMemento memento) { |
| 227 |
// close all but the primary/parent property sheet |
| 228 |
String secondaryId = getViewSite().getSecondaryId(); |
| 229 |
if (null == secondaryId) { |
| 230 |
super.saveState(memento); |
| 231 |
} else { |
| 232 |
getViewSite().getPage().hideView(this); |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
/* (non-Javadoc) |
| 166 |
* Method declared on PageBookView. |
237 |
* Method declared on PageBookView. |
| 167 |
* The property sheet may show properties for any view other than this view. |
238 |
* The property sheet may show properties for any view other than this view. |
| 168 |
*/ |
239 |
*/ |
| 169 |
protected boolean isImportant(IWorkbenchPart part) { |
240 |
protected boolean isImportant(IWorkbenchPart part) { |
| 170 |
return part != this; |
241 |
return pinPropertySheetAction == null |
|
|
242 |
|| (pinPropertySheetAction != null && !pinPropertySheetAction |
| 243 |
.isChecked()) && !(part instanceof PropertySheet); |
| 171 |
} |
244 |
} |
| 172 |
|
245 |
|
| 173 |
/** |
246 |
/* (non-Javadoc) |
|
|
247 |
* @see org.eclipse.ui.part.PageBookView#partClosed(org.eclipse.ui.IWorkbenchPart) |
| 248 |
*/ |
| 249 |
public void partClosed(IWorkbenchPart part) { |
| 250 |
if (pinPropertySheetAction.isChecked() && part.equals(currentPart)) { |
| 251 |
pinPropertySheetAction.setChecked(false); |
| 252 |
} |
| 253 |
super.partClosed(part); |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 174 |
* The <code>PropertySheet</code> implementation of this <code>IPartListener</code> |
257 |
* The <code>PropertySheet</code> implementation of this <code>IPartListener</code> |
| 175 |
* method first sees if the active part is an <code>IContributedContentsView</code> |
258 |
* method first sees if the active part is an <code>IContributedContentsView</code> |
| 176 |
* adapter and if so, asks it for its contributing part. |
259 |
* adapter and if so, asks it for its contributing part. |
|
Lines 190-195
Link Here
|
| 190 |
super.partActivated(part); |
273 |
super.partActivated(part); |
| 191 |
} |
274 |
} |
| 192 |
|
275 |
|
|
|
276 |
if(isImportant(part)) { |
| 277 |
currentPart = part; |
| 278 |
} |
| 279 |
|
| 193 |
// When the view is first opened, pass the selection to the page |
280 |
// When the view is first opened, pass the selection to the page |
| 194 |
if (bootstrapSelection != null) { |
281 |
if (bootstrapSelection != null) { |
| 195 |
IPropertySheetPage page = (IPropertySheetPage) getCurrentPage(); |
282 |
IPropertySheetPage page = (IPropertySheetPage) getCurrentPage(); |
|
Lines 206-219
Link Here
|
| 206 |
*/ |
293 |
*/ |
| 207 |
public void selectionChanged(IWorkbenchPart part, ISelection sel) { |
294 |
public void selectionChanged(IWorkbenchPart part, ISelection sel) { |
| 208 |
// we ignore our own selection or null selection |
295 |
// we ignore our own selection or null selection |
| 209 |
if (part == this || sel == null) { |
296 |
if (sel == null || !isImportant(part) |
|
|
297 |
|| (!isImportant(part) && sel.equals(currentSelection))) { |
| 210 |
return; |
298 |
return; |
| 211 |
} |
299 |
} |
| 212 |
|
300 |
|
|
|
301 |
currentPart = part; |
| 302 |
currentSelection = sel; |
| 303 |
|
| 213 |
// pass the selection to the page |
304 |
// pass the selection to the page |
| 214 |
IPropertySheetPage page = (IPropertySheetPage) getCurrentPage(); |
305 |
IPropertySheetPage page = (IPropertySheetPage) getCurrentPage(); |
| 215 |
if (page != null) { |
306 |
if (page != null) { |
| 216 |
page.selectionChanged(part, sel); |
307 |
page.selectionChanged(currentPart, currentSelection); |
| 217 |
} |
308 |
} |
| 218 |
} |
309 |
} |
| 219 |
|
310 |
|
|
Lines 246-249
Link Here
|
| 246 |
} |
337 |
} |
| 247 |
return null; |
338 |
return null; |
| 248 |
} |
339 |
} |
|
|
340 |
|
| 341 |
/** |
| 342 |
* Open a new view instance with the current selection. |
| 343 |
* @since 3.5 |
| 344 |
*/ |
| 345 |
private class NewPropertySheetAction extends Action { |
| 346 |
|
| 347 |
private NewPropertySheetAction() { |
| 348 |
super(PropertiesMessages.New_text); |
| 349 |
|
| 350 |
setId(NewPropertySheetAction.class.getName() |
| 351 |
+ "#" + SECONDARY_ID_COUNTER); //$NON-NLS-1$ |
| 352 |
setToolTipText(PropertiesMessages.New_toolTip); |
| 353 |
setImageDescriptor(ViewsPlugin |
| 354 |
.getViewImageDescriptor("elcl16/new.gif")); //$NON-NLS-1$ |
| 355 |
|
| 356 |
PlatformUI.getWorkbench().getHelpSystem().setHelp(this, |
| 357 |
IPropertiesHelpContextIds.NEW_ACTION); |
| 358 |
} |
| 359 |
|
| 360 |
/* |
| 361 |
* (non-Javadoc) |
| 362 |
* |
| 363 |
* @see org.eclipse.jface.action.Action#run() |
| 364 |
*/ |
| 365 |
public void run() { |
| 366 |
super.run(); |
| 367 |
try { |
| 368 |
IWorkbenchPage workbenchPage = getViewSite().getPage(); |
| 369 |
|
| 370 |
PropertySheet newSheet = (PropertySheet) workbenchPage |
| 371 |
.showView( |
| 372 |
getViewSite().getId(), |
| 373 |
PropertySheet.class.getName() |
| 374 |
+ "#" + ++SECONDARY_ID_COUNTER, IWorkbenchPage.VIEW_ACTIVATE); //$NON-NLS-1$ |
| 375 |
newSheet.partActivated(currentPart); |
| 376 |
newSheet.selectionChanged(currentPart, currentSelection); |
| 377 |
|
| 378 |
// and pin this one |
| 379 |
pinPropertySheetAction.setChecked(true); |
| 380 |
} catch (PartInitException e) { |
| 381 |
ViewsPlugin.getDefault().getLog().log( |
| 382 |
new Status(IStatus.ERROR, ViewsPlugin.PLUGIN_ID, |
| 383 |
IStatus.OK, e.getMessage(), e)); |
| 384 |
} |
| 385 |
} |
| 386 |
} |
| 249 |
} |
387 |
} |