0001: /*******************************************************************************
0002: * Copyright (c) 2000, 2007 IBM Corporation and others.
0003: * All rights reserved. This program and the accompanying materials
0004: * are made available under the terms of the Eclipse Public License v1.0
0005: * which accompanies this distribution, and is available at
0006: * http://www.eclipse.org/legal/epl-v10.html
0007: *
0008: * Contributors:
0009: * IBM Corporation - initial API and implementation
0010: * Peter Friese <peter.friese@gentleware.com> - bug 194529, bug 196867
0011: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.plugin;
0012:
0013: import java.util.ArrayList;
0014: import java.util.HashSet;
0015: import java.util.Hashtable;
0016: import java.util.Iterator;
0017: import java.util.TreeSet;
0018:
0019: import org.eclipse.core.resources.IProject;
0020: import org.eclipse.core.runtime.CoreException;
0021: import org.eclipse.core.runtime.IConfigurationElement;
0022: import org.eclipse.core.runtime.Path;
0023: import org.eclipse.core.runtime.Platform;
0024: import org.eclipse.jface.action.Action;
0025: import org.eclipse.jface.action.IAction;
0026: import org.eclipse.jface.action.IMenuManager;
0027: import org.eclipse.jface.action.MenuManager;
0028: import org.eclipse.jface.action.Separator;
0029: import org.eclipse.jface.action.ToolBarManager;
0030: import org.eclipse.jface.util.IPropertyChangeListener;
0031: import org.eclipse.jface.util.PropertyChangeEvent;
0032: import org.eclipse.jface.viewers.ISelection;
0033: import org.eclipse.jface.viewers.IStructuredSelection;
0034: import org.eclipse.jface.viewers.ITreeContentProvider;
0035: import org.eclipse.jface.viewers.LabelProvider;
0036: import org.eclipse.jface.viewers.StructuredSelection;
0037: import org.eclipse.jface.viewers.StructuredViewer;
0038: import org.eclipse.jface.viewers.TreeViewer;
0039: import org.eclipse.jface.viewers.ViewerDropAdapter;
0040: import org.eclipse.jface.wizard.WizardDialog;
0041: import org.eclipse.pde.core.IModelChangedEvent;
0042: import org.eclipse.pde.core.IModelChangedListener;
0043: import org.eclipse.pde.core.plugin.IExtensions;
0044: import org.eclipse.pde.core.plugin.IPluginAttribute;
0045: import org.eclipse.pde.core.plugin.IPluginBase;
0046: import org.eclipse.pde.core.plugin.IPluginElement;
0047: import org.eclipse.pde.core.plugin.IPluginExtension;
0048: import org.eclipse.pde.core.plugin.IPluginModelBase;
0049: import org.eclipse.pde.core.plugin.IPluginObject;
0050: import org.eclipse.pde.core.plugin.IPluginParent;
0051: import org.eclipse.pde.core.plugin.ISharedExtensionsModel;
0052: import org.eclipse.pde.core.plugin.ISharedPluginModel;
0053: import org.eclipse.pde.internal.core.PDECore;
0054: import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
0055: import org.eclipse.pde.internal.core.ischema.ISchema;
0056: import org.eclipse.pde.internal.core.ischema.ISchemaComplexType;
0057: import org.eclipse.pde.internal.core.ischema.ISchemaElement;
0058: import org.eclipse.pde.internal.core.schema.SchemaRegistry;
0059: import org.eclipse.pde.internal.core.text.IDocumentElementNode;
0060: import org.eclipse.pde.internal.core.text.plugin.PluginBaseNode;
0061: import org.eclipse.pde.internal.ui.PDELabelProvider;
0062: import org.eclipse.pde.internal.ui.PDEPlugin;
0063: import org.eclipse.pde.internal.ui.PDEPluginImages;
0064: import org.eclipse.pde.internal.ui.PDEUIMessages;
0065: import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
0066: import org.eclipse.pde.internal.ui.editor.PDEFormPage;
0067: import org.eclipse.pde.internal.ui.editor.TreeSection;
0068: import org.eclipse.pde.internal.ui.editor.actions.CollapseAction;
0069: import org.eclipse.pde.internal.ui.editor.actions.SortAction;
0070: import org.eclipse.pde.internal.ui.editor.contentassist.XMLElementProposalComputer;
0071: import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
0072: import org.eclipse.pde.internal.ui.parts.TreePart;
0073: import org.eclipse.pde.internal.ui.search.PluginSearchActionGroup;
0074: import org.eclipse.pde.internal.ui.util.SWTUtil;
0075: import org.eclipse.pde.internal.ui.util.SharedLabelProvider;
0076: import org.eclipse.pde.internal.ui.wizards.extension.ExtensionEditorWizard;
0077: import org.eclipse.pde.internal.ui.wizards.extension.NewExtensionWizard;
0078: import org.eclipse.pde.ui.IExtensionEditorWizard;
0079: import org.eclipse.swt.SWT;
0080: import org.eclipse.swt.custom.BusyIndicator;
0081: import org.eclipse.swt.events.DisposeEvent;
0082: import org.eclipse.swt.events.DisposeListener;
0083: import org.eclipse.swt.events.ModifyEvent;
0084: import org.eclipse.swt.events.ModifyListener;
0085: import org.eclipse.swt.graphics.Cursor;
0086: import org.eclipse.swt.graphics.Image;
0087: import org.eclipse.swt.internal.BidiUtil;
0088: import org.eclipse.swt.widgets.Composite;
0089: import org.eclipse.swt.widgets.Display;
0090: import org.eclipse.swt.widgets.ToolBar;
0091: import org.eclipse.swt.widgets.Tree;
0092: import org.eclipse.swt.widgets.TreeItem;
0093: import org.eclipse.ui.actions.ActionContext;
0094: import org.eclipse.ui.actions.ActionFactory;
0095: import org.eclipse.ui.dialogs.PatternFilter;
0096: import org.eclipse.ui.forms.widgets.FormToolkit;
0097: import org.eclipse.ui.forms.widgets.Section;
0098:
0099: public class ExtensionsSection extends TreeSection implements
0100: IModelChangedListener, IPropertyChangeListener {
0101: private static final int BUTTON_MOVE_DOWN = 4;
0102: private static final int BUTTON_MOVE_UP = 3;
0103: private static final int BUTTON_EDIT = 2;
0104: private static final int BUTTON_REMOVE = 1;
0105: private TreeViewer fExtensionTree;
0106: private Image fExtensionImage;
0107: private Image fGenericElementImage;
0108: private FormFilteredTree fFilteredTree;
0109: private SchemaRegistry fSchemaRegistry;
0110: private Hashtable fEditorWizards;
0111: private SortAction fSortAction;
0112: private CollapseAction fCollapseAction;
0113:
0114: private static final int BUTTON_ADD = 0;
0115:
0116: private static final String[] COMMON_LABEL_PROPERTIES = { "label", //$NON-NLS-1$
0117: "name", //$NON-NLS-1$
0118: "id" }; //$NON-NLS-1$
0119:
0120: private static final String[] VALID_IMAGE_TYPES = {
0121: "png", "bmp", "ico", "gif", "jpg", "tiff" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
0122:
0123: class ExtensionContentProvider extends DefaultContentProvider
0124: implements ITreeContentProvider {
0125: public Object[] getChildren(Object parent) {
0126: Object[] children = null;
0127: if (parent instanceof IPluginBase)
0128: children = ((IPluginBase) parent).getExtensions();
0129: else if (parent instanceof IPluginExtension) {
0130: children = ((IPluginExtension) parent).getChildren();
0131: } else if (parent instanceof IPluginElement) {
0132: children = ((IPluginElement) parent).getChildren();
0133: }
0134: if (children == null)
0135: children = new Object[0];
0136: return children;
0137: }
0138:
0139: public boolean hasChildren(Object parent) {
0140: return getChildren(parent).length > 0;
0141: }
0142:
0143: public Object getParent(Object child) {
0144: if (child instanceof IPluginExtension) {
0145: return ((IPluginModelBase) getPage().getModel())
0146: .getPluginBase();
0147: }
0148: if (child instanceof IPluginObject)
0149: return ((IPluginObject) child).getParent();
0150: return null;
0151: }
0152:
0153: public Object[] getElements(Object parent) {
0154: return getChildren(parent);
0155: }
0156: }
0157:
0158: class ExtensionLabelProvider extends LabelProvider {
0159: public String getText(Object obj) {
0160: return resolveObjectName(obj);
0161: }
0162:
0163: public Image getImage(Object obj) {
0164: return resolveObjectImage(obj);
0165: }
0166: }
0167:
0168: public ExtensionsSection(PDEFormPage page, Composite parent) {
0169: super (page, parent, Section.DESCRIPTION, new String[] {
0170: PDEUIMessages.ManifestEditor_DetailExtension_new,
0171: PDEUIMessages.ManifestEditor_DetailExtension_remove,
0172: PDEUIMessages.ManifestEditor_DetailExtension_edit,
0173: PDEUIMessages.ManifestEditor_DetailExtension_up,
0174: PDEUIMessages.ManifestEditor_DetailExtension_down });
0175: fHandleDefaultButton = false;
0176: }
0177:
0178: private static void addItemsForExtensionWithSchema(
0179: MenuManager menu, IPluginExtension extension,
0180: IPluginParent parent) {
0181: ISchema schema = getSchema(extension);
0182: String tagName = (parent == extension ? "extension" : parent.getName()); //$NON-NLS-1$
0183: ISchemaElement elementInfo = schema.findElement(tagName);
0184:
0185: if ((elementInfo != null)
0186: && (elementInfo.getType() instanceof ISchemaComplexType)
0187: && (parent instanceof IDocumentElementNode)) {
0188: // We have a schema complex type. Either the element has attributes
0189: // or the element has children.
0190: // Generate the list of element proposals
0191: TreeSet elementSet = XMLElementProposalComputer
0192: .computeElementProposal(elementInfo,
0193: (IDocumentElementNode) parent);
0194:
0195: // Create a corresponding menu entry for each element proposal
0196: Iterator iterator = elementSet.iterator();
0197: while (iterator.hasNext()) {
0198: Action action = new NewElementAction(
0199: (ISchemaElement) iterator.next(), parent);
0200: menu.add(action);
0201: }
0202: }
0203: }
0204:
0205: /**
0206: * @param parent
0207: * @return
0208: */
0209: private static ISchema getSchema(IPluginParent parent) {
0210: if (parent instanceof IPluginExtension) {
0211: return getSchema((IPluginExtension) parent);
0212: } else if (parent instanceof IPluginElement) {
0213: return getSchema((IPluginElement) parent);
0214: } else {
0215: return null;
0216: }
0217: }
0218:
0219: private static ISchema getSchema(IPluginExtension extension) {
0220: String point = extension.getPoint();
0221: SchemaRegistry registry = PDECore.getDefault()
0222: .getSchemaRegistry();
0223: return registry.getSchema(point);
0224: }
0225:
0226: /**
0227: * @param element
0228: * @return
0229: */
0230: static ISchemaElement getSchemaElement(IPluginElement element) {
0231: ISchema schema = getSchema(element);
0232: if (schema != null) {
0233: return schema.findElement(element.getName());
0234: }
0235: return null;
0236: }
0237:
0238: /**
0239: * @param element
0240: * @return
0241: */
0242: private static ISchema getSchema(IPluginElement element) {
0243: IPluginObject parent = element.getParent();
0244: while (parent != null && !(parent instanceof IPluginExtension)) {
0245: parent = parent.getParent();
0246: }
0247: if (parent != null) {
0248: return getSchema((IPluginExtension) parent);
0249: }
0250: return null;
0251: }
0252:
0253: public void createClient(Section section, FormToolkit toolkit) {
0254: initializeImages();
0255: Composite container = createClientContainer(section, 2, toolkit);
0256: TreePart treePart = getTreePart();
0257: createViewerPartControl(container, SWT.SINGLE, 2, toolkit);
0258: fExtensionTree = treePart.getTreeViewer();
0259: fExtensionTree
0260: .setContentProvider(new ExtensionContentProvider());
0261: fExtensionTree.setLabelProvider(new ExtensionLabelProvider());
0262: toolkit.paintBordersFor(container);
0263: section.setClient(container);
0264: section
0265: .setDescription(PDEUIMessages.ExtensionsSection_sectionDescExtensionsMaster);
0266: // See Bug # 160554: Set text before text client
0267: section
0268: .setText(PDEUIMessages.ManifestEditor_DetailExtension_title);
0269: initialize((IPluginModelBase) getPage().getModel());
0270: createSectionToolbar(section, toolkit);
0271: // Create the adapted listener for the filter entry field
0272: fFilteredTree.createUIListenerEntryFilter(this );
0273: fFilteredTree.getFilterControl().addModifyListener(
0274: new ModifyListener() {
0275: public void modifyText(ModifyEvent e) {
0276: StructuredViewer viewer = getStructuredViewerPart()
0277: .getViewer();
0278: IStructuredSelection ssel = (IStructuredSelection) viewer
0279: .getSelection();
0280: updateButtons(ssel.size() != 1 ? null : ssel
0281: .getFirstElement());
0282: }
0283: });
0284: }
0285:
0286: /**
0287: * @param section
0288: * @param toolkit
0289: */
0290: private void createSectionToolbar(Section section,
0291: FormToolkit toolkit) {
0292: ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
0293: ToolBar toolbar = toolBarManager.createControl(section);
0294: final Cursor handCursor = new Cursor(Display.getCurrent(),
0295: SWT.CURSOR_HAND);
0296: toolbar.setCursor(handCursor);
0297: // Cursor needs to be explicitly disposed
0298: toolbar.addDisposeListener(new DisposeListener() {
0299: public void widgetDisposed(DisposeEvent e) {
0300: if ((handCursor != null)
0301: && (handCursor.isDisposed() == false)) {
0302: handCursor.dispose();
0303: }
0304: }
0305: });
0306: // Add sort action to the tool bar
0307: fSortAction = new SortAction(fExtensionTree,
0308: PDEUIMessages.ExtensionsPage_sortAlpha, null, null,
0309: this );
0310: toolBarManager.add(fSortAction);
0311: // Add collapse action to the tool bar
0312: fCollapseAction = new CollapseAction(fExtensionTree,
0313: PDEUIMessages.ExtensionsPage_collapseAll);
0314: toolBarManager.add(fCollapseAction);
0315:
0316: toolBarManager.update(true);
0317:
0318: section.setTextClient(toolbar);
0319: }
0320:
0321: protected void selectionChanged(IStructuredSelection selection) {
0322: getPage().getPDEEditor().setSelection(selection);
0323: updateButtons(selection.getFirstElement());
0324: getTreePart().getButton(BUTTON_EDIT).setVisible(
0325: isSelectionEditable(selection));
0326: }
0327:
0328: protected void buttonSelected(int index) {
0329: switch (index) {
0330: case BUTTON_ADD:
0331: handleNew();
0332: break;
0333: case BUTTON_REMOVE:
0334: handleDelete();
0335: break;
0336: case BUTTON_EDIT:
0337: handleEdit();
0338: break;
0339: case BUTTON_MOVE_UP:
0340: handleMove(true);
0341: break;
0342: case BUTTON_MOVE_DOWN:
0343: handleMove(false);
0344: break;
0345: }
0346: }
0347:
0348: /* (non-Javadoc)
0349: * @see org.eclipse.ui.forms.AbstractFormPart#dispose()
0350: */
0351: public void dispose() {
0352: // Explicitly call the dispose method on the extensions tree
0353: if (fFilteredTree != null) {
0354: fFilteredTree.dispose();
0355: }
0356: fEditorWizards = null;
0357: IPluginModelBase model = (IPluginModelBase) getPage()
0358: .getPDEEditor().getAggregateModel();
0359: if (model != null)
0360: model.removeModelChangedListener(this );
0361: super .dispose();
0362: }
0363:
0364: /* (non-Javadoc)
0365: * @see org.eclipse.pde.internal.ui.editor.PDESection#doGlobalAction(java.lang.String)
0366: */
0367: public boolean doGlobalAction(String actionId) {
0368:
0369: if (!isEditable()) {
0370: return false;
0371: }
0372:
0373: if (actionId.equals(ActionFactory.DELETE.getId())) {
0374: handleDelete();
0375: return true;
0376: }
0377: if (actionId.equals(ActionFactory.CUT.getId())) {
0378: // delete here and let the editor transfer
0379: // the selection to the clipboard
0380: handleDelete();
0381: return false;
0382: }
0383: if (actionId.equals(ActionFactory.PASTE.getId())) {
0384: doPaste();
0385: return true;
0386: }
0387:
0388: return false;
0389: }
0390:
0391: public boolean setFormInput(Object object) {
0392: if (object instanceof IPluginExtension
0393: || object instanceof IPluginElement) {
0394: fExtensionTree.setSelection(
0395: new StructuredSelection(object), true);
0396: return true;
0397: }
0398: return false;
0399: }
0400:
0401: protected void fillContextMenu(IMenuManager manager) {
0402: ISelection selection = fExtensionTree.getSelection();
0403: IStructuredSelection ssel = (IStructuredSelection) selection;
0404: if (ssel.size() == 1) {
0405: Object object = ssel.getFirstElement();
0406: if (object instanceof IPluginParent) {
0407: IPluginParent parent = (IPluginParent) object;
0408: if (parent.getModel().getUnderlyingResource() != null) {
0409: fillContextMenu(getPage(), parent, manager);
0410: manager.add(new Separator());
0411: }
0412: }
0413: } else if (ssel.size() > 1) {
0414: // multiple
0415: Action delAction = new Action() {
0416: public void run() {
0417: handleDelete();
0418: }
0419: };
0420: delAction.setText(PDEUIMessages.Actions_delete_label);
0421: manager.add(delAction);
0422: manager.add(new Separator());
0423: delAction.setEnabled(isEditable());
0424: }
0425: if (ssel.size() == 1) {
0426: manager.add(new Separator());
0427: Object object = ssel.getFirstElement();
0428: if (object instanceof IPluginExtension) {
0429: PluginSearchActionGroup actionGroup = new PluginSearchActionGroup();
0430: actionGroup.setContext(new ActionContext(selection));
0431: actionGroup.fillContextMenu(manager);
0432: manager.add(new Separator());
0433: }
0434: //manager.add(new PropertiesAction(getFormPage().getEditor()));
0435: }
0436: manager.add(new Separator());
0437: manager.add(new Separator());
0438: getPage().getPDEEditor().getContributor().addClipboardActions(
0439: manager);
0440: getPage().getPDEEditor().getContributor()
0441: .contextMenuAboutToShow(manager, false);
0442:
0443: }
0444:
0445: static IMenuManager fillContextMenu(PDEFormPage page,
0446: final IPluginParent parent, IMenuManager manager) {
0447: return fillContextMenu(page, parent, manager, false);
0448: }
0449:
0450: static IMenuManager fillContextMenu(PDEFormPage page,
0451: final IPluginParent parent, IMenuManager manager,
0452: boolean addSiblingItems) {
0453: return fillContextMenu(page, parent, manager, addSiblingItems,
0454: true);
0455: }
0456:
0457: static IMenuManager fillContextMenu(PDEFormPage page,
0458: final IPluginParent parent, IMenuManager manager,
0459: boolean addSiblingItems, boolean fullMenu) {
0460: MenuManager menu = new MenuManager(
0461: PDEUIMessages.Menus_new_label);
0462: IPluginExtension extension = getExtension(parent);
0463: ISchema schema = getSchema(extension);
0464: if (schema == null) {
0465: menu.add(new NewElementAction(null, parent));
0466: } else {
0467: addItemsForExtensionWithSchema(menu, extension, parent);
0468: if (addSiblingItems) {
0469: IPluginObject parentsParent = parent.getParent();
0470: if (!(parentsParent instanceof IPluginExtension)) {
0471: IPluginParent pparent = (IPluginParent) parentsParent;
0472: menu.add(new Separator());
0473: addItemsForExtensionWithSchema(menu, extension,
0474: pparent);
0475: }
0476: }
0477: }
0478: manager.add(menu);
0479: manager.add(new Separator());
0480: if (fullMenu) {
0481: Action deleteAction = new Action(
0482: PDEUIMessages.Actions_delete_label) {
0483: public void run() {
0484: try {
0485: IPluginObject parentsParent = parent
0486: .getParent();
0487: if (parent instanceof IPluginExtension) {
0488: IPluginBase plugin = (IPluginBase) parentsParent;
0489: plugin.remove((IPluginExtension) parent);
0490: } else {
0491: IPluginParent parentElement = (IPluginParent) parent
0492: .getParent();
0493: parentElement.remove(parent);
0494: }
0495: } catch (CoreException e) {
0496: }
0497: }
0498: };
0499: deleteAction.setEnabled(page.getModel().isEditable());
0500: manager.add(deleteAction);
0501: }
0502: return menu;
0503: }
0504:
0505: static IPluginExtension getExtension(IPluginParent parent) {
0506: while (parent != null && !(parent instanceof IPluginExtension)) {
0507: parent = (IPluginParent) parent.getParent();
0508: }
0509: return (IPluginExtension) parent;
0510: }
0511:
0512: private void handleDelete() {
0513: IStructuredSelection sel = (IStructuredSelection) fExtensionTree
0514: .getSelection();
0515: if (sel.isEmpty())
0516: return;
0517: for (Iterator iter = sel.iterator(); iter.hasNext();) {
0518: IPluginObject object = (IPluginObject) iter.next();
0519: try {
0520: IStructuredSelection newSelection = null;
0521: boolean sorted = fSortAction != null
0522: && fSortAction.isChecked();
0523: if (object instanceof IPluginElement) {
0524: IPluginElement ee = (IPluginElement) object;
0525: IPluginParent parent = (IPluginParent) ee
0526: .getParent();
0527: if (!sorted) {
0528: int index = getNewSelectionIndex(parent
0529: .getIndexOf(ee), parent.getChildCount());
0530: newSelection = index == -1 ? new StructuredSelection(
0531: parent)
0532: : new StructuredSelection(parent
0533: .getChildren()[index]);
0534: } else {
0535: IPluginObject original[] = parent.getChildren();
0536: IPluginObject objects[] = new IPluginObject[original.length];
0537: for (int i = 0; i < original.length; i++)
0538: objects[i] = original[i];
0539: fExtensionTree.getComparator().sort(
0540: fExtensionTree, objects);
0541: int index = getNewSelectionIndex(getArrayIndex(
0542: objects, ee), objects.length);
0543: newSelection = index == -1 ? new StructuredSelection(
0544: parent)
0545: : new StructuredSelection(
0546: objects[index]);
0547: }
0548: parent.remove(ee);
0549: } else if (object instanceof IPluginExtension) {
0550: IPluginExtension extension = (IPluginExtension) object;
0551: IPluginBase plugin = extension.getPluginBase();
0552: if (!sorted) {
0553: int index = getNewSelectionIndex(plugin
0554: .getIndexOf(extension), plugin
0555: .getExtensions().length);
0556: if (index != -1)
0557: newSelection = new StructuredSelection(
0558: plugin.getExtensions()[index]);
0559: } else {
0560: IPluginExtension original[] = plugin
0561: .getExtensions();
0562: IPluginExtension extensions[] = new IPluginExtension[original.length];
0563: for (int i = 0; i < original.length; i++)
0564: extensions[i] = original[i];
0565: fExtensionTree.getComparator().sort(
0566: fExtensionTree, extensions);
0567: int index = getNewSelectionIndex(getArrayIndex(
0568: extensions, extension),
0569: extensions.length);
0570: if (index != -1)
0571: newSelection = new StructuredSelection(
0572: extensions[index]);
0573: }
0574: plugin.remove(extension);
0575: }
0576: if (newSelection != null)
0577: fExtensionTree.setSelection(newSelection);
0578: } catch (CoreException e) {
0579: PDEPlugin.logException(e);
0580: }
0581: }
0582: }
0583:
0584: private void handleNew() {
0585: final IProject project = getPage().getPDEEditor()
0586: .getCommonProject();
0587: BusyIndicator.showWhile(fExtensionTree.getTree().getDisplay(),
0588: new Runnable() {
0589: public void run() {
0590: ((ManifestEditor) getPage().getEditor())
0591: .ensurePluginContextPresence();
0592: NewExtensionWizard wizard = new NewExtensionWizard(
0593: project, (IPluginModelBase) getPage()
0594: .getModel(),
0595: (ManifestEditor) getPage()
0596: .getPDEEditor()) {
0597: public boolean performFinish() {
0598: return super .performFinish();
0599: }
0600: };
0601: WizardDialog dialog = new WizardDialog(
0602: PDEPlugin.getActiveWorkbenchShell(),
0603: wizard);
0604: dialog.create();
0605: SWTUtil.setDialogSize(dialog, 500, 500);
0606: dialog.open();
0607: }
0608: });
0609: }
0610:
0611: private void handleEdit(IConfigurationElement element,
0612: IStructuredSelection selection) {
0613: IProject project = getPage().getPDEEditor().getCommonProject();
0614: IPluginModelBase model = (IPluginModelBase) getPage()
0615: .getModel();
0616: try {
0617: final IExtensionEditorWizard wizard = (IExtensionEditorWizard) element
0618: .createExecutableExtension("class"); //$NON-NLS-1$
0619: wizard.init(project, model, selection);
0620: BusyIndicator.showWhile(fExtensionTree.getTree()
0621: .getDisplay(), new Runnable() {
0622: public void run() {
0623: WizardDialog dialog = new WizardDialog(PDEPlugin
0624: .getActiveWorkbenchShell(), wizard);
0625: dialog.create();
0626: SWTUtil.setDialogSize(dialog, 500, 500);
0627: dialog.open();
0628: }
0629: });
0630: } catch (CoreException e) {
0631: PDEPlugin.logException(e);
0632: }
0633: }
0634:
0635: private void handleEdit() {
0636: final IStructuredSelection selection = (IStructuredSelection) fExtensionTree
0637: .getSelection();
0638: ArrayList editorWizards = getEditorWizards(selection);
0639: if (editorWizards == null)
0640: return;
0641: if (editorWizards.size() == 1) {
0642: // open the wizard directly
0643: handleEdit((IConfigurationElement) editorWizards.get(0),
0644: selection);
0645: } else {
0646: IProject project = getPage().getPDEEditor()
0647: .getCommonProject();
0648: IPluginModelBase model = (IPluginModelBase) getPage()
0649: .getModel();
0650: final ExtensionEditorWizard wizard = new ExtensionEditorWizard(
0651: project, model, selection);
0652: BusyIndicator.showWhile(fExtensionTree.getTree()
0653: .getDisplay(), new Runnable() {
0654: public void run() {
0655: WizardDialog dialog = new WizardDialog(PDEPlugin
0656: .getActiveWorkbenchShell(), wizard);
0657: dialog.create();
0658: SWTUtil.setDialogSize(dialog, 500, 500);
0659: dialog.open();
0660: }
0661: });
0662: }
0663: }
0664:
0665: private ArrayList getEditorWizards(IStructuredSelection selection) {
0666: if (selection.size() != 1)
0667: return null;
0668: Object obj = selection.getFirstElement();
0669: String pointId = null;
0670: if (obj instanceof IPluginExtension) {
0671: pointId = ((IPluginExtension) obj).getPoint();
0672: } else if (obj instanceof IPluginElement) {
0673: IPluginObject parent = ((IPluginElement) obj).getParent();
0674: while (parent != null) {
0675: if (parent instanceof IPluginExtension) {
0676: pointId = ((IPluginExtension) parent).getPoint();
0677: break;
0678: }
0679: parent = parent.getParent();
0680: }
0681: }
0682: if (pointId == null)
0683: return null;
0684: if (fEditorWizards == null)
0685: loadExtensionWizards();
0686: return (ArrayList) fEditorWizards.get(pointId);
0687: }
0688:
0689: private void loadExtensionWizards() {
0690: fEditorWizards = new Hashtable();
0691: IConfigurationElement[] elements = Platform
0692: .getExtensionRegistry().getConfigurationElementsFor(
0693: "org.eclipse.pde.ui.newExtension"); //$NON-NLS-1$
0694: for (int i = 0; i < elements.length; i++) {
0695: IConfigurationElement element = elements[i];
0696: if (element.getName().equals("editorWizard")) { //$NON-NLS-1$
0697: String pointId = element.getAttribute("point"); //$NON-NLS-1$
0698: if (pointId == null)
0699: continue;
0700: ArrayList list = (ArrayList) fEditorWizards
0701: .get(pointId);
0702: if (list == null) {
0703: list = new ArrayList();
0704: fEditorWizards.put(pointId, list);
0705: }
0706: list.add(element);
0707: }
0708: }
0709: }
0710:
0711: private boolean isSelectionEditable(IStructuredSelection selection) {
0712: if (!getPage().getModel().isEditable())
0713: return false;
0714: return getEditorWizards(selection) != null;
0715: }
0716:
0717: public void initialize(IPluginModelBase model) {
0718: fExtensionTree.setInput(model.getPluginBase());
0719: selectFirstExtension();
0720: boolean editable = model.isEditable();
0721: TreePart treePart = getTreePart();
0722: treePart.setButtonEnabled(BUTTON_ADD, editable);
0723: treePart.setButtonEnabled(BUTTON_REMOVE, false);
0724: treePart.setButtonEnabled(BUTTON_EDIT, false);
0725: treePart.setButtonEnabled(BUTTON_MOVE_UP, false);
0726: treePart.setButtonEnabled(BUTTON_MOVE_DOWN, false);
0727: model.addModelChangedListener(this );
0728: }
0729:
0730: private void selectFirstExtension() {
0731: Tree tree = fExtensionTree.getTree();
0732: TreeItem[] items = tree.getItems();
0733: if (items.length == 0)
0734: return;
0735: TreeItem firstItem = items[0];
0736: Object obj = firstItem.getData();
0737: fExtensionTree.setSelection(new StructuredSelection(obj));
0738: }
0739:
0740: void fireSelection() {
0741: fExtensionTree.setSelection(fExtensionTree.getSelection());
0742: }
0743:
0744: public void initializeImages() {
0745: PDELabelProvider provider = PDEPlugin.getDefault()
0746: .getLabelProvider();
0747: fExtensionImage = provider
0748: .get(PDEPluginImages.DESC_EXTENSION_OBJ);
0749: fGenericElementImage = provider
0750: .get(PDEPluginImages.DESC_GENERIC_XML_OBJ);
0751: }
0752:
0753: public void refresh() {
0754: IPluginModelBase model = (IPluginModelBase) getPage()
0755: .getModel();
0756: fExtensionTree.setInput(model.getPluginBase());
0757: selectFirstExtension();
0758: getManagedForm().fireSelectionChanged(ExtensionsSection.this ,
0759: fExtensionTree.getSelection());
0760: super .refresh();
0761: }
0762:
0763: public void modelChanged(IModelChangedEvent event) {
0764: if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
0765: markStale();
0766: return;
0767: }
0768: Object changeObject = event.getChangedObjects()[0];
0769: if (changeObject instanceof IPluginBase
0770: && event.getChangeType() == IModelChangedEvent.CHANGE
0771: && event.getChangedProperty().equals(
0772: IExtensions.P_EXTENSION_ORDER)) {
0773: IStructuredSelection sel = (IStructuredSelection) fExtensionTree
0774: .getSelection();
0775: IPluginExtension extension = (IPluginExtension) sel
0776: .getFirstElement();
0777: fExtensionTree.refresh();
0778: fExtensionTree.setSelection(new StructuredSelection(
0779: extension));
0780: return;
0781: }
0782: if (changeObject instanceof IPluginExtension
0783: || (changeObject instanceof IPluginElement && ((IPluginElement) changeObject)
0784: .getParent() instanceof IPluginParent)) {
0785: IPluginObject pobj = (IPluginObject) changeObject;
0786: IPluginObject parent = changeObject instanceof IPluginExtension ? ((IPluginModelBase) getPage()
0787: .getModel()).getPluginBase()
0788: : pobj.getParent();
0789: if (event.getChangeType() == IModelChangedEvent.INSERT) {
0790: fExtensionTree.refresh(parent);
0791: fExtensionTree.setSelection(new StructuredSelection(
0792: changeObject), true);
0793: fExtensionTree.getTree().setFocus();
0794: } else if (event.getChangeType() == IModelChangedEvent.REMOVE) {
0795: fExtensionTree.remove(pobj);
0796: } else {
0797: if (event.getChangedProperty().equals(
0798: IPluginParent.P_SIBLING_ORDER)) {
0799: IStructuredSelection sel = (IStructuredSelection) fExtensionTree
0800: .getSelection();
0801: IPluginObject child = (IPluginObject) sel
0802: .getFirstElement();
0803: fExtensionTree.refresh(child.getParent());
0804: fExtensionTree
0805: .setSelection(new StructuredSelection(child));
0806: } else {
0807: fExtensionTree.update(changeObject, null);
0808: }
0809: }
0810: }
0811: }
0812:
0813: private Image resolveObjectImage(Object obj) {
0814: if (obj instanceof IPluginExtension) {
0815: return fExtensionImage;
0816: }
0817: Image elementImage = fGenericElementImage;
0818: if (obj instanceof IPluginElement) {
0819: IPluginElement element = (IPluginElement) obj;
0820: Image customImage = getCustomImage(element);
0821: if (customImage != null)
0822: elementImage = customImage;
0823: String bodyText = element.getText();
0824: boolean hasBodyText = bodyText != null
0825: && bodyText.length() > 0;
0826: if (hasBodyText) {
0827: elementImage = PDEPlugin.getDefault()
0828: .getLabelProvider().get(elementImage,
0829: SharedLabelProvider.F_EDIT);
0830: }
0831: }
0832: return elementImage;
0833: }
0834:
0835: private static boolean isStorageModel(IPluginObject object) {
0836: IPluginModelBase modelBase = object.getPluginModel();
0837: return modelBase.getInstallLocation() == null;
0838: }
0839:
0840: static Image getCustomImage(IPluginElement element) {
0841: if (isStorageModel(element))
0842: return null;
0843: ISchemaElement elementInfo = getSchemaElement(element);
0844: if (elementInfo != null
0845: && elementInfo.getIconProperty() != null) {
0846: String iconProperty = elementInfo.getIconProperty();
0847: IPluginAttribute att = element.getAttribute(iconProperty);
0848: String iconPath = null;
0849: if (att != null && att.getValue() != null) {
0850: iconPath = att.getValue();
0851: }
0852: // we have a value from a resource attribute
0853: if (iconPath != null) {
0854: String ext = new Path(iconPath).getFileExtension();
0855: // if the resource targets a folder, the file extension will be null
0856: if (ext == null)
0857: return null;
0858: boolean valid = false;
0859: // ensure the resource is an image
0860: for (int i = 0; i < VALID_IMAGE_TYPES.length; i++) {
0861: if (ext.equalsIgnoreCase(VALID_IMAGE_TYPES[i])) {
0862: valid = true;
0863: break;
0864: }
0865: }
0866: // if the resource is an image, get the image, otherwise return null
0867: return valid ? getImageFromPlugin(element, iconPath)
0868: : null;
0869: }
0870: }
0871: return null;
0872: }
0873:
0874: private static Image getImageFromPlugin(IPluginElement element,
0875: String iconPathName) {
0876: // 39283 - ignore icon paths that
0877: // point at plugin.properties
0878: if (iconPathName.startsWith("%")) //$NON-NLS-1$
0879: return null;
0880:
0881: IPluginModelBase model = element.getPluginModel();
0882: if (model == null)
0883: return null;
0884:
0885: return PDEPlugin.getDefault().getLabelProvider()
0886: .getImageFromPlugin(model, iconPathName);
0887: }
0888:
0889: private String resolveObjectName(Object obj) {
0890: return resolveObjectName(getSchemaRegistry(), obj);
0891: }
0892:
0893: private SchemaRegistry getSchemaRegistry() {
0894: if (fSchemaRegistry == null)
0895: fSchemaRegistry = PDECore.getDefault().getSchemaRegistry();
0896: return fSchemaRegistry;
0897: }
0898:
0899: public static String resolveObjectName(
0900: SchemaRegistry schemaRegistry, Object obj) {
0901: boolean fullNames = PDEPlugin.isFullNameModeEnabled();
0902: if (obj instanceof IPluginExtension) {
0903: IPluginExtension extension = (IPluginExtension) obj;
0904: if (!fullNames) {
0905: return extension.getPoint();
0906: }
0907: if (extension.getName() != null)
0908: return extension.getTranslatedName();
0909: ISchema schema = schemaRegistry.getSchema(extension
0910: .getPoint());
0911: // try extension point schema definition
0912: if (schema != null) {
0913: // exists
0914: return schema.getName();
0915: }
0916: return extension.getPoint();
0917: } else if (obj instanceof IPluginElement) {
0918: IPluginElement element = (IPluginElement) obj;
0919: String baseName = element.getName();
0920: String fullName = null;
0921: ISchemaElement elementInfo = getSchemaElement(element);
0922: IPluginAttribute labelAtt = null;
0923: if (elementInfo != null
0924: && elementInfo.getLabelProperty() != null) {
0925: labelAtt = element.getAttribute(elementInfo
0926: .getLabelProperty());
0927: }
0928: if (labelAtt == null) {
0929: // try some hard-coded attributes that
0930: // are used frequently
0931: for (int i = 0; i < COMMON_LABEL_PROPERTIES.length; i++) {
0932: labelAtt = element
0933: .getAttribute(COMMON_LABEL_PROPERTIES[i]);
0934: if (labelAtt != null)
0935: break;
0936: }
0937: if (labelAtt == null) {
0938: // Last try - if there is only one attribute,
0939: // use that
0940: if (element.getAttributeCount() == 1)
0941: labelAtt = element.getAttributes()[0];
0942: }
0943: }
0944: if (labelAtt != null && labelAtt.getValue() != null)
0945: fullName = stripShortcuts(labelAtt.getValue());
0946: fullName = element.getResourceString(fullName);
0947: if (fullNames)
0948: return fullName != null ? fullName : baseName;
0949: if (fullName == null)
0950: return baseName;
0951: // Bug 183417 - Bidi3.3: Elements' labels in the extensions page in the fragment manifest characters order is incorrect
0952: // add RTL zero length character just before the ( and the LTR character just after to ensure:
0953: // 1. The leading parenthesis takes proper orientation when running in bidi configuration
0954: // Assumption: baseName (taken from the schema definition), is only latin characters and is therefore always displayed LTR
0955: if (BidiUtil.isBidiPlatform())
0956: return fullName + " \u200f(\u200e" + baseName + ")"; //$NON-NLS-1$ //$NON-NLS-2$
0957: return fullName + " (" + baseName + ')'; //$NON-NLS-1$
0958: }
0959: return obj.toString();
0960: }
0961:
0962: public void setFocus() {
0963: if (fExtensionTree != null)
0964: fExtensionTree.getTree().setFocus();
0965: }
0966:
0967: public static String stripShortcuts(String input) {
0968: StringBuffer output = new StringBuffer();
0969: for (int i = 0; i < input.length(); i++) {
0970: char c = input.charAt(i);
0971: if (c == '&')
0972: continue;
0973: else if (c == '@')
0974: break;
0975: output.append(c);
0976: }
0977: return output.toString();
0978: }
0979:
0980: /* (non-Javadoc)
0981: * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#canPaste(java.lang.Object, java.lang.Object[])
0982: */
0983: protected boolean canPaste(Object targetObject,
0984: Object[] sourceObjects) {
0985: // Note: Multi-select in tree viewer is disabled; but, this function
0986: // can support multiple source objects
0987: // Rule: Element source objects are always pasted as children of the
0988: // target object (if allowable)
0989: // Rule: Extension source objects are always pasted and are independent
0990: // of the target object
0991: // Ensure all the sourceObjects are either extensions or elements
0992: boolean allExtensions = true;
0993: boolean allElements = true;
0994: for (int i = 0; i < sourceObjects.length; i++) {
0995: if (sourceObjects[i] instanceof IPluginExtension) {
0996: allElements = false;
0997: } else if (sourceObjects[i] instanceof IPluginElement) {
0998: allExtensions = false;
0999: } else {
1000: return false;
1001: }
1002: }
1003: // Because of the extension rule, we can paste all extension source
1004: // objects
1005: if (allExtensions) {
1006: return true;
1007: }
1008: // Pasting a mixture of elements and extensions is not supported
1009: // (or wise from the users perspective)
1010: if (allElements == false) {
1011: return false;
1012: }
1013: // Ensure the target object can have children
1014: if ((targetObject instanceof IPluginParent) == false) {
1015: return false;
1016: } else if ((targetObject instanceof IDocumentElementNode) == false) {
1017: return false;
1018: }
1019: // Retrieve the schema corresponding to the target object
1020: IPluginParent targetParent = (IPluginParent) targetObject;
1021: ISchema schema = getSchema(targetParent);
1022: // If there is no schema, then a source object can be pasted as a
1023: // child of any target object
1024: if (schema == null) {
1025: return true;
1026: }
1027: // Determine the element name of the target object
1028: String tagName = ((IDocumentElementNode) targetParent)
1029: .getXMLTagName();
1030: // Retrieve the element schema for the target object
1031: ISchemaElement schemaElement = schema.findElement(tagName);
1032: // Ensure we found a schema element and it is a schema complex type
1033: if (schemaElement == null) {
1034: // Something is seriously wrong, we have a schema
1035: return false;
1036: } else if ((schemaElement.getType() instanceof ISchemaComplexType) == false) {
1037: // Something is seriously wrong, we are a plugin parent
1038: return false;
1039: }
1040: // We have a schema complex type. Either the target object has
1041: // attributes or the element has children.
1042: // Generate the list of element proposals
1043: TreeSet elementSet = XMLElementProposalComputer
1044: .computeElementProposal(schemaElement,
1045: (IDocumentElementNode) targetObject);
1046: // Determine whether we can paste the source elements as children of
1047: // the target object
1048: if (sourceObjects.length > 1) {
1049: return canPasteSourceElements(
1050: (IPluginElement[]) sourceObjects, elementSet);
1051: }
1052: return canPasteSourceElement((IPluginElement) sourceObjects[0],
1053: elementSet);
1054: }
1055:
1056: /**
1057: * @param sourceElements
1058: * @param targetElementSet
1059: * @return
1060: */
1061: private boolean canPasteSourceElements(
1062: IPluginElement[] sourceElements, TreeSet targetElementSet) {
1063: // Performance optimization
1064: // HashSet of schema elements is not comparable for the source
1065: // objects (schema elements are transient)
1066: // Create a new HashSet with element names for comparison
1067: HashSet targetElementNameSet = new HashSet();
1068: Iterator iterator = targetElementSet.iterator();
1069: while (iterator.hasNext()) {
1070: targetElementNameSet.add(((ISchemaElement) iterator.next())
1071: .getName());
1072: }
1073: // Paste will be enabled only if all source objects can be pasted
1074: // as children into the target element
1075: // Limitation: Multiplicity checks will be compromised because we
1076: // are pasting multiple elements as a single transaction. The
1077: // mulitplicity check is computed on the current static state of the
1078: // target object with the assumption one new element will be added.
1079: // Obviously, adding more than one element can invalidate the check
1080: // due to choice, sequence multiplicity constraints. Even if source
1081: // elements that are pasted violate multiplicity constraints the
1082: // extensions builder will flag them with errors
1083: for (int i = 0; i < sourceElements.length; i++) {
1084: String sourceTagName = sourceElements[i].getName();
1085: if (targetElementNameSet.contains(sourceTagName) == false) {
1086: return false;
1087: }
1088: }
1089: return true;
1090: }
1091:
1092: /**
1093: * @param sourceElement
1094: * @param targetElementSet
1095: * @return
1096: */
1097: private boolean canPasteSourceElement(IPluginElement sourceElement,
1098: TreeSet targetElementSet) {
1099: boolean canPaste = false;
1100: // Get the source element tag name
1101: String sourceTagName = sourceElement.getName();
1102: // Iterate over set of valid element proposals
1103: Iterator iterator = targetElementSet.iterator();
1104: while (iterator.hasNext()) {
1105: // Get the proposal element tag name
1106: String targetTagName = ((ISchemaElement) iterator.next())
1107: .getName();
1108: // Only a source element that is found ithin the set of element
1109: // proposals can be pasted
1110: if (sourceTagName.equals(targetTagName)) {
1111: canPaste = true;
1112: break;
1113: }
1114: }
1115: return canPaste;
1116: }
1117:
1118: /**
1119: * @return
1120: */
1121: private IPluginModelBase getPluginModelBase() {
1122: // Note: This method will work with fragments as long as a fragment.xml
1123: // is defined first. Otherwise, paste will not work out of the box.
1124: // Get the model
1125: IPluginModelBase model = (IPluginModelBase) getPage()
1126: .getModel();
1127: // Ensure the model is a bundle plugin model
1128: if ((model instanceof IBundlePluginModelBase) == false) {
1129: return null;
1130: }
1131: // Get the extension model
1132: ISharedExtensionsModel extensionModel = ((IBundlePluginModelBase) model)
1133: .getExtensionsModel();
1134: // Ensure the extension model is defined
1135: if ((extensionModel == null)
1136: || ((extensionModel instanceof IPluginModelBase) == false)) {
1137: return null;
1138: }
1139: return ((IPluginModelBase) extensionModel);
1140: }
1141:
1142: /* (non-Javadoc)
1143: * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#doPaste(java.lang.Object, java.lang.Object[])
1144: */
1145: protected void doPaste(Object targetObject, Object[] sourceObjects) {
1146: // By default, fragment.xml does not exist until the first extension
1147: // or extension point is created.
1148: // Ensure the file exists before pasting because the model will be
1149: // null and the paste will fail if it does not exist
1150: ((ManifestEditor) getPage().getEditor())
1151: .ensurePluginContextPresence();
1152: // Note: Multi-select in tree viewer is disabled; but, this function
1153: // can support multiple source objects
1154: // Get the model
1155: IPluginModelBase model = getPluginModelBase();
1156: // Ensure the model is defined
1157: if (model == null) {
1158: return;
1159: }
1160: IPluginBase pluginBase = model.getPluginBase();
1161: try {
1162: // Paste all source objects into the target object
1163: for (int i = 0; i < sourceObjects.length; i++) {
1164: Object sourceObject = sourceObjects[i];
1165:
1166: if ((sourceObject instanceof IPluginExtension)
1167: && (pluginBase instanceof IDocumentElementNode)) {
1168: // Extension object
1169: IDocumentElementNode extension = (IDocumentElementNode) sourceObject;
1170: // Adjust all the source object transient field values to
1171: // acceptable values
1172: extension.reconnect(
1173: (IDocumentElementNode) pluginBase, model);
1174: // Add the extension to the plugin parent (plugin)
1175: pluginBase.add((IPluginExtension) extension);
1176:
1177: } else if ((sourceObject instanceof IPluginElement)
1178: && (targetObject instanceof IPluginParent)
1179: && (targetObject instanceof IDocumentElementNode)) {
1180: // Element object
1181: IDocumentElementNode element = (IDocumentElementNode) sourceObject;
1182: // Adjust all the source object transient field values to
1183: // acceptable values
1184: element.reconnect(
1185: (IDocumentElementNode) targetObject, model);
1186: // Add the element to the plugin parent (extension or
1187: // element)
1188: ((IPluginParent) targetObject)
1189: .add((IPluginElement) element);
1190: }
1191: }
1192: } catch (CoreException e) {
1193: PDEPlugin.logException(e);
1194: }
1195: }
1196:
1197: private void handleMove(boolean up) {
1198: IStructuredSelection sel = (IStructuredSelection) fExtensionTree
1199: .getSelection();
1200: IPluginObject object = (IPluginObject) sel.getFirstElement();
1201: if (object instanceof IPluginElement) {
1202: IPluginParent parent = (IPluginParent) object.getParent();
1203: IPluginObject[] children = parent.getChildren();
1204: int index = parent.getIndexOf(object);
1205: int newIndex = up ? index - 1 : index + 1;
1206: IPluginObject child2 = children[newIndex];
1207: try {
1208: parent.swap(object, child2);
1209: } catch (CoreException e) {
1210: PDEPlugin.logException(e);
1211: }
1212: } else if (object instanceof IPluginExtension) {
1213: IPluginExtension extension = (IPluginExtension) object;
1214: IPluginBase plugin = extension.getPluginBase();
1215: IPluginExtension[] extensions = plugin.getExtensions();
1216: int index = plugin.getIndexOf(extension);
1217: int newIndex = up ? index - 1 : index + 1;
1218: IPluginExtension e2 = extensions[newIndex];
1219: try {
1220: plugin.swap(extension, e2);
1221: } catch (CoreException e) {
1222: PDEPlugin.logException(e);
1223: }
1224: }
1225: }
1226:
1227: private void updateButtons(Object item) {
1228: if (getPage().getModel().isEditable() == false)
1229: return;
1230: boolean sorted = fSortAction != null && fSortAction.isChecked();
1231: if (sorted) {
1232: getTreePart().setButtonEnabled(BUTTON_MOVE_UP, false);
1233: getTreePart().setButtonEnabled(BUTTON_MOVE_DOWN, false);
1234: return;
1235: }
1236:
1237: boolean filtered = fFilteredTree.isFiltered();
1238: boolean addEnabled = true;
1239: boolean removeEnabled = false;
1240: boolean upEnabled = false;
1241: boolean downEnabled = false;
1242:
1243: if (item != null) {
1244: removeEnabled = true;
1245: }
1246: if (filtered) {
1247: // Fix for bug 194529 and bug 194828
1248: addEnabled = false;
1249: upEnabled = false;
1250: downEnabled = false;
1251: } else {
1252: if (item instanceof IPluginElement) {
1253: IPluginElement element = (IPluginElement) item;
1254: IPluginParent parent = (IPluginParent) element
1255: .getParent();
1256: // check up
1257: int index = parent.getIndexOf(element);
1258: if (index > 0)
1259: upEnabled = true;
1260: if (index < parent.getChildCount() - 1)
1261: downEnabled = true;
1262: } else if (item instanceof IPluginExtension) {
1263: IPluginExtension extension = (IPluginExtension) item;
1264: IExtensions extensions = (IExtensions) extension
1265: .getParent();
1266: int index = extensions.getIndexOf(extension);
1267: int size = extensions.getExtensions().length;
1268: if (index > 0)
1269: upEnabled = true;
1270: if (index < size - 1)
1271: downEnabled = true;
1272: }
1273: }
1274: getTreePart().setButtonEnabled(BUTTON_ADD, addEnabled);
1275: getTreePart().setButtonEnabled(BUTTON_REMOVE, removeEnabled);
1276: getTreePart().setButtonEnabled(BUTTON_MOVE_UP, upEnabled);
1277: getTreePart().setButtonEnabled(BUTTON_MOVE_DOWN, downEnabled);
1278: }
1279:
1280: /* (non-Javadoc)
1281: * @see org.eclipse.pde.internal.ui.editor.TreeSection#createTreeViewer(org.eclipse.swt.widgets.Composite, int)
1282: */
1283: protected TreeViewer createTreeViewer(Composite parent, int style) {
1284: fFilteredTree = new FormFilteredTree(parent, style,
1285: new PatternFilter());
1286: parent.setData("filtered", Boolean.TRUE); //$NON-NLS-1$
1287: return fFilteredTree.getViewer();
1288: }
1289:
1290: public void propertyChange(PropertyChangeEvent event) {
1291: if (fSortAction.equals(event.getSource())
1292: && IAction.RESULT.equals(event.getProperty())) {
1293: StructuredViewer viewer = getStructuredViewerPart()
1294: .getViewer();
1295: IStructuredSelection ssel = (IStructuredSelection) viewer
1296: .getSelection();
1297: updateButtons(ssel.size() != 1 ? null : ssel
1298: .getFirstElement());
1299: }
1300: }
1301:
1302: protected void selectExtensionElement(ISelection selection) {
1303: fExtensionTree.setSelection(selection, true);
1304: }
1305:
1306: /* (non-Javadoc)
1307: * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#isDragAndDropEnabled()
1308: */
1309: protected boolean isDragAndDropEnabled() {
1310: return true;
1311: }
1312:
1313: /* (non-Javadoc)
1314: * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#canDragMove(java.lang.Object[])
1315: */
1316: public boolean canDragMove(Object[] sourceObjects) {
1317: // Validate source objects
1318: if (validateDragMoveSanity(sourceObjects) == false) {
1319: return false;
1320: } else if (fFilteredTree.isFiltered()) {
1321: return false;
1322: } else if (isTreeViewerSorted()) {
1323: return false;
1324: }
1325: return true;
1326: }
1327:
1328: /**
1329: * @param targetObject
1330: * @param sourceObjects
1331: * @return
1332: */
1333: private boolean validateDropMoveSanity(Object targetObject,
1334: Object[] sourceObjects) {
1335: // Validate target object
1336: if ((targetObject instanceof IPluginParent) == false) {
1337: return false;
1338: } else if ((targetObject instanceof IDocumentElementNode) == false) {
1339: return false;
1340: }
1341: // Validate source objects
1342: if (validateDragMoveSanity(sourceObjects) == false) {
1343: return false;
1344: }
1345: return true;
1346: }
1347:
1348: /**
1349: * @param sourceObjects
1350: * @return
1351: */
1352: private boolean validateDragMoveSanity(Object[] sourceObjects) {
1353: // Validate source
1354: if (sourceObjects == null) {
1355: // No objects
1356: return false;
1357: } else if (sourceObjects.length != 1) {
1358: // Multiple selection not supported
1359: return false;
1360: } else if ((sourceObjects[0] instanceof IDocumentElementNode) == false) {
1361: // Must be the right type
1362: return false;
1363: } else if ((sourceObjects[0] instanceof IPluginParent) == false) {
1364: // Must be the right type
1365: return false;
1366: }
1367: return true;
1368: }
1369:
1370: /**
1371: * @param sourcePluginObject
1372: * @param targetPluginObject
1373: * @return
1374: */
1375: private boolean validateDropMoveModel(
1376: IPluginParent sourcePluginObject,
1377: IPluginParent targetPluginObject) {
1378: // Objects have to be from the same model
1379: ISharedPluginModel sourceModel = sourcePluginObject.getModel();
1380: ISharedPluginModel targetModel = targetPluginObject.getModel();
1381: if (sourceModel.equals(targetModel)) {
1382: return true;
1383: }
1384: return false;
1385: }
1386:
1387: /* (non-Javadoc)
1388: * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#canDropMove(java.lang.Object, java.lang.Object[], int)
1389: */
1390: public boolean canDropMove(Object targetObject,
1391: Object[] sourceObjects, int targetLocation) {
1392: // Sanity check
1393: if (validateDropMoveSanity(targetObject, sourceObjects) == false) {
1394: return false;
1395: }
1396: // Multiple selection not supported
1397: IPluginParent sourcePluginObject = (IPluginParent) sourceObjects[0];
1398: IPluginParent targetPluginObject = (IPluginParent) targetObject;
1399: // Validate model
1400: if (validateDropMoveModel(sourcePluginObject,
1401: targetPluginObject) == false) {
1402: return false;
1403: }
1404: // Validate move
1405: if (sourcePluginObject instanceof IPluginExtension) {
1406: IPluginExtension sourceExtensionObject = (IPluginExtension) sourcePluginObject;
1407: if (targetPluginObject instanceof IPluginExtension) {
1408: // Source: Extension
1409: // Target: Extension
1410: IPluginExtension targetExtensionObject = (IPluginExtension) targetPluginObject;
1411: return canDropMove(targetExtensionObject,
1412: sourceExtensionObject, targetLocation);
1413: } else if (targetPluginObject instanceof IPluginElement) {
1414: // Source: Extension
1415: // Target: Element
1416: return false;
1417: }
1418: } else if (sourcePluginObject instanceof IPluginElement) {
1419: IPluginElement sourceElementObject = (IPluginElement) sourcePluginObject;
1420: if (targetPluginObject instanceof IPluginExtension) {
1421: // Source: Element
1422: // Target: Extension
1423: IPluginExtension targetExtensionObject = (IPluginExtension) targetPluginObject;
1424: return canDropMove(targetExtensionObject,
1425: sourceElementObject, targetLocation);
1426: } else if (targetPluginObject instanceof IPluginElement) {
1427: // Source: Element
1428: // Target: Element
1429: IPluginElement targetElementObject = (IPluginElement) targetPluginObject;
1430: return canDropMove(targetElementObject,
1431: sourceElementObject, targetLocation);
1432: }
1433: }
1434: return false;
1435: }
1436:
1437: /**
1438: * @param targetElementObject
1439: * @param sourceElementObject
1440: * @param targetLocation
1441: * @return
1442: */
1443: private boolean canDropMove(IPluginElement targetElementObject,
1444: IPluginElement sourceElementObject, int targetLocation) {
1445:
1446: // Verify that the source is not the parent of the target
1447: if (validateDropMoveParent(targetElementObject,
1448: sourceElementObject) == false) {
1449: return false;
1450: }
1451:
1452: if (targetLocation == ViewerDropAdapter.LOCATION_BEFORE) {
1453: IDocumentElementNode previousNode = ((IDocumentElementNode) targetElementObject)
1454: .getPreviousSibling();
1455: if (sourceElementObject.equals(previousNode)) {
1456: return false;
1457: }
1458: IPluginObject targetParentObject = targetElementObject
1459: .getParent();
1460: if ((targetParentObject instanceof IPluginParent) == false) {
1461: return false;
1462: }
1463: // Paste element as a sibling of the other element (before)
1464: return validateDropMoveSchema(
1465: (IPluginParent) targetParentObject,
1466: sourceElementObject);
1467: } else if (targetLocation == ViewerDropAdapter.LOCATION_AFTER) {
1468: IDocumentElementNode nextNode = ((IDocumentElementNode) sourceElementObject)
1469: .getPreviousSibling();
1470: if (targetElementObject.equals(nextNode)) {
1471: return false;
1472: }
1473: IPluginObject targetParentObject = targetElementObject
1474: .getParent();
1475: if ((targetParentObject instanceof IPluginParent) == false) {
1476: return false;
1477: }
1478: // Paste element as a sibling of the other element (after)
1479: return validateDropMoveSchema(
1480: (IPluginParent) targetParentObject,
1481: sourceElementObject);
1482: } else if (targetLocation == ViewerDropAdapter.LOCATION_ON) {
1483: IDocumentElementNode targetExtensionNode = (IDocumentElementNode) targetElementObject;
1484: int childCount = targetExtensionNode.getChildCount();
1485: if (childCount != 0) {
1486: IDocumentElementNode lastNode = targetExtensionNode
1487: .getChildAt(childCount - 1);
1488: if (sourceElementObject.equals(lastNode)) {
1489: return false;
1490: }
1491: }
1492: // Paste element as the last child of the element
1493: return validateDropMoveSchema(targetElementObject,
1494: sourceElementObject);
1495: }
1496: return false;
1497: }
1498:
1499: /**
1500: * @param targetElementObject
1501: * @param sourceElementObject
1502: * @return
1503: */
1504: private boolean validateDropMoveParent(
1505: IPluginElement targetElementObject,
1506: IPluginElement sourceElementObject) {
1507:
1508: IPluginObject currentParent = targetElementObject.getParent();
1509: while (true) {
1510: if (currentParent == null) {
1511: return true;
1512: } else if ((currentParent instanceof IPluginElement) == false) {
1513: return true;
1514: } else if (sourceElementObject.equals(currentParent)) {
1515: return false;
1516: }
1517: currentParent = currentParent.getParent();
1518: }
1519: }
1520:
1521: /**
1522: * @param targetExtensionObject
1523: * @param sourceElementObject
1524: * @param targetLocation
1525: * @return
1526: */
1527: private boolean canDropMove(IPluginExtension targetExtensionObject,
1528: IPluginElement sourceElementObject, int targetLocation) {
1529:
1530: if (targetLocation == ViewerDropAdapter.LOCATION_BEFORE) {
1531: return false;
1532: } else if (targetLocation == ViewerDropAdapter.LOCATION_AFTER) {
1533: return false;
1534: } else if (targetLocation == ViewerDropAdapter.LOCATION_ON) {
1535: IDocumentElementNode targetExtensionNode = (IDocumentElementNode) targetExtensionObject;
1536: int childCount = targetExtensionNode.getChildCount();
1537: if (childCount != 0) {
1538: IDocumentElementNode lastNode = targetExtensionNode
1539: .getChildAt(childCount - 1);
1540: if (sourceElementObject.equals(lastNode)) {
1541: return false;
1542: }
1543: }
1544: // Paste element as the last child of the extension
1545: return validateDropMoveSchema(targetExtensionObject,
1546: sourceElementObject);
1547: }
1548: return false;
1549: }
1550:
1551: /**
1552: * @param targetPluginObject
1553: * @param sourcePluginObject
1554: * @return
1555: */
1556: private boolean validateDropMoveSchema(
1557: IPluginParent targetPluginObject,
1558: IPluginParent sourcePluginObject) {
1559: IDocumentElementNode targetPluginNode = (IDocumentElementNode) targetPluginObject;
1560: // If the target is the source's parent, then the move is always
1561: // valid. No need to check the schema. Order does not matter
1562: if (targetPluginObject.equals(sourcePluginObject.getParent())) {
1563: return true;
1564: }
1565: // Retrieve the schema corresponding to the target object
1566: ISchema schema = getSchema(targetPluginObject);
1567: // If there is no schema, then a source object can be pasted as a
1568: // child of any target object
1569: if (schema == null) {
1570: return true;
1571: }
1572: // Determine the element name of the target object
1573: String targetNodeTagName = targetPluginNode.getXMLTagName();
1574: // Retrieve the element schema for the target object
1575: ISchemaElement schemaElement = schema
1576: .findElement(targetNodeTagName);
1577: // Ensure we found a schema element and it is a schema complex type
1578: if (schemaElement == null) {
1579: // Something is seriously wrong, we have a schema
1580: return false;
1581: } else if ((schemaElement.getType() instanceof ISchemaComplexType) == false) {
1582: // Something is seriously wrong, we are a plugin parent
1583: return false;
1584: }
1585: // We have a schema complex type. Either the target object has
1586: // attributes or the element has children.
1587: // Generate the list of element proposals
1588: TreeSet elementSet = XMLElementProposalComputer
1589: .computeElementProposal(schemaElement, targetPluginNode);
1590: // Iterate over set of valid element proposals
1591: Iterator iterator = elementSet.iterator();
1592: while (iterator.hasNext()) {
1593: // Get the proposal element tag name
1594: String targetTagName = ((ISchemaElement) iterator.next())
1595: .getName();
1596: // Only a source element that is found ithin the set of element
1597: // proposals can be pasted
1598: String sourceNodeTagName = ((IDocumentElementNode) sourcePluginObject)
1599: .getXMLTagName();
1600: if (sourceNodeTagName.equals(targetTagName)) {
1601: return true;
1602: }
1603: }
1604: return false;
1605: }
1606:
1607: /**
1608: * @param targetExtensionObject
1609: * @param sourceExtensionObject
1610: * @param targetLocation
1611: * @return
1612: */
1613: private boolean canDropMove(IPluginExtension targetExtensionObject,
1614: IPluginExtension sourceExtensionObject, int targetLocation) {
1615:
1616: if (targetLocation == ViewerDropAdapter.LOCATION_BEFORE) {
1617: IDocumentElementNode previousNode = ((IDocumentElementNode) targetExtensionObject)
1618: .getPreviousSibling();
1619: if (sourceExtensionObject.equals(previousNode)) {
1620: return false;
1621: }
1622: // Paste extension as sibling of extension (before)
1623: return true;
1624: } else if (targetLocation == ViewerDropAdapter.LOCATION_AFTER) {
1625: IDocumentElementNode nextNode = ((IDocumentElementNode) sourceExtensionObject)
1626: .getPreviousSibling();
1627: if (targetExtensionObject.equals(nextNode)) {
1628: return false;
1629: }
1630: // Paste extension as sibling of extension (after)
1631: return true;
1632: } else if (targetLocation == ViewerDropAdapter.LOCATION_ON) {
1633: return false;
1634: }
1635: return false;
1636: }
1637:
1638: /* (non-Javadoc)
1639: * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#doDragRemove(java.lang.Object[])
1640: */
1641: public void doDragRemove(Object[] sourceObjects) {
1642: // Validate source objects
1643: if (validateDragMoveSanity(sourceObjects) == false) {
1644: return;
1645: }
1646: IPluginParent pluginParentObject = (IPluginParent) sourceObjects[0];
1647: // Remove the object from the model
1648: try {
1649: if (pluginParentObject instanceof IPluginExtension) {
1650: IPluginExtension extension = (IPluginExtension) pluginParentObject;
1651: IPluginBase pluginBase = pluginParentObject
1652: .getPluginBase();
1653: if (pluginBase != null) {
1654: pluginBase.remove(extension);
1655: }
1656: } else if (pluginParentObject instanceof IPluginElement) {
1657: IPluginElement element = (IPluginElement) pluginParentObject;
1658: IPluginObject object = element.getParent();
1659: if (object instanceof IPluginParent) {
1660: ((IPluginParent) object).remove(element);
1661: }
1662: }
1663: // Applicable for move operations
1664: // Flush the text edit operations associated with the move operation
1665: // to the source page
1666: // Move involves add new cloned object x and remove of original object
1667: // x
1668: // Without flushing, multiple move operations up and down cause the
1669: // text edit operations to get completely screwed up (e.g. mark-up
1670: // in wrong position or getting lost)
1671: // TODO: MP: Undo: What are the implications of this?
1672: ((PDEFormEditor) getPage().getEditor()).getContextManager()
1673: .getPrimaryContext().flushEditorInput();
1674: } catch (CoreException e) {
1675: PDEPlugin.logException(e);
1676: }
1677: }
1678:
1679: /* (non-Javadoc)
1680: * @see org.eclipse.pde.internal.ui.editor.StructuredViewerSection#doDropMove(java.lang.Object, java.lang.Object[], int)
1681: */
1682: public void doDropMove(Object targetObject, Object[] sourceObjects,
1683: int targetLocation) {
1684: // Sanity check
1685: if (validateDropMoveSanity(targetObject, sourceObjects) == false) {
1686: Display.getDefault().beep();
1687: return;
1688: }
1689: // Multiple selection not supported
1690: IPluginParent sourcePluginObject = (IPluginParent) sourceObjects[0];
1691: IPluginParent targetPluginObject = (IPluginParent) targetObject;
1692: // Validate move
1693: try {
1694: if (sourcePluginObject instanceof IPluginExtension) {
1695: IPluginExtension sourceExtensionObject = (IPluginExtension) sourcePluginObject;
1696: if (targetPluginObject instanceof IPluginExtension) {
1697: // Source: Extension
1698: // Target: Extension
1699: IPluginExtension targetExtensionObject = (IPluginExtension) targetPluginObject;
1700: doDropMove(targetExtensionObject,
1701: sourceExtensionObject, targetLocation);
1702: } else if (targetPluginObject instanceof IPluginElement) {
1703: // Source: Extension
1704: // Target: Element
1705: return;
1706: }
1707: } else if (sourcePluginObject instanceof IPluginElement) {
1708: IPluginElement sourceElementObject = (IPluginElement) sourcePluginObject;
1709: if (targetPluginObject instanceof IPluginExtension) {
1710: // Source: Element
1711: // Target: Extension
1712: IPluginExtension targetExtensionObject = (IPluginExtension) targetPluginObject;
1713: doDropMove(targetExtensionObject,
1714: sourceElementObject, targetLocation);
1715: } else if (targetPluginObject instanceof IPluginElement) {
1716: // Source: Element
1717: // Target: Element
1718: IPluginElement targetElementObject = (IPluginElement) targetPluginObject;
1719: doDropMove(targetElementObject,
1720: sourceElementObject, targetLocation);
1721: }
1722: }
1723: } catch (CoreException e) {
1724: PDEPlugin.logException(e);
1725: }
1726: }
1727:
1728: /**
1729: * @param targetExtensionObject
1730: * @param sourceExtensionObject
1731: * @param targetLocation
1732: */
1733: private void doDropMove(IPluginExtension targetExtensionObject,
1734: IPluginExtension sourceExtensionObject, int targetLocation)
1735: throws CoreException {
1736: // Get the model
1737: IPluginModelBase model = getPluginModelBase();
1738: // Ensure the model is defined
1739: if (model == null) {
1740: return;
1741: }
1742: // Get the plugin base
1743: IPluginBase pluginBase = model.getPluginBase();
1744: // Ensure the plugin base is a document node
1745: if ((pluginBase instanceof IDocumentElementNode) == false) {
1746: return;
1747: } else if ((pluginBase instanceof PluginBaseNode) == false) {
1748: return;
1749: }
1750: // Plug-in base node
1751: IDocumentElementNode pluginBaseNode = (IDocumentElementNode) pluginBase;
1752: // Source extension node
1753: IDocumentElementNode sourceExtensionNode = (IDocumentElementNode) sourceExtensionObject;
1754: // Target extension node
1755: IDocumentElementNode targetExtensionNode = (IDocumentElementNode) targetExtensionObject;
1756: // Do drop move
1757: if (targetLocation == ViewerDropAdapter.LOCATION_BEFORE) {
1758: // Adjust all the source object transient field values to
1759: // acceptable values
1760: sourceExtensionNode.reconnect(pluginBaseNode, model);
1761: // Get index of target extension
1762: int index = (pluginBaseNode.indexOf(targetExtensionNode));
1763: // Ensure the target index was found
1764: if (index == -1) {
1765: return;
1766: }
1767: // Paste extension as sibling of extension (before)
1768: ((PluginBaseNode) pluginBaseNode).add(
1769: sourceExtensionObject, index);
1770: } else if (targetLocation == ViewerDropAdapter.LOCATION_AFTER) {
1771: // Adjust all the source object transient field values to
1772: // acceptable values
1773: sourceExtensionNode.reconnect(pluginBaseNode, model);
1774: // Get index of target extension
1775: int index = (pluginBaseNode.indexOf(targetExtensionNode));
1776: // Ensure the target index was found
1777: if (index == -1) {
1778: return;
1779: }
1780: // Paste extension as sibling of extension (after)
1781: ((PluginBaseNode) pluginBaseNode).add(
1782: sourceExtensionObject, index + 1);
1783: } else if (targetLocation == ViewerDropAdapter.LOCATION_ON) {
1784: // NO-OP
1785: }
1786: }
1787:
1788: /**
1789: * @param targetExtensionObject
1790: * @param sourceElementObject
1791: * @param targetLocation
1792: */
1793: private void doDropMove(IPluginExtension targetExtensionObject,
1794: IPluginElement sourceElementObject, int targetLocation)
1795: throws CoreException {
1796: // Get the model
1797: IPluginModelBase model = getPluginModelBase();
1798: // Ensure the model is defined
1799: if (model == null) {
1800: return;
1801: }
1802: // Target extension node
1803: IDocumentElementNode targetExtensionNode = (IDocumentElementNode) targetExtensionObject;
1804: // Source extension node
1805: IDocumentElementNode sourceElementNode = (IDocumentElementNode) sourceElementObject;
1806: // Do drop move
1807: if (targetLocation == ViewerDropAdapter.LOCATION_BEFORE) {
1808: // NO-OP
1809: } else if (targetLocation == ViewerDropAdapter.LOCATION_AFTER) {
1810: // NO-OP
1811: } else if (targetLocation == ViewerDropAdapter.LOCATION_ON) {
1812: // Adjust all the source object transient field values to
1813: // acceptable values
1814: sourceElementNode.reconnect(targetExtensionNode, model);
1815: // Paste element as the last child of the extension
1816: targetExtensionObject.add(sourceElementObject);
1817: }
1818: }
1819:
1820: /**
1821: * @param targetElementObject
1822: * @param sourceElementObject
1823: * @param targetLocation
1824: */
1825: private void doDropMove(IPluginElement targetElementObject,
1826: IPluginElement sourceElementObject, int targetLocation)
1827: throws CoreException {
1828: // Get the model
1829: IPluginModelBase model = getPluginModelBase();
1830: // Ensure the model is defined
1831: if (model == null) {
1832: return;
1833: }
1834: // Target extension node
1835: IDocumentElementNode targetElementNode = (IDocumentElementNode) targetElementObject;
1836: // Source extension node
1837: IDocumentElementNode sourceElementNode = (IDocumentElementNode) sourceElementObject;
1838: // Do drop move
1839: if (targetLocation == ViewerDropAdapter.LOCATION_BEFORE) {
1840: // Get the target's parent
1841: IPluginObject targetParentObject = targetElementObject
1842: .getParent();
1843: if ((targetParentObject instanceof IPluginParent) == false) {
1844: return;
1845: } else if ((targetParentObject instanceof IDocumentElementNode) == false) {
1846: return;
1847: }
1848: IDocumentElementNode targetParentNode = (IDocumentElementNode) targetParentObject;
1849: // Adjust all the source object transient field values to
1850: // acceptable values
1851: sourceElementNode.reconnect(targetParentNode, model);
1852: // Get index of target element
1853: int index = (targetParentNode.indexOf(targetElementNode));
1854: // Ensure the target index was found
1855: if (index == -1) {
1856: return;
1857: }
1858: // Paste element as a sibling of the other element (before)
1859: ((IPluginParent) targetParentObject).add(index,
1860: sourceElementObject);
1861: } else if (targetLocation == ViewerDropAdapter.LOCATION_AFTER) {
1862: // Get the target's parent
1863: IPluginObject targetParentObject = targetElementObject
1864: .getParent();
1865: if ((targetParentObject instanceof IPluginParent) == false) {
1866: return;
1867: } else if ((targetParentObject instanceof IDocumentElementNode) == false) {
1868: return;
1869: }
1870: IDocumentElementNode targetParentNode = (IDocumentElementNode) targetParentObject;
1871: // Adjust all the source object transient field values to
1872: // acceptable values
1873: sourceElementNode.reconnect(targetParentNode, model);
1874: // Get index of target element
1875: int index = (targetParentNode.indexOf(targetElementNode));
1876: // Ensure the target index was found
1877: if (index == -1) {
1878: return;
1879: }
1880: // Paste element as a sibling of the other element (after)
1881: ((IPluginParent) targetParentObject).add(index + 1,
1882: sourceElementObject);
1883: } else if (targetLocation == ViewerDropAdapter.LOCATION_ON) {
1884: // Adjust all the source object transient field values to
1885: // acceptable values
1886: sourceElementNode.reconnect(targetElementNode, model);
1887: // Paste element as the last child of the element
1888: targetElementObject.add(sourceElementObject);
1889: }
1890:
1891: }
1892:
1893: /**
1894: * @return
1895: */
1896: private boolean isTreeViewerSorted() {
1897: if (fSortAction == null) {
1898: return false;
1899: }
1900: return fSortAction.isChecked();
1901: }
1902:
1903: }
|