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