|
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 |
* Remy Chi Jian Suen <remy.suen@gmail.com> - Provide more structure, safety, and convenience for ID-based references between extension points (id hell) |
| 11 |
*******************************************************************************/ |
| 12 |
package org.eclipse.pde.internal.ui.editor.plugin.rows; |
| 13 |
|
| 14 |
import java.util.*; |
| 15 |
import org.eclipse.core.runtime.IConfigurationElement; |
| 16 |
import org.eclipse.core.runtime.IExtension; |
| 17 |
import org.eclipse.jface.viewers.ILabelProvider; |
| 18 |
import org.eclipse.jface.viewers.LabelProvider; |
| 19 |
import org.eclipse.jface.window.Window; |
| 20 |
import org.eclipse.pde.internal.core.PDECore; |
| 21 |
import org.eclipse.pde.internal.core.ischema.ISchemaAttribute; |
| 22 |
import org.eclipse.pde.internal.ui.PDEPlugin; |
| 23 |
import org.eclipse.pde.internal.ui.PDEUIMessages; |
| 24 |
import org.eclipse.pde.internal.ui.editor.IContextPart; |
| 25 |
import org.eclipse.ui.dialogs.ElementListSelectionDialog; |
| 26 |
|
| 27 |
public class IdAttributeRow extends ButtonAttributeRow { |
| 28 |
|
| 29 |
public IdAttributeRow(IContextPart part, ISchemaAttribute att) { |
| 30 |
super(part, att); |
| 31 |
} |
| 32 |
|
| 33 |
protected boolean isReferenceModel() { |
| 34 |
return !part.getPage().getModel().isEditable(); |
| 35 |
} |
| 36 |
|
| 37 |
/* (non-Javadoc) |
| 38 |
* @see org.eclipse.pde.internal.ui.editor.plugin.rows.ButtonAttributeRow#browse() |
| 39 |
*/ |
| 40 |
protected void browse() { |
| 41 |
ILabelProvider provider = new LabelProvider(); |
| 42 |
ElementListSelectionDialog dialog = new ElementListSelectionDialog(PDEPlugin.getActiveWorkbenchShell(), provider); |
| 43 |
dialog.setTitle(PDEUIMessages.ResourceAttributeCellEditor_title); |
| 44 |
ArrayList attributesInfo = new ArrayList(); |
| 45 |
gatherInfo(attributesInfo); |
| 46 |
dialog.setElements(attributesInfo.toArray()); |
| 47 |
if (dialog.open() == Window.OK) { |
| 48 |
text.setText(dialog.getFirstResult().toString()); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
private void gatherInfo(ArrayList attributesInfo) { |
| 53 |
String basedOn = getAttribute().getBasedOn(); |
| 54 |
String[] path = basedOn.split("/"); //$NON-NLS-1$ |
| 55 |
IExtension[] extensions = PDECore.getDefault().getExtensionsRegistry().findExtensions(path[0], true); |
| 56 |
List members = new ArrayList(); |
| 57 |
for (int i = 0; i < extensions.length; i++) { |
| 58 |
IConfigurationElement[] elements = extensions[i].getConfigurationElements(); |
| 59 |
for (int j = 0; j < elements.length; j++) { |
| 60 |
if (elements[j].getName().equals(path[1])) { |
| 61 |
members.add(elements[j]); |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
List parents = members; |
| 66 |
for (int i = 2; i < path.length; i++) { |
| 67 |
if (path[i].startsWith("@")) { //$NON-NLS-1$ |
| 68 |
String attName = path[i].substring(1); |
| 69 |
for (Iterator iterator = parents.iterator(); iterator.hasNext();) { |
| 70 |
IConfigurationElement element = (IConfigurationElement) iterator.next(); |
| 71 |
String value = element.getAttribute(attName); |
| 72 |
if (value != null) { |
| 73 |
attributesInfo.add(value); |
| 74 |
} |
| 75 |
} |
| 76 |
return; |
| 77 |
} |
| 78 |
members = new ArrayList(); |
| 79 |
for (Iterator iterator = parents.iterator(); iterator.hasNext();) { |
| 80 |
IConfigurationElement element = (IConfigurationElement) iterator.next(); |
| 81 |
members.addAll(keepGoing(element, path[i])); |
| 82 |
} |
| 83 |
parents = members; |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
private List keepGoing(IConfigurationElement element, String tag) { |
| 88 |
return Arrays.asList(element.getChildren(tag)); |
| 89 |
} |
| 90 |
|
| 91 |
/* (non-Javadoc) |
| 92 |
* @see org.eclipse.pde.internal.ui.editor.plugin.rows.ReferenceAttributeRow#openReference() |
| 93 |
*/ |
| 94 |
protected void openReference() { |
| 95 |
// do nothing for now |
| 96 |
} |
| 97 |
|
| 98 |
} |