|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008 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 v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.pde.internal.ui.editor.ctxhelp; |
| 12 |
|
| 13 |
import java.util.*; |
| 14 |
import java.util.List; |
| 15 |
import org.eclipse.core.resources.IFile; |
| 16 |
import org.eclipse.core.resources.IResource; |
| 17 |
import org.eclipse.core.runtime.IPath; |
| 18 |
import org.eclipse.jface.action.*; |
| 19 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 20 |
import org.eclipse.jface.viewers.*; |
| 21 |
import org.eclipse.pde.core.IModelChangedEvent; |
| 22 |
import org.eclipse.pde.internal.core.ictxhelp.ICtxHelpConstants; |
| 23 |
import org.eclipse.pde.internal.core.text.IDocumentElementNode; |
| 24 |
import org.eclipse.pde.internal.core.text.ctxhelp.*; |
| 25 |
import org.eclipse.pde.internal.ui.PDEPlugin; |
| 26 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
| 27 |
import org.eclipse.pde.internal.ui.editor.PDEFormPage; |
| 28 |
import org.eclipse.pde.internal.ui.editor.TreeSection; |
| 29 |
import org.eclipse.pde.internal.ui.editor.actions.CollapseAction; |
| 30 |
import org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpAbstractAddAction; |
| 31 |
import org.eclipse.pde.internal.ui.editor.ctxhelp.details.CtxHelpRemoveAction; |
| 32 |
import org.eclipse.pde.internal.ui.editor.plugin.FormFilteredTree; |
| 33 |
import org.eclipse.pde.internal.ui.editor.toc.HelpEditorUtil; |
| 34 |
import org.eclipse.pde.internal.ui.parts.TreePart; |
| 35 |
import org.eclipse.pde.internal.ui.util.PDELabelUtility; |
| 36 |
import org.eclipse.swt.SWT; |
| 37 |
import org.eclipse.swt.dnd.DND; |
| 38 |
import org.eclipse.swt.events.DisposeEvent; |
| 39 |
import org.eclipse.swt.events.DisposeListener; |
| 40 |
import org.eclipse.swt.graphics.Cursor; |
| 41 |
import org.eclipse.swt.widgets.*; |
| 42 |
import org.eclipse.ui.PartInitException; |
| 43 |
import org.eclipse.ui.PlatformUI; |
| 44 |
import org.eclipse.ui.actions.ActionFactory; |
| 45 |
import org.eclipse.ui.actions.ContributionItemFactory; |
| 46 |
import org.eclipse.ui.dialogs.PatternFilter; |
| 47 |
import org.eclipse.ui.forms.widgets.FormToolkit; |
| 48 |
import org.eclipse.ui.forms.widgets.Section; |
| 49 |
import org.eclipse.ui.ide.IDE; |
| 50 |
import org.eclipse.ui.keys.IBindingService; |
| 51 |
|
| 52 |
/** |
| 53 |
* Tree section for the context help editor. Displays the structure |
| 54 |
* of the xml file and adds actions allowing manipulation of the structure. |
| 55 |
* @since 3.4 |
| 56 |
* @see CtxHelpEditor |
| 57 |
*/ |
| 58 |
public class CtxHelpTreeSection extends TreeSection { |
| 59 |
private CtxHelpModel fModel; |
| 60 |
private TreeViewer fTree; |
| 61 |
private FormFilteredTree fFilteredTree; |
| 62 |
|
| 63 |
/* The indices for each button attached to the Tree Viewer. |
| 64 |
* This type of UI form does not permit direct access to each particular |
| 65 |
* button. However, using these indices, one can perform any typical SWT |
| 66 |
* operation on any button. |
| 67 |
*/ |
| 68 |
private static final int F_BUTTON_ADD_CONTEXT = 0; |
| 69 |
private static final int F_BUTTON_ADD_TOPIC = 2; |
| 70 |
private static final int F_BUTTON_ADD_COMMAND = 3; |
| 71 |
private static final int F_BUTTON_REMOVE = 5; |
| 72 |
private static final int F_BUTTON_UP = 6; |
| 73 |
private static final int F_BUTTON_DOWN = 7; |
| 74 |
|
| 75 |
// When one of the move buttons is pressed, a flag is used to determine the direction |
| 76 |
private static final int F_UP_FLAG = -1; |
| 77 |
private static final int F_DOWN_FLAG = 1; |
| 78 |
|
| 79 |
// The actions that will add each type of object |
| 80 |
private CtxHelpAbstractAddAction fAddContextAction; |
| 81 |
private CtxHelpAbstractAddAction fAddTopicAction; |
| 82 |
private CtxHelpAbstractAddAction fAddCommandAction; |
| 83 |
|
| 84 |
// The object removal action |
| 85 |
private CtxHelpRemoveAction fRemoveObjectAction; |
| 86 |
|
| 87 |
// The action for opening a link from the context menu |
| 88 |
private OpenLinkAction fOpenLinkAction; |
| 89 |
|
| 90 |
// Used to temporarily store the target of a drop operation |
| 91 |
// so that it does not have be be recalculated |
| 92 |
private CtxHelpObject fDropTargetParent; |
| 93 |
private CtxHelpObject fDropTargetSibling; |
| 94 |
|
| 95 |
/** If items are dragged and dropped within this tree, then |
| 96 |
* this flag inhibits reselection on the removal (drag) action, |
| 97 |
* thus ensuring that the selected objects are the ones that were |
| 98 |
* dropped. |
| 99 |
*/ |
| 100 |
private boolean fDragFromHere; |
| 101 |
|
| 102 |
/** |
| 103 |
* Action that allows a linked file to be opened in the editor |
| 104 |
* @since 3.4 |
| 105 |
*/ |
| 106 |
class OpenLinkAction extends Action { |
| 107 |
private CtxHelpTopic fOpenTarget; |
| 108 |
|
| 109 |
public OpenLinkAction() { |
| 110 |
super(PDEUIMessages.Actions_open_label); |
| 111 |
} |
| 112 |
|
| 113 |
public void setTarget(CtxHelpTopic target) { |
| 114 |
fOpenTarget = target; |
| 115 |
} |
| 116 |
|
| 117 |
public void run() { |
| 118 |
if (fOpenTarget != null) { |
| 119 |
open(fOpenTarget); |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
public CtxHelpTreeSection(PDEFormPage formPage, Composite parent) { |
| 125 |
super(formPage, parent, Section.DESCRIPTION, new String[] {PDEUIMessages.CtxHelpTreeSection_addContext, null, PDEUIMessages.CtxHelpTreeSection_addTopic, PDEUIMessages.CtxHelpTreeSection_addCommand, null, PDEUIMessages.TocPage_remove, PDEUIMessages.TocPage_up, PDEUIMessages.TocPage_down}); |
| 126 |
} |
| 127 |
|
| 128 |
/* (non-Javadoc) |
| 129 |
* @see org.eclipse.pde.internal.ui.editor.PDESection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit) |
| 130 |
*/ |
| 131 |
protected void createClient(Section section, FormToolkit toolkit) { |
| 132 |
fModel = (CtxHelpModel) getPage().getModel(); |
| 133 |
|
| 134 |
Composite container = createClientContainer(section, 2, toolkit); |
| 135 |
createTree(container, toolkit); |
| 136 |
toolkit.paintBordersFor(container); |
| 137 |
|
| 138 |
section.setText(PDEUIMessages.CtxHelpTreeSection_contextHelp); |
| 139 |
section.setDescription(PDEUIMessages.CtxHelpTreeSection_editContextHelpStructure); |
| 140 |
section.setClient(container); |
| 141 |
|
| 142 |
createCommands(); |
| 143 |
|
| 144 |
initializeTreeViewer(); |
| 145 |
createSectionToolbar(section, toolkit); |
| 146 |
|
| 147 |
// Create the adapted listener for the filter entry field |
| 148 |
fFilteredTree.createUIListenerEntryFilter(this); |
| 149 |
} |
| 150 |
|
| 151 |
/** |
| 152 |
* Creates the commands used in this section. |
| 153 |
*/ |
| 154 |
private void createCommands() { |
| 155 |
fAddContextAction = new CtxHelpAbstractAddAction() { |
| 156 |
public void run() { |
| 157 |
if (fParentObject != null) { |
| 158 |
CtxHelpContext context = fParentObject.getModel().getFactory().createContext(); |
| 159 |
String id = PDELabelUtility.generateName(getChildNames(), PDEUIMessages.CtxHelpTreeSection_defaultContextName); |
| 160 |
context.setID(id); |
| 161 |
addChild(context); |
| 162 |
} |
| 163 |
} |
| 164 |
}; |
| 165 |
fAddContextAction.setText(PDEUIMessages.CtxHelpTreeSection_newContext); |
| 166 |
fAddTopicAction = new CtxHelpAbstractAddAction() { |
| 167 |
public void run() { |
| 168 |
if (fParentObject != null) { |
| 169 |
CtxHelpTopic topic = fParentObject.getModel().getFactory().createTopic(); |
| 170 |
String label = PDELabelUtility.generateName(getChildNames(), PDEUIMessages.CtxHelpTreeSection_defaultTopicName); |
| 171 |
topic.setLabel(label); |
| 172 |
addChild(topic); |
| 173 |
} |
| 174 |
} |
| 175 |
}; |
| 176 |
fAddTopicAction.setText(PDEUIMessages.CtxHelpTreeSection_newTopic); |
| 177 |
fAddCommandAction = new CtxHelpAbstractAddAction() { |
| 178 |
public void run() { |
| 179 |
if (fParentObject != null) { |
| 180 |
CtxHelpCommand command = fParentObject.getModel().getFactory().createCommand(); |
| 181 |
String label = PDELabelUtility.generateName(getChildNames(), PDEUIMessages.CtxHelpTreeSection_defaultCommandName); |
| 182 |
command.setLabel(label); |
| 183 |
addChild(command); |
| 184 |
} |
| 185 |
} |
| 186 |
}; |
| 187 |
fAddCommandAction.setText(PDEUIMessages.CtxHelpTreeSection_newCommand); |
| 188 |
|
| 189 |
fRemoveObjectAction = new CtxHelpRemoveAction(); |
| 190 |
fOpenLinkAction = new OpenLinkAction(); |
| 191 |
} |
| 192 |
|
| 193 |
/** |
| 194 |
* Adds a link (with hand cursor) for tree 'Collapse All' action, |
| 195 |
* which collapses the tree down to the second level |
| 196 |
* |
| 197 |
* @param section The section that the toolbar will belong to |
| 198 |
* @param toolkit The toolkit that will be used to make the toolbar |
| 199 |
*/ |
| 200 |
private void createSectionToolbar(Section section, FormToolkit toolkit) { |
| 201 |
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); |
| 202 |
ToolBar toolbar = toolBarManager.createControl(section); |
| 203 |
|
| 204 |
final Cursor handCursor = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND); |
| 205 |
toolbar.setCursor(handCursor); |
| 206 |
// Cursor needs to be explicitly disposed |
| 207 |
toolbar.addDisposeListener(new DisposeListener() { |
| 208 |
public void widgetDisposed(DisposeEvent e) { |
| 209 |
if ((handCursor != null) && (handCursor.isDisposed() == false)) { |
| 210 |
handCursor.dispose(); |
| 211 |
} |
| 212 |
} |
| 213 |
}); |
| 214 |
|
| 215 |
// Add collapse action to the tool bar |
| 216 |
toolBarManager.add(new CollapseAction(fTree, PDEUIMessages.ExtensionsPage_collapseAll, 1, fModel.getCtxHelpRoot())); |
| 217 |
toolBarManager.update(true); |
| 218 |
section.setTextClient(toolbar); |
| 219 |
} |
| 220 |
|
| 221 |
/** |
| 222 |
* Create the tree widget that will contain the structure |
| 223 |
* |
| 224 |
* @param container The container of the tree widget |
| 225 |
* @param toolkit The toolkit used to create the tree |
| 226 |
*/ |
| 227 |
private void createTree(Composite container, FormToolkit toolkit) { |
| 228 |
TreePart treePart = getTreePart(); |
| 229 |
createViewerPartControl(container, SWT.MULTI, 2, toolkit); |
| 230 |
|
| 231 |
fTree = treePart.getTreeViewer(); |
| 232 |
fTree.setContentProvider(new CtxHelpContentProvider()); |
| 233 |
fTree.setLabelProvider(PDEPlugin.getDefault().getLabelProvider()); |
| 234 |
|
| 235 |
PDEPlugin.getDefault().getLabelProvider().connect(this); |
| 236 |
|
| 237 |
// Create listener for the outline view 'link with editor' toggle button |
| 238 |
fTree.addPostSelectionChangedListener(getPage().getPDEEditor().new PDEFormEditorChangeListener()); |
| 239 |
} |
| 240 |
|
| 241 |
/* (non-Javadoc) |
| 242 |
* @see org.eclipse.pde.internal.ui.editor.TreeSection#createTreeViewer(org.eclipse.swt.widgets.Composite, int) |
| 243 |
*/ |
| 244 |
protected TreeViewer createTreeViewer(Composite parent, int style) { |
| 245 |
fFilteredTree = new FormFilteredTree(parent, style, new PatternFilter()); |
| 246 |
parent.setData("filtered", Boolean.TRUE); //$NON-NLS-1$ |
| 247 |
return fFilteredTree.getViewer(); |
| 248 |
} |
| 249 |
|
| 250 |
/** |
| 251 |
* Initialize the tree viewer widget and its buttons. |
| 252 |
*/ |
| 253 |
private void initializeTreeViewer() { |
| 254 |
if (fModel == null) { |
| 255 |
return; |
| 256 |
} |
| 257 |
|
| 258 |
CtxHelpRoot root = fModel.getCtxHelpRoot(); |
| 259 |
fTree.setInput(root); |
| 260 |
|
| 261 |
// Buttons must be disabled if file is not editable |
| 262 |
getTreePart().setButtonEnabled(F_BUTTON_ADD_CONTEXT, isEditable()); |
| 263 |
getTreePart().setButtonEnabled(F_BUTTON_ADD_COMMAND, isEditable()); |
| 264 |
getTreePart().setButtonEnabled(F_BUTTON_ADD_TOPIC, isEditable()); |
| 265 |
|
| 266 |
getTreePart().setButtonEnabled(F_BUTTON_REMOVE, false); |
| 267 |
getTreePart().setButtonEnabled(F_BUTTON_UP, false); |
| 268 |
getTreePart().setButtonEnabled(F_BUTTON_DOWN, false); |
| 269 |
} |
| 270 |
|
| 271 |
/* (non-Javadoc) |
| 272 |
* @see org.eclipse.ui.forms.AbstractFormPart#setFormInput(java.lang.Object) |
| 273 |
*/ |
| 274 |
public boolean setFormInput(Object object) { |
| 275 |
// This method allows the outline view to select items in the tree |
| 276 |
// (Invoked by org.eclipse.ui.forms.editor.IFormPage.selectReveal(Object object)) |
| 277 |
if (object instanceof CtxHelpObject) { |
| 278 |
fTree.setSelection(new StructuredSelection(object), true); |
| 279 |
|
| 280 |
// Verify that something was actually selected |
| 281 |
ISelection selection = fTree.getSelection(); |
| 282 |
if (selection != null && !selection.isEmpty()) { |
| 283 |
return true; |
| 284 |
} |
| 285 |
} |
| 286 |
return false; |
| 287 |
} |
| 288 |
|
| 289 |
/** |
| 290 |
* @return the selection of the tree |
| 291 |
*/ |
| 292 |
public ISelection getSelection() { |
| 293 |
return fTree.getSelection(); |
| 294 |
} |
| 295 |
|
| 296 |
/** |
| 297 |
* @param selection the new selection for the tree section |
| 298 |
*/ |
| 299 |
public void setSelection(ISelection selection) { |
| 300 |
fTree.setSelection(selection); |
| 301 |
} |
| 302 |
|
| 303 |
/** |
| 304 |
* Fire a selection change event and refresh the viewer's selection |
| 305 |
*/ |
| 306 |
public void fireSelection() { |
| 307 |
fTree.setSelection(fTree.getSelection()); |
| 308 |
} |
| 309 |
|
| 310 |
/* (non-Javadoc) |
| 311 |
* @see org.eclipse.pde.internal.ui.editor.TreeSection#selectionChanged(org.eclipse.jface.viewers.IStructuredSelection) |
| 312 |
*/ |
| 313 |
protected void selectionChanged(IStructuredSelection selection) { |
| 314 |
getPage().getPDEEditor().setSelection(selection); |
| 315 |
updateButtons(); |
| 316 |
} |
| 317 |
|
| 318 |
/** |
| 319 |
* Update the buttons in the section based on the current selection |
| 320 |
*/ |
| 321 |
public void updateButtons() { |
| 322 |
if (!fModel.isEditable()) { |
| 323 |
return; |
| 324 |
} |
| 325 |
|
| 326 |
IStructuredSelection selection = (IStructuredSelection) fTree.getSelection(); |
| 327 |
CtxHelpObject firstSelectedObject = (CtxHelpObject) selection.getFirstElement(); |
| 328 |
|
| 329 |
// Add Context |
| 330 |
getTreePart().setButtonEnabled(F_BUTTON_ADD_CONTEXT, true); |
| 331 |
|
| 332 |
// Add Topic |
| 333 |
boolean enableAdd = false; |
| 334 |
if (firstSelectedObject != null) { |
| 335 |
if (firstSelectedObject.canAddSibling(ICtxHelpConstants.TYPE_TOPIC)) { |
| 336 |
enableAdd = true; |
| 337 |
} else if (firstSelectedObject.canAddChild(ICtxHelpConstants.TYPE_TOPIC)) { |
| 338 |
enableAdd = true; |
| 339 |
} |
| 340 |
} |
| 341 |
getTreePart().setButtonEnabled(F_BUTTON_ADD_TOPIC, enableAdd); |
| 342 |
|
| 343 |
// Add Command |
| 344 |
enableAdd = false; |
| 345 |
if (firstSelectedObject != null) { |
| 346 |
if (firstSelectedObject.canAddSibling(ICtxHelpConstants.TYPE_COMMAND)) { |
| 347 |
enableAdd = true; |
| 348 |
} else if (firstSelectedObject.canAddChild(ICtxHelpConstants.TYPE_COMMAND)) { |
| 349 |
enableAdd = true; |
| 350 |
} |
| 351 |
} |
| 352 |
getTreePart().setButtonEnabled(F_BUTTON_ADD_COMMAND, enableAdd); |
| 353 |
|
| 354 |
// Remove button |
| 355 |
getTreePart().setButtonEnabled(F_BUTTON_REMOVE, getRemovableObjectFromSelection(selection).size() > 0); |
| 356 |
|
| 357 |
// Up and Down buttons |
| 358 |
boolean canMoveUp = true; |
| 359 |
boolean canMoveDown = true; |
| 360 |
if (firstSelectedObject == null || firstSelectedObject.getType() == ICtxHelpConstants.TYPE_ROOT || firstSelectedObject.getType() == ICtxHelpConstants.TYPE_DESCRIPTION || selection.size() > 1) { |
| 361 |
canMoveUp = false; |
| 362 |
canMoveDown = false; |
| 363 |
} else { |
| 364 |
CtxHelpObject parent = firstSelectedObject.getParent(); |
| 365 |
if (parent != null) { |
| 366 |
if (parent.isFirstChildNode(firstSelectedObject, firstSelectedObject.getClass())) { |
| 367 |
canMoveUp = false; |
| 368 |
} |
| 369 |
if (parent.isLastChildNode(firstSelectedObject, firstSelectedObject.getClass())) { |
| 370 |
canMoveDown = false; |
| 371 |
} |
| 372 |
} |
| 373 |
} |
| 374 |
getTreePart().setButtonEnabled(F_BUTTON_UP, canMoveUp); |
| 375 |
getTreePart().setButtonEnabled(F_BUTTON_DOWN, canMoveDown); |
| 376 |
} |
| 377 |
|
| 378 |
/* (non-Javadoc) |
| 379 |
* @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#fillContextMenu(org.eclipse.jface.action.IMenuManager) |
| 380 |
*/ |
| 381 |
protected void fillContextMenu(IMenuManager manager) { |
| 382 |
IStructuredSelection selection = (IStructuredSelection) fTree.getSelection(); |
| 383 |
Object object = selection.getFirstElement(); |
| 384 |
// Has to be null or a CtxHelpObject object |
| 385 |
CtxHelpObject firstSelectedObject = (CtxHelpObject) object; |
| 386 |
|
| 387 |
// Populate the "New" sub-menu |
| 388 |
if (firstSelectedObject != null) { |
| 389 |
MenuManager submenu = new MenuManager(PDEUIMessages.Menus_new_label); |
| 390 |
boolean addMenu = false; |
| 391 |
if (updateAddContextActionWithSelection(firstSelectedObject)) { |
| 392 |
submenu.add(fAddContextAction); |
| 393 |
addMenu = true; |
| 394 |
} |
| 395 |
if (updateAddTopicActionWithSelection(firstSelectedObject)) { |
| 396 |
submenu.add(fAddTopicAction); |
| 397 |
addMenu = true; |
| 398 |
} |
| 399 |
if (updateAddCommandActionWithSelection(firstSelectedObject)) { |
| 400 |
submenu.add(fAddCommandAction); |
| 401 |
addMenu = true; |
| 402 |
} |
| 403 |
if (addMenu) { |
| 404 |
manager.add(submenu); |
| 405 |
manager.add(new Separator()); |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
// Add the open link and show in actions |
| 410 |
if (firstSelectedObject instanceof CtxHelpTopic && ((CtxHelpTopic) firstSelectedObject).getLocation() != null) { |
| 411 |
fOpenLinkAction.setTarget((CtxHelpTopic) firstSelectedObject); |
| 412 |
manager.add(fOpenLinkAction); |
| 413 |
fillContextMenuShowInAction(manager); |
| 414 |
manager.add(new Separator()); |
| 415 |
} |
| 416 |
|
| 417 |
// Add clipboard actions |
| 418 |
getPage().getPDEEditor().getContributor().contextMenuAboutToShow(manager); |
| 419 |
manager.add(new Separator()); |
| 420 |
|
| 421 |
// Add remove action |
| 422 |
if (updateRemoveActionWithSelection(selection)) { |
| 423 |
manager.add(fRemoveObjectAction); |
| 424 |
manager.add(new Separator()); |
| 425 |
} |
| 426 |
|
| 427 |
} |
| 428 |
|
| 429 |
/** |
| 430 |
* Creates and a new submenu in the given menu manager and adds actions to |
| 431 |
* allow a linked file to be opened in various views. |
| 432 |
* @param manager menu manager to add the submenu to |
| 433 |
*/ |
| 434 |
private void fillContextMenuShowInAction(IMenuManager manager) { |
| 435 |
String showInLabel = PDEUIMessages.PluginsView_showIn; |
| 436 |
|
| 437 |
// Add a label for the keybinding for Show In action, if one exists |
| 438 |
IBindingService bindingService = (IBindingService) PlatformUI.getWorkbench().getAdapter(IBindingService.class); |
| 439 |
if (bindingService != null) { |
| 440 |
String keyBinding = bindingService.getBestActiveBindingFormattedFor("org.eclipse.ui.navigate.showInQuickMenu"); //$NON-NLS-1$ |
| 441 |
if (keyBinding != null) { |
| 442 |
showInLabel += '\t' + keyBinding; |
| 443 |
} |
| 444 |
} |
| 445 |
|
| 446 |
IMenuManager showInMenu = new MenuManager(showInLabel); |
| 447 |
showInMenu.add(ContributionItemFactory.VIEWS_SHOW_IN.create(getPage().getSite().getWorkbenchWindow())); |
| 448 |
|
| 449 |
manager.add(showInMenu); |
| 450 |
} |
| 451 |
|
| 452 |
/** |
| 453 |
* Updates the add context action if the action should be available for the selection. |
| 454 |
* Updates enablement, parent object and target object. Returns true if the action |
| 455 |
* should be available to the selection. |
| 456 |
* @param selectedObject selected object |
| 457 |
* @return true if the action should be available for the current selection, false otherwise |
| 458 |
*/ |
| 459 |
private boolean updateAddContextActionWithSelection(CtxHelpObject selectedObject) { |
| 460 |
if (selectedObject != null && selectedObject.canAddSibling(ICtxHelpConstants.TYPE_CONTEXT)) { |
| 461 |
fAddContextAction.setParentObject(selectedObject.getParent()); |
| 462 |
fAddContextAction.setTargetObject(selectedObject); |
| 463 |
fAddContextAction.setEnabled(fModel.isEditable()); |
| 464 |
return true; |
| 465 |
} else if (selectedObject != null && selectedObject.canAddChild(ICtxHelpConstants.TYPE_CONTEXT)) { |
| 466 |
fAddContextAction.setParentObject(selectedObject); |
| 467 |
fAddContextAction.setTargetObject(null); |
| 468 |
fAddContextAction.setEnabled(fModel.isEditable()); |
| 469 |
return true; |
| 470 |
} else if (fModel.getCtxHelpRoot().canAddChild(ICtxHelpConstants.TYPE_CONTEXT)) { |
| 471 |
fAddContextAction.setParentObject(fModel.getCtxHelpRoot()); |
| 472 |
fAddContextAction.setTargetObject(null); |
| 473 |
fAddContextAction.setEnabled(fModel.isEditable()); |
| 474 |
return true; |
| 475 |
} |
| 476 |
return false; |
| 477 |
} |
| 478 |
|
| 479 |
/** |
| 480 |
* Updates the add topic action if the action should be available for the selection. |
| 481 |
* Updates enablement, parent object and target object. Returns true if the action |
| 482 |
* should be available to the selection. |
| 483 |
* @param selectedObject selected object |
| 484 |
* @return true if the action should be available for the current selection, false otherwise |
| 485 |
*/ |
| 486 |
private boolean updateAddTopicActionWithSelection(CtxHelpObject selectedObject) { |
| 487 |
if (selectedObject != null) { |
| 488 |
if (selectedObject.canAddSibling(ICtxHelpConstants.TYPE_TOPIC)) { |
| 489 |
fAddTopicAction.setParentObject(selectedObject.getParent()); |
| 490 |
fAddTopicAction.setTargetObject(selectedObject); |
| 491 |
fAddTopicAction.setEnabled(fModel.isEditable()); |
| 492 |
return true; |
| 493 |
} else if (selectedObject.canAddChild(ICtxHelpConstants.TYPE_TOPIC)) { |
| 494 |
fAddTopicAction.setParentObject(selectedObject); |
| 495 |
fAddTopicAction.setTargetObject(null); |
| 496 |
fAddTopicAction.setEnabled(fModel.isEditable()); |
| 497 |
return true; |
| 498 |
} |
| 499 |
} |
| 500 |
return false; |
| 501 |
} |
| 502 |
|
| 503 |
/** |
| 504 |
* Updates the add topic action if the action should be available for the selection. |
| 505 |
* Updates enablement, parent object and target object. Returns true if the action |
| 506 |
* should be available to the selection. |
| 507 |
* @param selectedObject selected object |
| 508 |
* @return true if the action should be available for the current selection, false otherwise |
| 509 |
*/ |
| 510 |
private boolean updateAddCommandActionWithSelection(CtxHelpObject selectedObject) { |
| 511 |
if (selectedObject != null) { |
| 512 |
if (selectedObject.canAddSibling(ICtxHelpConstants.TYPE_COMMAND)) { |
| 513 |
fAddCommandAction.setParentObject(selectedObject.getParent()); |
| 514 |
fAddCommandAction.setTargetObject(selectedObject); |
| 515 |
fAddCommandAction.setEnabled(fModel.isEditable()); |
| 516 |
return true; |
| 517 |
} else if (selectedObject.canAddChild(ICtxHelpConstants.TYPE_COMMAND)) { |
| 518 |
fAddCommandAction.setParentObject(selectedObject); |
| 519 |
fAddCommandAction.setTargetObject(null); |
| 520 |
fAddCommandAction.setEnabled(fModel.isEditable()); |
| 521 |
return true; |
| 522 |
} |
| 523 |
} |
| 524 |
return false; |
| 525 |
} |
| 526 |
|
| 527 |
/** |
| 528 |
* Updates the remove action if the action should be available for the selection. |
| 529 |
* Updates enablement, parent object and target object. Returns true if the action |
| 530 |
* should be available to the selection. |
| 531 |
* @param selectedObject selected object |
| 532 |
* @return true if the action should be available for the current selection, false otherwise |
| 533 |
*/ |
| 534 |
private boolean updateRemoveActionWithSelection(IStructuredSelection selection) { |
| 535 |
List objectsToRemove = getRemovableObjectFromSelection(selection); |
| 536 |
fRemoveObjectAction.setToRemove((CtxHelpObject[]) objectsToRemove.toArray(new CtxHelpObject[objectsToRemove.size()])); |
| 537 |
fRemoveObjectAction.setEnabled(fModel.isEditable()); |
| 538 |
return objectsToRemove.size() > 0; |
| 539 |
} |
| 540 |
|
| 541 |
/** |
| 542 |
* Returns a list of objects that is the subset of objects in the selection that |
| 543 |
* can be removed. |
| 544 |
* @param selection the selection |
| 545 |
* @return list of {@link CtxHelpObject}s that can be removed, possibly empty. |
| 546 |
*/ |
| 547 |
private List getRemovableObjectFromSelection(IStructuredSelection selection) { |
| 548 |
List objectsToRemove = new ArrayList(); |
| 549 |
for (Iterator iterator = selection.iterator(); iterator.hasNext();) { |
| 550 |
Object currentObject = iterator.next(); |
| 551 |
if (currentObject instanceof CtxHelpObject && ((CtxHelpObject) currentObject).canBeRemoved()) { |
| 552 |
objectsToRemove.add(currentObject); |
| 553 |
} |
| 554 |
} |
| 555 |
return objectsToRemove; |
| 556 |
} |
| 557 |
|
| 558 |
/* (non-Javadoc) |
| 559 |
* @see org.eclipse.pde.internal.ui.editor.PDESection#doGlobalAction(java.lang.String) |
| 560 |
*/ |
| 561 |
public boolean doGlobalAction(String actionId) { |
| 562 |
boolean cutAction = actionId.equals(ActionFactory.CUT.getId()); |
| 563 |
|
| 564 |
if (cutAction || actionId.equals(ActionFactory.DELETE.getId())) { |
| 565 |
updateRemoveActionWithSelection((IStructuredSelection) fTree.getSelection()); |
| 566 |
fRemoveObjectAction.run(); |
| 567 |
return !cutAction; |
| 568 |
} |
| 569 |
|
| 570 |
if (actionId.equals(ActionFactory.PASTE.getId())) { |
| 571 |
doPaste(); |
| 572 |
return true; |
| 573 |
} |
| 574 |
|
| 575 |
return false; |
| 576 |
} |
| 577 |
|
| 578 |
/* (non-Javadoc) |
| 579 |
* @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#canPaste(java.lang.Object, java.lang.Object[]) |
| 580 |
*/ |
| 581 |
protected boolean canPaste(Object targetObject, Object[] sourceObjects) { |
| 582 |
return canDropCopy(targetObject, sourceObjects, ViewerDropAdapter.LOCATION_ON); |
| 583 |
} |
| 584 |
|
| 585 |
/* (non-Javadoc) |
| 586 |
* @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#doPaste(java.lang.Object, java.lang.Object[]) |
| 587 |
*/ |
| 588 |
protected void doPaste(Object targetObject, Object[] sourceObjects) { |
| 589 |
doDropCopy(targetObject, sourceObjects, ViewerDropAdapter.LOCATION_ON); |
| 590 |
} |
| 591 |
|
| 592 |
/* (non-Javadoc) |
| 593 |
* @see org.eclipse.pde.internal.ui.editor.TreeSection#handleDoubleClick(org.eclipse.jface.viewers.IStructuredSelection) |
| 594 |
*/ |
| 595 |
protected void handleDoubleClick(IStructuredSelection selection) { |
| 596 |
Object selected = selection.getFirstElement(); |
| 597 |
if (selected instanceof CtxHelpTopic) { |
| 598 |
open((CtxHelpTopic) selected); |
| 599 |
} else if (selected instanceof CtxHelpObject) { |
| 600 |
fTree.expandToLevel(selected, 1); |
| 601 |
} |
| 602 |
} |
| 603 |
|
| 604 |
/** |
| 605 |
* Opens the file that is linked in the given topic. |
| 606 |
* @param topic the topic containing a link to a file |
| 607 |
*/ |
| 608 |
public void open(CtxHelpTopic topic) { |
| 609 |
IPath resourcePath = topic.getLocation(); |
| 610 |
if (!isEditable() || resourcePath == null || resourcePath.isEmpty()) { |
| 611 |
MessageDialog.openWarning(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.WindowImagesSection_open, PDEUIMessages.WindowImagesSection_emptyPath); |
| 612 |
return; |
| 613 |
} |
| 614 |
|
| 615 |
IResource resource = fModel.getUnderlyingResource().getProject().findMember(resourcePath); |
| 616 |
if (resource != null && resource instanceof IFile) { |
| 617 |
IPath path = resource.getFullPath(); |
| 618 |
if (HelpEditorUtil.hasValidPageExtension(path)) { |
| 619 |
try { |
| 620 |
IDE.openEditor(PDEPlugin.getActivePage(), (IFile) resource, true); |
| 621 |
} catch (PartInitException e) { //suppress exception |
| 622 |
} |
| 623 |
} else { |
| 624 |
MessageDialog.openWarning(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.WindowImagesSection_open, PDEUIMessages.TocPage_invalidHTMLFile); |
| 625 |
} |
| 626 |
} else { |
| 627 |
MessageDialog.openWarning(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.WindowImagesSection_open, PDEUIMessages.WindowImagesSection_warning); |
| 628 |
} |
| 629 |
} |
| 630 |
|
| 631 |
/* (non-Javadoc) |
| 632 |
* @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#buttonSelected(int) |
| 633 |
*/ |
| 634 |
protected void buttonSelected(int index) { |
| 635 |
IStructuredSelection selection = (IStructuredSelection) fTree.getSelection(); |
| 636 |
Object object = selection.getFirstElement(); |
| 637 |
CtxHelpObject firstSelectedObject = (CtxHelpObject) object; |
| 638 |
switch (index) { |
| 639 |
case F_BUTTON_ADD_CONTEXT : |
| 640 |
updateAddContextActionWithSelection(firstSelectedObject); |
| 641 |
fAddContextAction.run(); |
| 642 |
break; |
| 643 |
case F_BUTTON_ADD_TOPIC : |
| 644 |
updateAddTopicActionWithSelection(firstSelectedObject); |
| 645 |
fAddTopicAction.run(); |
| 646 |
break; |
| 647 |
case F_BUTTON_ADD_COMMAND : |
| 648 |
updateAddCommandActionWithSelection(firstSelectedObject); |
| 649 |
fAddCommandAction.run(); |
| 650 |
break; |
| 651 |
case F_BUTTON_REMOVE : |
| 652 |
updateRemoveActionWithSelection(selection); |
| 653 |
fRemoveObjectAction.run(); |
| 654 |
break; |
| 655 |
case F_BUTTON_UP : |
| 656 |
handleMoveAction(F_UP_FLAG); |
| 657 |
break; |
| 658 |
case F_BUTTON_DOWN : |
| 659 |
handleMoveAction(F_DOWN_FLAG); |
| 660 |
break; |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
/** |
| 665 |
* Move an object within the structure. |
| 666 |
* |
| 667 |
* @param positionFlag The direction that the object will move, either F_UP_FLAG or F_DOWN_FLAG |
| 668 |
*/ |
| 669 |
private void handleMoveAction(int positionFlag) { |
| 670 |
IStructuredSelection sel = (IStructuredSelection) fTree.getSelection(); |
| 671 |
|
| 672 |
Object object = sel.getFirstElement(); |
| 673 |
if (object == null) { |
| 674 |
return; |
| 675 |
} else if (object instanceof CtxHelpObject) { |
| 676 |
CtxHelpObject ctxHelpObject = (CtxHelpObject) object; |
| 677 |
CtxHelpObject parent = ctxHelpObject.getParent(); |
| 678 |
if (parent != null) { |
| 679 |
parent.moveChild(ctxHelpObject, positionFlag); |
| 680 |
fTree.setSelection(new StructuredSelection(ctxHelpObject), true); |
| 681 |
} |
| 682 |
} |
| 683 |
|
| 684 |
} |
| 685 |
|
| 686 |
/* (non-Javadoc) |
| 687 |
* @see org.eclipse.ui.forms.AbstractFormPart#refresh() |
| 688 |
*/ |
| 689 |
public void refresh() { |
| 690 |
CtxHelpModel model = (CtxHelpModel) getPage().getModel(); |
| 691 |
fTree.setInput(model); |
| 692 |
fTree.expandToLevel(2); |
| 693 |
fTree.setSelection(new StructuredSelection(model.getCtxHelpRoot()), true); |
| 694 |
getManagedForm().fireSelectionChanged(this, fTree.getSelection()); |
| 695 |
super.refresh(); |
| 696 |
} |
| 697 |
|
| 698 |
/* (non-Javadoc) |
| 699 |
* @see org.eclipse.ui.forms.AbstractFormPart#dispose() |
| 700 |
*/ |
| 701 |
public void dispose() { |
| 702 |
PDEPlugin.getDefault().getLabelProvider().disconnect(this); |
| 703 |
super.dispose(); |
| 704 |
} |
| 705 |
|
| 706 |
/* (non-Javadoc) |
| 707 |
* @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#isDragAndDropEnabled() |
| 708 |
*/ |
| 709 |
protected boolean isDragAndDropEnabled() { |
| 710 |
// TODO DND turned off because the inserted element would often be placed in the wrong location in the xml |
| 711 |
return false; |
| 712 |
} |
| 713 |
|
| 714 |
/* (non-Javadoc) |
| 715 |
* @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#getSupportedDNDOperations() |
| 716 |
*/ |
| 717 |
public int getSupportedDNDOperations() { |
| 718 |
return DND.DROP_MOVE | DND.DROP_COPY; |
| 719 |
} |
| 720 |
|
| 721 |
/* (non-Javadoc) |
| 722 |
* @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#doDropCopy(java.lang.Object, java.lang.Object[], int) |
| 723 |
*/ |
| 724 |
public void doDropCopy(Object targetObject, Object[] sourceObjects, int targetLocation) { |
| 725 |
if (fDropTargetParent != null) { |
| 726 |
if (fDropTargetSibling != null) { |
| 727 |
if (targetLocation == ViewerDropAdapter.LOCATION_BEFORE) { |
| 728 |
for (int i = 0; i < sourceObjects.length; i++) { |
| 729 |
fDropTargetParent.addChild((CtxHelpObject) sourceObjects[i], fDropTargetSibling, true); |
| 730 |
} |
| 731 |
} else { |
| 732 |
for (int i = sourceObjects.length - 1; i >= 0; i--) { |
| 733 |
fDropTargetParent.addChild((CtxHelpObject) sourceObjects[i], fDropTargetSibling, false); |
| 734 |
} |
| 735 |
} |
| 736 |
} else { |
| 737 |
for (int i = 0; i < sourceObjects.length; i++) { |
| 738 |
fDropTargetParent.addChild((CtxHelpObject) sourceObjects[i]); |
| 739 |
} |
| 740 |
} |
| 741 |
} |
| 742 |
fDropTargetParent = null; |
| 743 |
fDropTargetSibling = null; |
| 744 |
} |
| 745 |
|
| 746 |
/* (non-Javadoc) |
| 747 |
* @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#doDropMove(java.lang.Object, java.lang.Object[], int) |
| 748 |
*/ |
| 749 |
public void doDropMove(Object targetObject, Object[] sourceObjects, int targetLocation) { |
| 750 |
doDropCopy(targetObject, sourceObjects, targetLocation); |
| 751 |
} |
| 752 |
|
| 753 |
/* (non-Javadoc) |
| 754 |
* @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#canDropCopy(java.lang.Object, java.lang.Object[], int) |
| 755 |
*/ |
| 756 |
public boolean canDropCopy(Object targetObject, Object[] sourceObjects, int targetLocation) { |
| 757 |
// Add as a child of the root |
| 758 |
if (targetObject == null || !(targetObject instanceof CtxHelpObject || ((CtxHelpObject) targetObject).getType() == ICtxHelpConstants.TYPE_ROOT)) { |
| 759 |
for (int i = 0; i < sourceObjects.length; i++) { |
| 760 |
if (!(sourceObjects[i] instanceof CtxHelpObject) || !fModel.getCtxHelpRoot().canAddChild(((CtxHelpObject) sourceObjects[i]).getType())) { |
| 761 |
return false; |
| 762 |
} |
| 763 |
} |
| 764 |
fDropTargetParent = fModel.getCtxHelpRoot(); |
| 765 |
fDropTargetSibling = null; |
| 766 |
return true; |
| 767 |
} |
| 768 |
|
| 769 |
CtxHelpObject dropTarget = (CtxHelpObject) targetObject; |
| 770 |
|
| 771 |
// Add as a child of the target |
| 772 |
if (targetLocation == ViewerDropAdapter.LOCATION_ON) { |
| 773 |
boolean result = true; |
| 774 |
for (int i = 0; i < sourceObjects.length; i++) { |
| 775 |
if (!(sourceObjects[i] instanceof CtxHelpObject) || !dropTarget.canAddChild(((CtxHelpObject) sourceObjects[i]).getType())) { |
| 776 |
result = false; |
| 777 |
break; |
| 778 |
} |
| 779 |
} |
| 780 |
// If adding as a child works, do so, otherwise try as a sibling |
| 781 |
if (result) { |
| 782 |
fDropTargetParent = dropTarget; |
| 783 |
fDropTargetSibling = null; |
| 784 |
return true; |
| 785 |
} |
| 786 |
} |
| 787 |
|
| 788 |
// Add as a sibling of the target |
| 789 |
for (int i = 0; i < sourceObjects.length; i++) { |
| 790 |
if (!(sourceObjects[i] instanceof CtxHelpObject) || !dropTarget.canAddSibling(((CtxHelpObject) sourceObjects[i]).getType())) { |
| 791 |
return false; |
| 792 |
} |
| 793 |
} |
| 794 |
fDropTargetParent = dropTarget.getParent(); |
| 795 |
fDropTargetSibling = dropTarget; |
| 796 |
return true; |
| 797 |
} |
| 798 |
|
| 799 |
/* (non-Javadoc) |
| 800 |
* @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#canDropMove(java.lang.Object, java.lang.Object[], int) |
| 801 |
*/ |
| 802 |
public boolean canDropMove(Object targetObject, Object[] sourceObjects, int targetLocation) { |
| 803 |
// Same as drop copy operation |
| 804 |
return canDropCopy(targetObject, sourceObjects, targetLocation); |
| 805 |
} |
| 806 |
|
| 807 |
/* (non-Javadoc) |
| 808 |
* @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#canDragCopy(java.lang.Object[]) |
| 809 |
*/ |
| 810 |
public boolean canDragCopy(Object[] sourceObjects) { |
| 811 |
// Allow anything to be drag copied |
| 812 |
return true; |
| 813 |
} |
| 814 |
|
| 815 |
/* (non-Javadoc) |
| 816 |
* @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#canDragMove(java.lang.Object[]) |
| 817 |
*/ |
| 818 |
public boolean canDragMove(Object[] sourceObjects) { |
| 819 |
for (int i = 0; i < sourceObjects.length; i++) { |
| 820 |
if (!(sourceObjects[i] instanceof CtxHelpObject) || !((CtxHelpObject) sourceObjects[i]).canBeRemoved()) { |
| 821 |
return false; |
| 822 |
} |
| 823 |
} |
| 824 |
fDragFromHere = true; |
| 825 |
return true; |
| 826 |
} |
| 827 |
|
| 828 |
/* (non-Javadoc) |
| 829 |
* @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#doDragRemove(java.lang.Object[]) |
| 830 |
*/ |
| 831 |
public void doDragRemove(Object[] sourceObjects) { |
| 832 |
updateRemoveActionWithSelection(new StructuredSelection(sourceObjects)); |
| 833 |
fRemoveObjectAction.run(); |
| 834 |
fDragFromHere = false; |
| 835 |
} |
| 836 |
|
| 837 |
/* (non-Javadoc) |
| 838 |
* @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent) |
| 839 |
*/ |
| 840 |
public void modelChanged(IModelChangedEvent event) { |
| 841 |
// No need to call super, world changed event handled here |
| 842 |
if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) { |
| 843 |
handleModelEventWorldChanged(event); |
| 844 |
} else if (event.getChangeType() == IModelChangedEvent.INSERT) { |
| 845 |
handleModelInsertType(event); |
| 846 |
} else if (event.getChangeType() == IModelChangedEvent.REMOVE) { |
| 847 |
handleModelRemoveType(event); |
| 848 |
} else if ((event.getChangeType() == IModelChangedEvent.CHANGE) && (event.getChangedProperty().equals(IDocumentElementNode.F_PROPERTY_CHANGE_TYPE_SWAP))) { |
| 849 |
handleModelChangeTypeSwap(event); |
| 850 |
} else if (event.getChangeType() == IModelChangedEvent.CHANGE) { |
| 851 |
handleModelChangeType(event); |
| 852 |
} |
| 853 |
} |
| 854 |
|
| 855 |
/** |
| 856 |
* Handles the swap event |
| 857 |
* @param event the swap event |
| 858 |
*/ |
| 859 |
private void handleModelChangeTypeSwap(IModelChangedEvent event) { |
| 860 |
Object[] objects = event.getChangedObjects(); |
| 861 |
CtxHelpObject object = (CtxHelpObject) objects[0]; |
| 862 |
|
| 863 |
if (object != null) { |
| 864 |
fTree.refresh(object); |
| 865 |
} |
| 866 |
} |
| 867 |
|
| 868 |
/** |
| 869 |
* The model is stale, refresh the UI |
| 870 |
* @param event The world-change event |
| 871 |
*/ |
| 872 |
private void handleModelEventWorldChanged(IModelChangedEvent event) { |
| 873 |
markStale(); |
| 874 |
} |
| 875 |
|
| 876 |
/** |
| 877 |
* Handle insertions in the model |
| 878 |
* @param event the insertion event |
| 879 |
*/ |
| 880 |
private void handleModelInsertType(IModelChangedEvent event) { |
| 881 |
Object[] objects = event.getChangedObjects(); |
| 882 |
for (int i = 0; i < objects.length; i++) { |
| 883 |
CtxHelpObject object = (CtxHelpObject) objects[i]; |
| 884 |
if (object != null) { |
| 885 |
if (object.getType() != ICtxHelpConstants.TYPE_ROOT) { |
| 886 |
fTree.refresh(object.getParent()); |
| 887 |
// Select the new object in the tree, unless it is a description node |
| 888 |
if (!(object instanceof CtxHelpDescription)) { |
| 889 |
fTree.setSelection(new StructuredSelection(object), true); |
| 890 |
} |
| 891 |
} |
| 892 |
} |
| 893 |
} |
| 894 |
} |
| 895 |
|
| 896 |
/** |
| 897 |
* Handle removals in the model |
| 898 |
* @param event the removal event |
| 899 |
*/ |
| 900 |
private void handleModelRemoveType(IModelChangedEvent event) { |
| 901 |
Object[] objects = event.getChangedObjects(); |
| 902 |
for (int i = 0; i < objects.length; i++) { |
| 903 |
if (objects[i] != null) { |
| 904 |
CtxHelpObject object = (CtxHelpObject) objects[i]; |
| 905 |
fTree.remove(object); |
| 906 |
CtxHelpObject nextSelection = fRemoveObjectAction.getNextSelection(); |
| 907 |
if (nextSelection != null) { |
| 908 |
fTree.refresh(object.getParent()); |
| 909 |
if (!fDragFromHere) { |
| 910 |
fTree.setSelection(new StructuredSelection(nextSelection), true); |
| 911 |
} |
| 912 |
fRemoveObjectAction.clearNextSelection(); |
| 913 |
} |
| 914 |
} |
| 915 |
} |
| 916 |
} |
| 917 |
|
| 918 |
/** |
| 919 |
* Handle an update to an object's properties |
| 920 |
* @param event the update event |
| 921 |
*/ |
| 922 |
private void handleModelChangeType(IModelChangedEvent event) { |
| 923 |
Object[] objects = event.getChangedObjects(); |
| 924 |
CtxHelpObject object = (CtxHelpObject) objects[0]; |
| 925 |
|
| 926 |
if (object != null) { |
| 927 |
fTree.update(object, null); |
| 928 |
} |
| 929 |
} |
| 930 |
|
| 931 |
} |