| 1 |
/** |
| 2 |
* Copyright (c) 2005-2012 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v2.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v20.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM - Initial API and implementation |
| 10 |
*/ |
| 11 |
package org.eclipse.emf.edit.ui.view; |
| 12 |
|
| 13 |
import java.lang.reflect.Field; |
| 14 |
import java.util.ArrayList; |
| 15 |
import java.util.Collection; |
| 16 |
import java.util.Collections; |
| 17 |
import java.util.List; |
| 18 |
import java.util.Map; |
| 19 |
|
| 20 |
import org.eclipse.emf.common.ui.viewer.ColumnResizer; |
| 21 |
import org.eclipse.emf.common.ui.viewer.ColumnResizer.Handler; |
| 22 |
import org.eclipse.emf.common.util.Diagnostic; |
| 23 |
import org.eclipse.emf.ecore.EObject; |
| 24 |
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; |
| 25 |
import org.eclipse.emf.edit.provider.IItemPropertySource; |
| 26 |
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; |
| 27 |
import org.eclipse.emf.edit.ui.EMFEditUIPlugin; |
| 28 |
import org.eclipse.emf.edit.ui.provider.DiagnosticDecorator; |
| 29 |
import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry; |
| 30 |
import org.eclipse.emf.edit.ui.provider.PropertyDescriptor; |
| 31 |
import org.eclipse.jface.action.Action; |
| 32 |
import org.eclipse.jface.action.ActionContributionItem; |
| 33 |
import org.eclipse.jface.action.IAction; |
| 34 |
import org.eclipse.jface.action.IContributionItem; |
| 35 |
import org.eclipse.jface.action.IContributionManagerOverrides; |
| 36 |
import org.eclipse.jface.action.IMenuManager; |
| 37 |
import org.eclipse.jface.action.IStatusLineManager; |
| 38 |
import org.eclipse.jface.action.IToolBarManager; |
| 39 |
import org.eclipse.jface.dialogs.IDialogSettings; |
| 40 |
import org.eclipse.jface.text.IFindReplaceTarget; |
| 41 |
import org.eclipse.jface.viewers.CellEditor; |
| 42 |
import org.eclipse.jface.viewers.ISelection; |
| 43 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 44 |
import org.eclipse.jface.viewers.StructuredSelection; |
| 45 |
import org.eclipse.jface.viewers.Viewer; |
| 46 |
import org.eclipse.swt.SWT; |
| 47 |
import org.eclipse.swt.SWTError; |
| 48 |
import org.eclipse.swt.dnd.Clipboard; |
| 49 |
import org.eclipse.swt.dnd.TextTransfer; |
| 50 |
import org.eclipse.swt.dnd.Transfer; |
| 51 |
import org.eclipse.swt.events.SelectionEvent; |
| 52 |
import org.eclipse.swt.events.SelectionListener; |
| 53 |
import org.eclipse.swt.graphics.Image; |
| 54 |
import org.eclipse.swt.widgets.Composite; |
| 55 |
import org.eclipse.swt.widgets.Control; |
| 56 |
import org.eclipse.swt.widgets.Event; |
| 57 |
import org.eclipse.swt.widgets.Menu; |
| 58 |
import org.eclipse.swt.widgets.Tree; |
| 59 |
import org.eclipse.swt.widgets.TreeItem; |
| 60 |
import org.eclipse.ui.ISharedImages; |
| 61 |
import org.eclipse.ui.IWorkbenchPart; |
| 62 |
import org.eclipse.ui.PlatformUI; |
| 63 |
import org.eclipse.ui.views.properties.IPropertyDescriptor; |
| 64 |
import org.eclipse.ui.views.properties.IPropertySheetEntry; |
| 65 |
import org.eclipse.ui.views.properties.IPropertySource; |
| 66 |
import org.eclipse.ui.views.properties.IPropertySource2; |
| 67 |
import org.eclipse.ui.views.properties.IPropertySourceProvider; |
| 68 |
import org.eclipse.ui.views.properties.PropertySheetEntry; |
| 69 |
import org.eclipse.ui.views.properties.PropertySheetPage; |
| 70 |
|
| 71 |
/** |
| 72 |
* This property sheet page has an additional button in its local toolbar that locates the value of the |
| 73 |
* selected property in the editor. |
| 74 |
* It also supports {@link #ExtendedPropertySheetPage(AdapterFactoryEditingDomain, Decoration) decorating} the property values to indicate bad values. |
| 75 |
*/ |
| 76 |
public class ExtendedPropertySheetPage extends PropertySheetPage |
| 77 |
{ |
| 78 |
/** |
| 79 |
* @since 2.9 |
| 80 |
*/ |
| 81 |
public static enum Decoration |
| 82 |
{ |
| 83 |
NONE, MANUAL, LIVE |
| 84 |
} |
| 85 |
|
| 86 |
protected List<Object> objectsToSelect = new ArrayList<Object>(); |
| 87 |
|
| 88 |
protected AdapterFactoryEditingDomain editingDomain; |
| 89 |
|
| 90 |
/** |
| 91 |
* @since 2.9 |
| 92 |
*/ |
| 93 |
protected DiagnosticDecorator diagnosticDecorator; |
| 94 |
|
| 95 |
/** |
| 96 |
* @since 2.9 |
| 97 |
*/ |
| 98 |
protected IDialogSettings dialogSettings; |
| 99 |
|
| 100 |
/** |
| 101 |
* @since 2.9 |
| 102 |
*/ |
| 103 |
protected List<?> input = Collections.emptyList(); |
| 104 |
|
| 105 |
/** |
| 106 |
* @since 2.9 |
| 107 |
*/ |
| 108 |
protected IPropertySourceProvider propertySourceProvider; |
| 109 |
|
| 110 |
protected IAction locateValueAction = new LocateValueAction(); |
| 111 |
|
| 112 |
/** |
| 113 |
* @since 2.14 |
| 114 |
*/ |
| 115 |
protected IWorkbenchPart workbenchPart; |
| 116 |
|
| 117 |
protected class LocateValueAction extends Action |
| 118 |
{ |
| 119 |
public LocateValueAction() |
| 120 |
{ |
| 121 |
setText(EMFEditUIPlugin.INSTANCE.getString("_UI_LocateValue_action")); |
| 122 |
setToolTipText(EMFEditUIPlugin.INSTANCE.getString("_UI_LocateValue_action_tool_tip")); |
| 123 |
setImageDescriptor(ExtendedImageRegistry.INSTANCE.getImageDescriptor(EMFEditUIPlugin.INSTANCE.getImage("full/elcl16/LocateValue"))); |
| 124 |
setDisabledImageDescriptor(ExtendedImageRegistry.INSTANCE.getImageDescriptor(EMFEditUIPlugin.INSTANCE.getImage("full/dlcl16/LocateValue"))); |
| 125 |
} |
| 126 |
|
| 127 |
@Override |
| 128 |
public void run() |
| 129 |
{ |
| 130 |
List<Object> selection = new ArrayList<Object>(); |
| 131 |
for (Object object : objectsToSelect) |
| 132 |
{ |
| 133 |
selection.add(editingDomain.getWrapper(object)); |
| 134 |
} |
| 135 |
setSelectionToViewer(selection); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* @since 2.14 |
| 141 |
*/ |
| 142 |
protected static class SetValueAction extends Action |
| 143 |
{ |
| 144 |
protected ExtendedPropertySheetEntry entry; |
| 145 |
|
| 146 |
public SetValueAction() |
| 147 |
{ |
| 148 |
setText(EMFEditUIPlugin.INSTANCE.getString("_UI_SetValue_action")); |
| 149 |
setToolTipText(EMFEditUIPlugin.INSTANCE.getString("_UI_SetValue_action_tool_tip")); |
| 150 |
setImageDescriptor(ExtendedImageRegistry.INSTANCE.getImageDescriptor(EMFEditUIPlugin.INSTANCE.getImage("full/elcl16/SetProperty.png"))); |
| 151 |
setDisabledImageDescriptor(ExtendedImageRegistry.INSTANCE.getImageDescriptor(EMFEditUIPlugin.INSTANCE.getImage("full/dlcl16/SetProperty.png"))); |
| 152 |
} |
| 153 |
|
| 154 |
@Override |
| 155 |
public void run() |
| 156 |
{ |
| 157 |
entry.setPropertyValue(); |
| 158 |
} |
| 159 |
|
| 160 |
public void setEntry(ExtendedPropertySheetEntry entry) |
| 161 |
{ |
| 162 |
this.entry = entry; |
| 163 |
setEnabled(entry != null && entry.isSetValueEnabled()); |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
/** |
| 168 |
* @since 2.14 |
| 169 |
*/ |
| 170 |
protected SetValueAction setValueAction = new SetValueAction(); |
| 171 |
|
| 172 |
/** |
| 173 |
* @since 2.14 |
| 174 |
*/ |
| 175 |
protected IAction restoreValueAction; |
| 176 |
|
| 177 |
/** |
| 178 |
* @since 2.14 |
| 179 |
*/ |
| 180 |
protected int autoExpandLevel; |
| 181 |
|
| 182 |
/** |
| 183 |
* @since 2.14 |
| 184 |
*/ |
| 185 |
protected boolean autoResizeColumns; |
| 186 |
|
| 187 |
/** |
| 188 |
* @since 2.14 |
| 189 |
*/ |
| 190 |
protected Handler columnResizer; |
| 191 |
|
| 192 |
/** |
| 193 |
* @since 2.14 |
| 194 |
*/ |
| 195 |
protected Clipboard clipboard = new Clipboard(PlatformUI.getWorkbench().getDisplay()); |
| 196 |
|
| 197 |
/** |
| 198 |
* @since 2.14 |
| 199 |
*/ |
| 200 |
protected CopyValuePropertyAction copyPropertyValueAction = new CopyValuePropertyAction(clipboard); |
| 201 |
|
| 202 |
private ExtendedPropertySheetEntry rootEntry; |
| 203 |
|
| 204 |
private IAction filterAction; |
| 205 |
|
| 206 |
private IAction categoriesAction; |
| 207 |
|
| 208 |
public ExtendedPropertySheetPage(AdapterFactoryEditingDomain editingDomain) |
| 209 |
{ |
| 210 |
this(editingDomain, Decoration.NONE, null, 0, false); |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* @since 2.9 |
| 215 |
*/ |
| 216 |
public ExtendedPropertySheetPage(AdapterFactoryEditingDomain editingDomain, Decoration decoration) |
| 217 |
{ |
| 218 |
this(editingDomain, decoration, null, 0, false); |
| 219 |
} |
| 220 |
|
| 221 |
/** |
| 222 |
* @since 2.9 |
| 223 |
*/ |
| 224 |
public ExtendedPropertySheetPage(AdapterFactoryEditingDomain editingDomain, Decoration decoration, IDialogSettings dialogSettings) |
| 225 |
{ |
| 226 |
this(editingDomain, decoration, dialogSettings, 0, false); |
| 227 |
} |
| 228 |
|
| 229 |
/** |
| 230 |
* @since 2.14 |
| 231 |
*/ |
| 232 |
public ExtendedPropertySheetPage(AdapterFactoryEditingDomain editingDomain, Decoration decoration, IDialogSettings dialogSettings, int autoExpandLevel, boolean autoResizeColumns) |
| 233 |
{ |
| 234 |
this.editingDomain = editingDomain; |
| 235 |
this.dialogSettings = dialogSettings; |
| 236 |
this.autoExpandLevel = autoExpandLevel; |
| 237 |
this.autoResizeColumns = autoResizeColumns; |
| 238 |
this.autoResizeColumns = autoResizeColumns; |
| 239 |
diagnosticDecorator = createDiagnosticDecorator(decoration); |
| 240 |
} |
| 241 |
|
| 242 |
/** |
| 243 |
* @since 2.14 |
| 244 |
*/ |
| 245 |
public IAction getFilterAction() |
| 246 |
{ |
| 247 |
return filterAction; |
| 248 |
} |
| 249 |
|
| 250 |
/** |
| 251 |
* @since 2.14 |
| 252 |
*/ |
| 253 |
public IAction getCategoriesAction() |
| 254 |
{ |
| 255 |
return categoriesAction; |
| 256 |
} |
| 257 |
|
| 258 |
/** |
| 259 |
* @since 2.9 |
| 260 |
*/ |
| 261 |
protected DiagnosticDecorator createDiagnosticDecorator(Decoration decoration) |
| 262 |
{ |
| 263 |
switch (decoration) |
| 264 |
{ |
| 265 |
case MANUAL: |
| 266 |
{ |
| 267 |
return new DiagnosticDecorator(editingDomain.getResourceSet(), this); |
| 268 |
} |
| 269 |
case LIVE: |
| 270 |
{ |
| 271 |
return new DiagnosticDecorator(editingDomain, this, dialogSettings); |
| 272 |
} |
| 273 |
default: |
| 274 |
{ |
| 275 |
return null; |
| 276 |
} |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
@Override |
| 281 |
public void setPropertySourceProvider(IPropertySourceProvider newProvider) |
| 282 |
{ |
| 283 |
propertySourceProvider = newProvider; |
| 284 |
super.setPropertySourceProvider(newProvider); |
| 285 |
} |
| 286 |
|
| 287 |
@Override |
| 288 |
public void createControl(Composite parent) |
| 289 |
{ |
| 290 |
super.createControl(parent); |
| 291 |
|
| 292 |
// Always create our extension of a property sheet entry. |
| 293 |
// |
| 294 |
ExtendedPropertySheetEntry decoratingPropertySheetEntry = new ExtendedPropertySheetEntry(diagnosticDecorator); |
| 295 |
decoratingPropertySheetEntry.setPropertySourceProvider(propertySourceProvider); |
| 296 |
rootEntry = decoratingPropertySheetEntry; |
| 297 |
setRootEntry(decoratingPropertySheetEntry); |
| 298 |
|
| 299 |
// The property sheet page's viewer does not respond to widget selected events in a way that updates the current entry selection. |
| 300 |
// This ensures that we can update the tool bar actions when the selection is changed via the keyboard. |
| 301 |
// |
| 302 |
final Tree tree = (Tree)getControl(); |
| 303 |
tree.addSelectionListener(new SelectionListener() |
| 304 |
{ |
| 305 |
public void widgetSelected(SelectionEvent e) |
| 306 |
{ |
| 307 |
Object data = e.item.getData(); |
| 308 |
handleEntrySelection(new StructuredSelection(data)); |
| 309 |
} |
| 310 |
|
| 311 |
public void widgetDefaultSelected(SelectionEvent e) |
| 312 |
{ |
| 313 |
} |
| 314 |
}); |
| 315 |
|
| 316 |
if (autoResizeColumns) |
| 317 |
{ |
| 318 |
columnResizer = ColumnResizer.addColumnResizer(tree); |
| 319 |
} |
| 320 |
|
| 321 |
Menu menu = getControl().getMenu(); |
| 322 |
IMenuManager menuManager = (IMenuManager)menu.getData("org.eclipse.jface.action.MenuManager.managerKey"); |
| 323 |
if (menuManager != null) |
| 324 |
{ |
| 325 |
menuManager.insertAfter("copy", copyPropertyValueAction); |
| 326 |
menuManager.insertAfter("defaults", setValueAction); |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
/** |
| 331 |
* This method should be overridden to set the selection. |
| 332 |
*/ |
| 333 |
protected void setSelectionToViewer(List<?> selection) |
| 334 |
{ |
| 335 |
// Do nothing. |
| 336 |
} |
| 337 |
|
| 338 |
@Override |
| 339 |
public void makeContributions(IMenuManager menuManager, final IToolBarManager toolBarManager, IStatusLineManager statusLineManager) |
| 340 |
{ |
| 341 |
class DelegatingToolBarManager implements IToolBarManager |
| 342 |
{ |
| 343 |
public void add(IAction action) |
| 344 |
{ |
| 345 |
if ("defaults".equals(action.getId())) |
| 346 |
{ |
| 347 |
restoreValueAction = action; |
| 348 |
if (setValueAction != null) |
| 349 |
{ |
| 350 |
toolBarManager.add(setValueAction); |
| 351 |
} |
| 352 |
} |
| 353 |
toolBarManager.add(action); |
| 354 |
} |
| 355 |
|
| 356 |
public void add(IContributionItem item) |
| 357 |
{ |
| 358 |
toolBarManager.add(item); |
| 359 |
} |
| 360 |
|
| 361 |
public void appendToGroup(String groupName, IAction action) |
| 362 |
{ |
| 363 |
toolBarManager.appendToGroup(groupName, action); |
| 364 |
} |
| 365 |
|
| 366 |
public void appendToGroup(String groupName, IContributionItem item) |
| 367 |
{ |
| 368 |
toolBarManager.appendToGroup(groupName, item); |
| 369 |
} |
| 370 |
|
| 371 |
public IContributionItem find(String id) |
| 372 |
{ |
| 373 |
return toolBarManager.find(id); |
| 374 |
} |
| 375 |
|
| 376 |
public IContributionItem[] getItems() |
| 377 |
{ |
| 378 |
return toolBarManager.getItems(); |
| 379 |
} |
| 380 |
|
| 381 |
public IContributionManagerOverrides getOverrides() |
| 382 |
{ |
| 383 |
return toolBarManager.getOverrides(); |
| 384 |
} |
| 385 |
|
| 386 |
public void insertAfter(String id, IAction action) |
| 387 |
{ |
| 388 |
toolBarManager.insertAfter(id, action); |
| 389 |
} |
| 390 |
|
| 391 |
public void insertAfter(String id, IContributionItem item) |
| 392 |
{ |
| 393 |
toolBarManager.insertAfter(id, item); |
| 394 |
} |
| 395 |
|
| 396 |
public void insertBefore(String id, IAction action) |
| 397 |
{ |
| 398 |
toolBarManager.insertBefore(id, action); |
| 399 |
} |
| 400 |
|
| 401 |
public void insertBefore(String id, IContributionItem item) |
| 402 |
{ |
| 403 |
toolBarManager.insertBefore(id, item); |
| 404 |
} |
| 405 |
|
| 406 |
public boolean isDirty() |
| 407 |
{ |
| 408 |
return toolBarManager.isDirty(); |
| 409 |
} |
| 410 |
|
| 411 |
public boolean isEmpty() |
| 412 |
{ |
| 413 |
return toolBarManager.isEmpty(); |
| 414 |
} |
| 415 |
|
| 416 |
public void markDirty() |
| 417 |
{ |
| 418 |
toolBarManager.markDirty(); |
| 419 |
} |
| 420 |
|
| 421 |
public void prependToGroup(String groupName, IAction action) |
| 422 |
{ |
| 423 |
toolBarManager.prependToGroup(groupName, action); |
| 424 |
} |
| 425 |
|
| 426 |
public void prependToGroup(String groupName, IContributionItem item) |
| 427 |
{ |
| 428 |
toolBarManager.prependToGroup(groupName, item); |
| 429 |
} |
| 430 |
|
| 431 |
public IContributionItem remove(String id) |
| 432 |
{ |
| 433 |
return toolBarManager.remove(id); |
| 434 |
} |
| 435 |
|
| 436 |
public IContributionItem remove(IContributionItem item) |
| 437 |
{ |
| 438 |
return toolBarManager.remove(item); |
| 439 |
} |
| 440 |
|
| 441 |
public void removeAll() |
| 442 |
{ |
| 443 |
toolBarManager.removeAll(); |
| 444 |
} |
| 445 |
|
| 446 |
public void update(boolean force) |
| 447 |
{ |
| 448 |
toolBarManager.update(force); |
| 449 |
} |
| 450 |
} |
| 451 |
|
| 452 |
super.makeContributions(menuManager, new DelegatingToolBarManager(), statusLineManager); |
| 453 |
toolBarManager.add(locateValueAction); |
| 454 |
for (IContributionItem contributionItem : toolBarManager.getItems()) |
| 455 |
{ |
| 456 |
if ("filter".equals(contributionItem.getId()) && contributionItem instanceof ActionContributionItem) |
| 457 |
{ |
| 458 |
filterAction = ((ActionContributionItem)contributionItem).getAction(); |
| 459 |
} |
| 460 |
else if ("categories".equals(contributionItem.getId()) && contributionItem instanceof ActionContributionItem) |
| 461 |
{ |
| 462 |
categoriesAction = ((ActionContributionItem)contributionItem).getAction(); |
| 463 |
} |
| 464 |
} |
| 465 |
} |
| 466 |
|
| 467 |
@Override |
| 468 |
public void handleEntrySelection(ISelection selection) |
| 469 |
{ |
| 470 |
ExtendedPropertySheetEntry entry = null; |
| 471 |
objectsToSelect.clear(); |
| 472 |
if (!selection.isEmpty() && selection instanceof IStructuredSelection) |
| 473 |
{ |
| 474 |
IStructuredSelection structuredSelection = (IStructuredSelection)selection; |
| 475 |
if (structuredSelection.size() == 1) |
| 476 |
{ |
| 477 |
Object object = structuredSelection.getFirstElement(); |
| 478 |
if (object instanceof ExtendedPropertySheetEntry) |
| 479 |
{ |
| 480 |
entry = (ExtendedPropertySheetEntry)object; |
| 481 |
|
| 482 |
Object [] values = entry.getValues(); |
| 483 |
if (values != null) |
| 484 |
{ |
| 485 |
for (int i = 0; i < values.length; ++i) |
| 486 |
{ |
| 487 |
Object value = values[i]; |
| 488 |
if (value instanceof IItemPropertySource) |
| 489 |
{ |
| 490 |
Object realValue = ((IItemPropertySource)value).getEditableValue(null); |
| 491 |
if (realValue instanceof Collection<?>) |
| 492 |
{ |
| 493 |
for (Object o : (Collection<?>)realValue) |
| 494 |
{ |
| 495 |
addObjectToSelect(o); |
| 496 |
} |
| 497 |
} |
| 498 |
else |
| 499 |
{ |
| 500 |
addObjectToSelect(realValue); |
| 501 |
} |
| 502 |
} |
| 503 |
} |
| 504 |
} |
| 505 |
} |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
locateValueAction.setEnabled(!objectsToSelect.isEmpty()); |
| 510 |
|
| 511 |
if (restoreValueAction == null || entry == null) |
| 512 |
{ |
| 513 |
super.handleEntrySelection(selection); |
| 514 |
} |
| 515 |
else |
| 516 |
{ |
| 517 |
restoreValueAction.setEnabled(entry.isRestoreValueEnabled()); |
| 518 |
} |
| 519 |
|
| 520 |
copyPropertyValueAction.selectionChanged(selection); |
| 521 |
|
| 522 |
if (setValueAction != null) |
| 523 |
{ |
| 524 |
setValueAction.setEntry(entry); |
| 525 |
} |
| 526 |
} |
| 527 |
|
| 528 |
protected void addObjectToSelect(Object object) |
| 529 |
{ |
| 530 |
if (object instanceof EObject) |
| 531 |
{ |
| 532 |
objectsToSelect.add(object); |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
@Override |
| 537 |
public void selectionChanged(IWorkbenchPart part, ISelection selection) |
| 538 |
{ |
| 539 |
workbenchPart = part; |
| 540 |
if (selection instanceof IStructuredSelection) |
| 541 |
{ |
| 542 |
input = ((IStructuredSelection)selection).toList(); |
| 543 |
} |
| 544 |
else |
| 545 |
{ |
| 546 |
input = Collections.emptyList(); |
| 547 |
} |
| 548 |
|
| 549 |
Tree tree = (Tree)getControl(); |
| 550 |
if (tree != null) |
| 551 |
{ |
| 552 |
try |
| 553 |
{ |
| 554 |
tree.setRedraw(false); |
| 555 |
super.selectionChanged(part, selection); |
| 556 |
} |
| 557 |
finally |
| 558 |
{ |
| 559 |
if (columnResizer != null) |
| 560 |
{ |
| 561 |
columnResizer.resizeColumns(); |
| 562 |
} |
| 563 |
tree.setRedraw(true); |
| 564 |
} |
| 565 |
|
| 566 |
if (autoExpandLevel != 0) |
| 567 |
{ |
| 568 |
try |
| 569 |
{ |
| 570 |
tree.setRedraw(false); |
| 571 |
expand(tree, tree.getItems(), autoExpandLevel); |
| 572 |
} |
| 573 |
finally |
| 574 |
{ |
| 575 |
tree.setRedraw(true); |
| 576 |
} |
| 577 |
} |
| 578 |
} |
| 579 |
} |
| 580 |
|
| 581 |
private void expand(Tree tree, TreeItem[] items, int level) |
| 582 |
{ |
| 583 |
if (level != 0) |
| 584 |
{ |
| 585 |
for (TreeItem treeItem : items) |
| 586 |
{ |
| 587 |
Event event = new Event(); |
| 588 |
event.item = treeItem; |
| 589 |
if (!treeItem.getExpanded()) |
| 590 |
{ |
| 591 |
tree.notifyListeners(SWT.Expand, event); |
| 592 |
treeItem.setExpanded(true); |
| 593 |
} |
| 594 |
expand(tree, treeItem.getItems(), level - 1); |
| 595 |
} |
| 596 |
} |
| 597 |
} |
| 598 |
|
| 599 |
/** |
| 600 |
* Provides access to the current input to the page. |
| 601 |
* |
| 602 |
* @since 2.9 |
| 603 |
*/ |
| 604 |
public List<?> getInput() |
| 605 |
{ |
| 606 |
return input; |
| 607 |
} |
| 608 |
|
| 609 |
@Override |
| 610 |
public void dispose() |
| 611 |
{ |
| 612 |
if (diagnosticDecorator != null) |
| 613 |
{ |
| 614 |
diagnosticDecorator.dispose(); |
| 615 |
} |
| 616 |
clipboard.dispose(); |
| 617 |
super.dispose(); |
| 618 |
} |
| 619 |
|
| 620 |
/** |
| 621 |
* Refreshes only the labels of the property sheet viewer. |
| 622 |
* It does not dismiss the cell editor, if there is one. |
| 623 |
* |
| 624 |
* @since 2.12 |
| 625 |
*/ |
| 626 |
public void refreshLabels() |
| 627 |
{ |
| 628 |
try |
| 629 |
{ |
| 630 |
Field viewerField = PropertySheetPage.class.getDeclaredField("viewer"); |
| 631 |
viewerField.setAccessible(true); |
| 632 |
Viewer viewer = (Viewer)viewerField.get(this); |
| 633 |
viewer.refresh(); |
| 634 |
if (columnResizer != null) |
| 635 |
{ |
| 636 |
columnResizer.resizeColumns(); |
| 637 |
} |
| 638 |
return; |
| 639 |
} |
| 640 |
catch (Throwable throwable) |
| 641 |
{ |
| 642 |
// Ignore. |
| 643 |
} |
| 644 |
|
| 645 |
refresh(); |
| 646 |
} |
| 647 |
|
| 648 |
@Override |
| 649 |
public void refresh() |
| 650 |
{ |
| 651 |
Control control = getControl(); |
| 652 |
if (control == null) |
| 653 |
{ |
| 654 |
return; |
| 655 |
} |
| 656 |
|
| 657 |
// Check that there isn't currently a cell editor active. |
| 658 |
// If there is a focus control that isn't the control of the property sheet page... |
| 659 |
Control focusControl = control.getDisplay().getFocusControl(); |
| 660 |
if (focusControl != null && focusControl != control) |
| 661 |
{ |
| 662 |
// Check if that focus control is contained by the property sheet page's control. |
| 663 |
for (Control parent = focusControl.getParent(); parent != null; parent = parent.getParent()) |
| 664 |
{ |
| 665 |
if (parent == control) |
| 666 |
{ |
| 667 |
if (columnResizer != null) |
| 668 |
{ |
| 669 |
columnResizer.resizeColumns(); |
| 670 |
} |
| 671 |
|
| 672 |
// If it is, then don't refresh the property sheet page |
| 673 |
// because that will make the cell editor deactivate. |
| 674 |
return; |
| 675 |
} |
| 676 |
} |
| 677 |
} |
| 678 |
|
| 679 |
// If it's a CCombo and the list (Shell) is active, the above logic won't find it. |
| 680 |
if (setValueAction.entry != null && setValueAction.entry.editor != null && setValueAction.entry.editor.getControl() != null |
| 681 |
&& !setValueAction.entry.editor.getControl().isDisposed() && setValueAction.entry.editor.getControl().isFocusControl()) |
| 682 |
{ |
| 683 |
if (columnResizer != null) |
| 684 |
{ |
| 685 |
columnResizer.resizeColumns(); |
| 686 |
} |
| 687 |
return; |
| 688 |
} |
| 689 |
|
| 690 |
Tree tree = (Tree)control; |
| 691 |
try |
| 692 |
{ |
| 693 |
tree.setRedraw(false); |
| 694 |
int expectedModCount = rootEntry.modCount; |
| 695 |
super.refresh(); |
| 696 |
if (expectedModCount != rootEntry.modCount && autoExpandLevel != 0) |
| 697 |
{ |
| 698 |
expand(tree, tree.getItems(), autoExpandLevel); |
| 699 |
} |
| 700 |
|
| 701 |
if (columnResizer != null) |
| 702 |
{ |
| 703 |
columnResizer.resizeColumns(); |
| 704 |
} |
| 705 |
} |
| 706 |
finally |
| 707 |
{ |
| 708 |
tree.setRedraw(true); |
| 709 |
} |
| 710 |
} |
| 711 |
|
| 712 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
| 713 |
@Override |
| 714 |
public Object getAdapter(Class adapter) |
| 715 |
{ |
| 716 |
if (workbenchPart != null && adapter == IFindReplaceTarget.class) |
| 717 |
{ |
| 718 |
return workbenchPart.getAdapter(adapter); |
| 719 |
} |
| 720 |
else |
| 721 |
{ |
| 722 |
return super.getAdapter(adapter); |
| 723 |
} |
| 724 |
} |
| 725 |
|
| 726 |
/** |
| 727 |
* @since 2.14 |
| 728 |
*/ |
| 729 |
public static class ExtendedPropertySheetEntry extends PropertySheetEntry |
| 730 |
{ |
| 731 |
private int modCount; |
| 732 |
|
| 733 |
protected DiagnosticDecorator diagnosticDecorator; |
| 734 |
|
| 735 |
protected CellEditor editor; |
| 736 |
|
| 737 |
public ExtendedPropertySheetEntry(DiagnosticDecorator diagnosticDecorator) |
| 738 |
{ |
| 739 |
this.diagnosticDecorator = diagnosticDecorator; |
| 740 |
} |
| 741 |
|
| 742 |
@Override |
| 743 |
public IPropertyDescriptor getDescriptor() |
| 744 |
{ |
| 745 |
return super.getDescriptor(); |
| 746 |
} |
| 747 |
|
| 748 |
@Override |
| 749 |
protected PropertySheetEntry createChildEntry() |
| 750 |
{ |
| 751 |
++modCount; |
| 752 |
for (PropertySheetEntry parent = getParent(); parent instanceof ExtendedPropertySheetEntry; parent = ((ExtendedPropertySheetEntry)parent).getParent()) |
| 753 |
{ |
| 754 |
++((ExtendedPropertySheetEntry)parent).modCount; |
| 755 |
} |
| 756 |
|
| 757 |
return new ExtendedPropertySheetEntry(diagnosticDecorator); |
| 758 |
} |
| 759 |
|
| 760 |
public boolean isRestoreValueEnabled() |
| 761 |
{ |
| 762 |
PropertySheetEntry parent = getParent(); |
| 763 |
if (parent != null) |
| 764 |
{ |
| 765 |
Object[] objects = parent.getValues(); |
| 766 |
IPropertyDescriptor descriptor = getDescriptor(); |
| 767 |
Object id = descriptor.getId(); |
| 768 |
for (Object object : objects) |
| 769 |
{ |
| 770 |
IPropertySource source = getPropertySource(object); |
| 771 |
for (IPropertyDescriptor propertyDescriptor : source.getPropertyDescriptors()) |
| 772 |
{ |
| 773 |
if (id.equals(propertyDescriptor.getId())) |
| 774 |
{ |
| 775 |
if (source.isPropertySet(id) && (!(source instanceof IPropertySource2) || ((IPropertySource2)source).isPropertyResettable(id))) |
| 776 |
{ |
| 777 |
return true; |
| 778 |
} |
| 779 |
else |
| 780 |
{ |
| 781 |
break; |
| 782 |
} |
| 783 |
} |
| 784 |
} |
| 785 |
} |
| 786 |
} |
| 787 |
return false; |
| 788 |
} |
| 789 |
|
| 790 |
public boolean isSetValueEnabled() |
| 791 |
{ |
| 792 |
PropertySheetEntry parent = getParent(); |
| 793 |
if (parent != null) |
| 794 |
{ |
| 795 |
Object[] objects = parent.getValues(); |
| 796 |
IPropertyDescriptor descriptor = getDescriptor(); |
| 797 |
Object id = descriptor.getId(); |
| 798 |
for (Object object : objects) |
| 799 |
{ |
| 800 |
IPropertySource source = getPropertySource(object); |
| 801 |
for (IPropertyDescriptor propertyDescriptor : source.getPropertyDescriptors()) |
| 802 |
{ |
| 803 |
if (id.equals(propertyDescriptor.getId())) |
| 804 |
{ |
| 805 |
if (!source.isPropertySet(id) && source instanceof IUnsettablePropertySource && ((IUnsettablePropertySource)source).isPropertyUnsettable(id)) |
| 806 |
{ |
| 807 |
return true; |
| 808 |
} |
| 809 |
else |
| 810 |
{ |
| 811 |
break; |
| 812 |
} |
| 813 |
} |
| 814 |
} |
| 815 |
} |
| 816 |
} |
| 817 |
return false; |
| 818 |
} |
| 819 |
|
| 820 |
public void setPropertyValue() |
| 821 |
{ |
| 822 |
PropertySheetEntry parent = getParent(); |
| 823 |
if (parent != null) |
| 824 |
{ |
| 825 |
boolean change = false; |
| 826 |
Object[] objects = parent.getValues(); |
| 827 |
IPropertyDescriptor descriptor = getDescriptor(); |
| 828 |
Object id = descriptor.getId(); |
| 829 |
for (int i = 0; i < objects.length; ++i) |
| 830 |
{ |
| 831 |
Object object = objects[i]; |
| 832 |
IPropertySource source = getPropertySource(object); |
| 833 |
Object value = getEditValue(i); |
| 834 |
source.setPropertyValue(id, value); |
| 835 |
change = true; |
| 836 |
} |
| 837 |
if (change) |
| 838 |
{ |
| 839 |
refreshFromRoot(); |
| 840 |
} |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
@Override |
| 845 |
public Image getImage() |
| 846 |
{ |
| 847 |
Image image = super.getImage(); |
| 848 |
if (image == null) |
| 849 |
{ |
| 850 |
image = ExtendedImageRegistry.INSTANCE.getImage(ItemPropertyDescriptor.GENERIC_VALUE_IMAGE); |
| 851 |
} |
| 852 |
Diagnostic featureDiagnostic = findDiagnostic(); |
| 853 |
return featureDiagnostic != null ? diagnosticDecorator.decorate(image, featureDiagnostic) : image; |
| 854 |
} |
| 855 |
|
| 856 |
protected Diagnostic findDiagnostic() |
| 857 |
{ |
| 858 |
if (diagnosticDecorator != null) |
| 859 |
{ |
| 860 |
IPropertyDescriptor descriptor = getDescriptor(); |
| 861 |
if (descriptor instanceof PropertyDescriptor) |
| 862 |
{ |
| 863 |
Object feature = ((PropertyDescriptor)descriptor).getFeature(); |
| 864 |
Map<Object, ? extends Diagnostic> decorations = diagnosticDecorator.getDecorations(); |
| 865 |
if (!decorations.isEmpty() && feature != null) |
| 866 |
{ |
| 867 |
for (Diagnostic diagnostic : decorations.values()) |
| 868 |
{ |
| 869 |
Diagnostic featureDiagnostic = find(diagnostic, feature); |
| 870 |
if (featureDiagnostic != null) |
| 871 |
{ |
| 872 |
return featureDiagnostic; |
| 873 |
} |
| 874 |
} |
| 875 |
} |
| 876 |
} |
| 877 |
} |
| 878 |
return null; |
| 879 |
} |
| 880 |
|
| 881 |
protected Diagnostic find(Diagnostic diagnostic, Object feature) |
| 882 |
{ |
| 883 |
// Gather them all... |
| 884 |
// |
| 885 |
if (diagnostic.getData().contains(feature)) |
| 886 |
{ |
| 887 |
return diagnostic; |
| 888 |
} |
| 889 |
for (Diagnostic child : diagnostic.getChildren()) |
| 890 |
{ |
| 891 |
Diagnostic result = find(child, feature); |
| 892 |
if (result != null) |
| 893 |
{ |
| 894 |
return result; |
| 895 |
} |
| 896 |
} |
| 897 |
return null; |
| 898 |
} |
| 899 |
|
| 900 |
@Override |
| 901 |
public String getDescription() |
| 902 |
{ |
| 903 |
String description = super.getDescription(); |
| 904 |
Diagnostic featureDiagnostic = findDiagnostic(); |
| 905 |
if (featureDiagnostic != null) |
| 906 |
{ |
| 907 |
List<Diagnostic> children = featureDiagnostic.getChildren(); |
| 908 |
if (!children.isEmpty()) |
| 909 |
{ |
| 910 |
return description + " - " + DiagnosticDecorator.strip(children.get(0).getMessage()); |
| 911 |
} |
| 912 |
else |
| 913 |
{ |
| 914 |
return description + " - " + DiagnosticDecorator.strip(featureDiagnostic.getMessage()); |
| 915 |
} |
| 916 |
} |
| 917 |
else |
| 918 |
{ |
| 919 |
return description; |
| 920 |
} |
| 921 |
} |
| 922 |
|
| 923 |
/** |
| 924 |
* This override guards the creation so it's only done if the current selection in the tree is the tree item for this property sheet entry. |
| 925 |
* The framework listens for and handles the mouse down event using the point of that event to determine the tree item, |
| 926 |
* but if the tree scrolls during an expansion, that point may not be the tree item that was actually expanded but instead a tree item that's just been revealed. |
| 927 |
* We really only want to create a cell editor for the actual selected tree item. |
| 928 |
*/ |
| 929 |
@Override |
| 930 |
public CellEditor getEditor(Composite parent) |
| 931 |
{ |
| 932 |
editor = null; |
| 933 |
Tree tree = (Tree)parent; |
| 934 |
TreeItem[] selection = tree.getSelection(); |
| 935 |
for (TreeItem treeItem : selection) |
| 936 |
{ |
| 937 |
if (treeItem.getData() == this) |
| 938 |
{ |
| 939 |
editor = super.getEditor(parent); |
| 940 |
break; |
| 941 |
} |
| 942 |
} |
| 943 |
return editor; |
| 944 |
} |
| 945 |
|
| 946 |
@Override |
| 947 |
public void setValues(Object[] objects) |
| 948 |
{ |
| 949 |
editor = null; |
| 950 |
super.setValues(objects); |
| 951 |
} |
| 952 |
|
| 953 |
@Override |
| 954 |
public void applyEditorValue() |
| 955 |
{ |
| 956 |
if (editor != null && editor.isDirty()) |
| 957 |
{ |
| 958 |
super.applyEditorValue(); |
| 959 |
} |
| 960 |
} |
| 961 |
} |
| 962 |
|
| 963 |
/** |
| 964 |
* An extension of the standard <code>{@link IPropertySource2}</code> interface. |
| 965 |
* <p> |
| 966 |
* This interface provides an extended API to allow a property to indicate whether or not it supports the concept of being in the <em>unset</em> state, |
| 967 |
* i.e., to indicate that the value state of the property includes one additional state, the unset state, that is distinct from the set of values the property can have. |
| 968 |
* For a property with {@link IPropertyDescriptor#getId() ID} <code>x</code> that returns <code>true</code> for <code>{@link #isPropertyUnsettable(Object) isPropertyUnsettable}(x)</code> |
| 969 |
* and that returns <code>false</code> for <code>{@link #isPropertySet(Object) isPropertySet}(x)</code>, |
| 970 |
* calling <code>{@link #setPropertyValue(Object, Object) setPropertyValue}(x, {@link #getEditableValue getEditableValue}(x)</code> |
| 971 |
* will result in <code>isPropertySet(true)</code> becoming <code>true</code>, even though in both states the property has the same value. |
| 972 |
* Such a property <code>x</code> will always return <code>false</code> for <code>isPropertySet(x)</code> after a call to <code>{@link #resetPropertyValue(Object) resetPropertyValue}(x)</code>. |
| 973 |
* A property <code>x</code> that is read-only will always return <code>false</code> for <code>isPropertyUnsettable(x)</code>. |
| 974 |
* </p> |
| 975 |
* |
| 976 |
* @since 2.14 |
| 977 |
*/ |
| 978 |
public interface IUnsettablePropertySource extends IPropertySource2 |
| 979 |
{ |
| 980 |
/** |
| 981 |
* Returns whether the property supports the concept of being in the <em>{@link IUnsettablePropertySource unset}</em> state. |
| 982 |
* @param id the ID of the property. |
| 983 |
* @return whether the property supports the concept of being in the unset. |
| 984 |
* @see IUnsettablePropertySource |
| 985 |
*/ |
| 986 |
boolean isPropertyUnsettable(Object id); |
| 987 |
} |
| 988 |
|
| 989 |
/** |
| 990 |
* @since 2.14 |
| 991 |
*/ |
| 992 |
protected static class CopyValuePropertyAction extends Action |
| 993 |
{ |
| 994 |
private Clipboard clipboard; |
| 995 |
|
| 996 |
private IStructuredSelection selection; |
| 997 |
|
| 998 |
public CopyValuePropertyAction(Clipboard clipboard) |
| 999 |
{ |
| 1000 |
super(EMFEditUIPlugin.INSTANCE.getString("_UI_CopyValue_menu_item")); |
| 1001 |
this.clipboard = clipboard; |
| 1002 |
setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); |
| 1003 |
} |
| 1004 |
|
| 1005 |
@Override |
| 1006 |
public void run() |
| 1007 |
{ |
| 1008 |
if (selection != null && !selection.isEmpty()) |
| 1009 |
{ |
| 1010 |
IPropertySheetEntry entry = (IPropertySheetEntry)selection.getFirstElement(); |
| 1011 |
String value = entry.getValueAsString(); |
| 1012 |
if (value != null) |
| 1013 |
{ |
| 1014 |
setClipboard(value); |
| 1015 |
} |
| 1016 |
} |
| 1017 |
} |
| 1018 |
|
| 1019 |
public void selectionChanged(ISelection selection) |
| 1020 |
{ |
| 1021 |
if (selection instanceof IStructuredSelection) |
| 1022 |
{ |
| 1023 |
this.selection = (IStructuredSelection)selection; |
| 1024 |
setEnabled(!selection.isEmpty()); |
| 1025 |
} |
| 1026 |
else |
| 1027 |
{ |
| 1028 |
this.selection = null; |
| 1029 |
setEnabled(false); |
| 1030 |
} |
| 1031 |
} |
| 1032 |
|
| 1033 |
private void setClipboard(String text) |
| 1034 |
{ |
| 1035 |
try |
| 1036 |
{ |
| 1037 |
Object[] data = new Object []{ text }; |
| 1038 |
Transfer[] transferTypes = new Transfer []{ TextTransfer.getInstance() }; |
| 1039 |
clipboard.setContents(data, transferTypes); |
| 1040 |
} |
| 1041 |
catch (SWTError exception) |
| 1042 |
{ |
| 1043 |
EMFEditUIPlugin.INSTANCE.log(exception); |
| 1044 |
} |
| 1045 |
} |
| 1046 |
} |
| 1047 |
} |