Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 181515 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/core/ischema/ISchemaAttribute.java (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 43-49 Link Here
43
	public static final String[] TYPES = {"boolean", //$NON-NLS-1$
43
	public static final String[] TYPES = {"boolean", //$NON-NLS-1$
44
			"string", //$NON-NLS-1$
44
			"string", //$NON-NLS-1$
45
			"java", //$NON-NLS-1$
45
			"java", //$NON-NLS-1$
46
			"resource" //$NON-NLS-1$
46
			"resource", //$NON-NLS-1$
47
			"identifier" //$NON-NLS-1$
47
	};
48
	};
48
49
49
	/**
50
	/**
(-)src/org/eclipse/pde/internal/core/ischema/IMetaAttribute.java (-7 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 33-38 Link Here
33
	public static final int RESOURCE = 2;
33
	public static final int RESOURCE = 2;
34
34
35
	/**
35
	/**
36
	 * Indicates that the value of the associated attribute is defined
37
	 * in another extension element attribute.
38
	 * 
39
	 * @since 3.4
40
	 */
41
	public static final int IDENTIFIER = 3;
42
43
	/**
36
	 * Property that indicates if an attribute is translatable
44
	 * Property that indicates if an attribute is translatable
37
	 */
45
	 */
38
	public static final String P_TRANSLATABLE = "translatable"; //$NON-NLS-1$
46
	public static final String P_TRANSLATABLE = "translatable"; //$NON-NLS-1$
Lines 42-55 Link Here
42
	 */
50
	 */
43
	public static final String P_DEPRECATED = "deprecated"; //$NON-NLS-1$
51
	public static final String P_DEPRECATED = "deprecated"; //$NON-NLS-1$
44
52
45
	/*
46
	 * non-Javadoc
47
	 */
48
	public static final String[] kindTable = {"string", "java", "resource"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
49
50
	/**
53
	/**
51
	 * Returns optional name of the Java type this type must be based on (only
54
	 * Returns optional name of the Java type this type must be based on (only
52
	 * for JAVA kind).
55
	 * for JAVA kind), or the path expression for IDENTIFIER kind.
53
	 */
56
	 */
54
	public String getBasedOn();
57
	public String getBasedOn();
55
58
(-)src/org/eclipse/pde/internal/core/schema/SchemaAttribute.java (-9 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 12-23 Link Here
12
package org.eclipse.pde.internal.core.schema;
12
package org.eclipse.pde.internal.core.schema;
13
13
14
import java.io.PrintWriter;
14
import java.io.PrintWriter;
15
15
import org.eclipse.pde.internal.core.ischema.*;
16
import org.eclipse.pde.internal.core.ischema.ISchema;
17
import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
18
import org.eclipse.pde.internal.core.ischema.ISchemaElement;
19
import org.eclipse.pde.internal.core.ischema.ISchemaObject;
20
import org.eclipse.pde.internal.core.ischema.ISchemaSimpleType;
21
import org.eclipse.pde.internal.core.util.SchemaUtil;
16
import org.eclipse.pde.internal.core.util.SchemaUtil;
22
import org.eclipse.pde.internal.core.util.XMLComponentRegistry;
17
import org.eclipse.pde.internal.core.util.XMLComponentRegistry;
23
18
Lines 67-73 Link Here
67
	}
62
	}
68
63
69
	public String getBasedOn() {
64
	public String getBasedOn() {
70
		return getKind() == JAVA ? basedOn : null;
65
		if (getKind() == JAVA || getKind() == IDENTIFIER)
66
			return basedOn;
67
		return null;
71
	}
68
	}
72
69
73
	public int getKind() {
70
	public int getKind() {
Lines 190-202 Link Here
190
				writer.println(indent2 + "<appinfo>"); //$NON-NLS-1$
187
				writer.println(indent2 + "<appinfo>"); //$NON-NLS-1$
191
				writer.print(indent3 + "<meta.attribute"); //$NON-NLS-1$
188
				writer.print(indent3 + "<meta.attribute"); //$NON-NLS-1$
192
				String kindValue = null;
189
				String kindValue = null;
193
				switch (getKind()) {
190
				switch (getKind()) { // TODO let's use some constants ;D
194
					case JAVA :
191
					case JAVA :
195
						kindValue = "java"; //$NON-NLS-1$
192
						kindValue = "java"; //$NON-NLS-1$
196
						break;
193
						break;
197
					case RESOURCE :
194
					case RESOURCE :
198
						kindValue = "resource"; //$NON-NLS-1$
195
						kindValue = "resource"; //$NON-NLS-1$
199
						break;
196
						break;
197
					case IDENTIFIER :
198
						kindValue = "identifier"; //$NON-NLS-1$
200
				}
199
				}
201
				if (kindValue != null)
200
				if (kindValue != null)
202
					writer.print(" kind=\"" + kindValue + "\""); //$NON-NLS-1$ //$NON-NLS-2$
201
					writer.print(" kind=\"" + kindValue + "\""); //$NON-NLS-1$ //$NON-NLS-2$
(-)src/org/eclipse/pde/internal/core/schema/Schema.java (-34 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-53 Link Here
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.pde.internal.core.schema;
12
package org.eclipse.pde.internal.core.schema;
13
13
14
import java.io.FileNotFoundException;
14
import java.io.*;
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.io.PrintWriter;
18
import java.net.URL;
15
import java.net.URL;
19
import java.util.Collections;
16
import java.util.*;
20
import java.util.Iterator;
21
import java.util.Locale;
22
import java.util.Vector;
23
24
import org.eclipse.core.runtime.PlatformObject;
17
import org.eclipse.core.runtime.PlatformObject;
25
import org.eclipse.pde.core.IModelChangedEvent;
18
import org.eclipse.pde.core.*;
26
import org.eclipse.pde.core.IModelChangedListener;
27
import org.eclipse.pde.core.ModelChangedEvent;
28
import org.eclipse.pde.internal.core.PDECore;
19
import org.eclipse.pde.internal.core.PDECore;
29
import org.eclipse.pde.internal.core.XMLDefaultHandler;
20
import org.eclipse.pde.internal.core.XMLDefaultHandler;
30
import org.eclipse.pde.internal.core.ischema.IDocumentSection;
21
import org.eclipse.pde.internal.core.ischema.*;
31
import org.eclipse.pde.internal.core.ischema.IMetaAttribute;
22
import org.eclipse.pde.internal.core.util.*;
32
import org.eclipse.pde.internal.core.ischema.ISchema;
23
import org.w3c.dom.*;
33
import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
34
import org.eclipse.pde.internal.core.ischema.ISchemaComplexType;
35
import org.eclipse.pde.internal.core.ischema.ISchemaCompositor;
36
import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor;
37
import org.eclipse.pde.internal.core.ischema.ISchemaElement;
38
import org.eclipse.pde.internal.core.ischema.ISchemaEnumeration;
39
import org.eclipse.pde.internal.core.ischema.ISchemaInclude;
40
import org.eclipse.pde.internal.core.ischema.ISchemaObject;
41
import org.eclipse.pde.internal.core.ischema.ISchemaObjectReference;
42
import org.eclipse.pde.internal.core.ischema.ISchemaRootElement;
43
import org.eclipse.pde.internal.core.ischema.ISchemaSimpleType;
44
import org.eclipse.pde.internal.core.ischema.ISchemaType;
45
import org.eclipse.pde.internal.core.util.PDEXMLHelper;
46
import org.eclipse.pde.internal.core.util.SAXParserWrapper;
47
import org.eclipse.pde.internal.core.util.SchemaUtil;
48
import org.w3c.dom.NamedNodeMap;
49
import org.w3c.dom.Node;
50
import org.w3c.dom.NodeList;
51
import org.xml.sax.SAXException;
24
import org.xml.sax.SAXException;
52
25
53
public class Schema extends PlatformObject implements ISchema {
26
public class Schema extends PlatformObject implements ISchema {
Lines 716-721 Link Here
716
				return IMetaAttribute.JAVA;
689
				return IMetaAttribute.JAVA;
717
			if (name.equals("resource")) //$NON-NLS-1$
690
			if (name.equals("resource")) //$NON-NLS-1$
718
				return IMetaAttribute.RESOURCE;
691
				return IMetaAttribute.RESOURCE;
692
			if (name.equals("identifier")) //$NON-NLS-1$
693
				return IMetaAttribute.IDENTIFIER;
719
		}
694
		}
720
		return IMetaAttribute.STRING;
695
		return IMetaAttribute.STRING;
721
	}
696
	}
(-)src/org/eclipse/pde/internal/ui/PDEUIMessages.java (-10 / +10 lines)
Lines 1081-1086 Link Here
1081
	public static String ResourceAttributeCellEditor_title;
1081
	public static String ResourceAttributeCellEditor_title;
1082
	public static String ResourceAttributeCellEditor_message;
1082
	public static String ResourceAttributeCellEditor_message;
1083
1083
1084
	public static String IdAttributeRow_title;
1085
	public static String IdAttributeRow_message;
1086
	public static String IdAttributeRow_emptyMessage;
1087
1084
	public static String ManifestEditor_RuntimeForm_title;
1088
	public static String ManifestEditor_RuntimeForm_title;
1085
	public static String ManifestSourcePage_extensionPoints;
1089
	public static String ManifestSourcePage_extensionPoints;
1086
1090
Lines 2607-2633 Link Here
2607
	public static String SchemaDetails_deprecated;
2611
	public static String SchemaDetails_deprecated;
2608
2612
2609
	public static String SchemaAttributeDetails_use;
2613
	public static String SchemaAttributeDetails_use;
2610
2611
	public static String SchemaAttributeDetails_type;
2614
	public static String SchemaAttributeDetails_type;
2612
2613
	public static String SchemaAttributeDetails_restrictions;
2615
	public static String SchemaAttributeDetails_restrictions;
2614
2615
	public static String SchemaAttributeDetails_addRestButton;
2616
	public static String SchemaAttributeDetails_addRestButton;
2616
2617
	public static String SchemaAttributeDetails_removeRestButton;
2617
	public static String SchemaAttributeDetails_removeRestButton;
2618
2619
	public static String SchemaAttributeDetails_extends;
2618
	public static String SchemaAttributeDetails_extends;
2620
2621
	public static String SchemaAttributeDetails_browseButton;
2619
	public static String SchemaAttributeDetails_browseButton;
2622
2623
	public static String SchemaAttributeDetails_implements;
2620
	public static String SchemaAttributeDetails_implements;
2624
2625
	public static String SchemaAttributeDetails_title;
2621
	public static String SchemaAttributeDetails_title;
2626
2627
	public static String SchemaAttributeDetails_description;
2622
	public static String SchemaAttributeDetails_description;
2628
2629
	public static String SchemaAttributeDetails_defaultDefaultValue;
2623
	public static String SchemaAttributeDetails_defaultDefaultValue;
2630
2624
2625
	public static String SchemaStringAttributeDetails_reference;
2626
2631
	public static String SchemaDetails_name;
2627
	public static String SchemaDetails_name;
2632
2628
2633
	public static String SchemaRootElementDetails_replacement;
2629
	public static String SchemaRootElementDetails_replacement;
Lines 3195-3198 Link Here
3195
	public static String FilteredPluginArtifactsSelectionDialog_showExtensionPoints;
3191
	public static String FilteredPluginArtifactsSelectionDialog_showExtensionPoints;
3196
	public static String FilteredPluginArtifactsSelectionDialog_showExportedPackages;
3192
	public static String FilteredPluginArtifactsSelectionDialog_showExportedPackages;
3197
3193
3194
	public static String FilteredSchemaAttributeSelectionDialog_title;
3195
	public static String FilteredSchemaAttributeSelectionDialog_message;
3196
	public static String FilteredSchemaAttributeSelectionDialog_searching;
3197
3198
}
3198
}
(-)src/org/eclipse/pde/internal/ui/pderesources.properties (-1 / +8 lines)
Lines 2474-2477 Link Here
2474
FilteredPluginArtifactsSelectionDialog_searching=Searching...
2474
FilteredPluginArtifactsSelectionDialog_searching=Searching...
2475
FilteredPluginArtifactsSelectionDialog_showExtensions=Show Extensions
2475
FilteredPluginArtifactsSelectionDialog_showExtensions=Show Extensions
2476
FilteredPluginArtifactsSelectionDialog_showExtensionPoints=Show Extension Points
2476
FilteredPluginArtifactsSelectionDialog_showExtensionPoints=Show Extension Points
2477
FilteredPluginArtifactsSelectionDialog_showExportedPackages=Show Exported Packages
2477
FilteredPluginArtifactsSelectionDialog_showExportedPackages=Show Exported Packages
2478
SchemaStringAttributeDetails_reference=Reference:
2479
IdAttributeRow_title=Select Identifier
2480
IdAttributeRow_message=Select an identifier:
2481
IdAttributeRow_emptyMessage=No identifiers found
2482
FilteredSchemaAttributeSelectionDialog_title=Select Attribute
2483
FilteredSchemaAttributeSelectionDialog_message=&Select an attribute (? = any character, * = any string):
2484
FilteredSchemaAttributeSelectionDialog_searching=Searching...
(-)src/org/eclipse/pde/internal/ui/editor/plugin/ExtensionElementDetails.java (-6 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2007 IBM Corporation and others.
2
 * Copyright (c) 2003, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
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)
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.pde.internal.ui.editor.plugin;
12
package org.eclipse.pde.internal.ui.editor.plugin;
12
13
Lines 86-96 Link Here
86
87
87
		if (schemaElement != null) {
88
		if (schemaElement != null) {
88
			ISchemaAttribute atts[] = schemaElement.getAttributes();
89
			ISchemaAttribute atts[] = schemaElement.getAttributes();
89
			// Compute horizontal span
90
			if (isEditable()) {
90
			for (int i = 0; i < atts.length; i++) {
91
				// Compute horizontal span
91
				if (isEditable() && (atts[i].getKind() == IMetaAttribute.JAVA || atts[i].getKind() == IMetaAttribute.RESOURCE)) {
92
				for (int i = 0; i < atts.length; i++) {
92
					span = 3;
93
					if (atts[i].getKind() == IMetaAttribute.JAVA || atts[i].getKind() == IMetaAttribute.RESOURCE || atts[i].getKind() == IMetaAttribute.IDENTIFIER) {
93
					break;
94
						span = 3;
95
						break;
96
					}
94
				}
97
				}
95
			}
98
			}
96
			glayout.numColumns = span;
99
			glayout.numColumns = span;
Lines 125-130 Link Here
125
			row = new ClassAttributeRow(this, att);
128
			row = new ClassAttributeRow(this, att);
126
		else if (att.getKind() == IMetaAttribute.RESOURCE)
129
		else if (att.getKind() == IMetaAttribute.RESOURCE)
127
			row = new ResourceAttributeRow(this, att);
130
			row = new ResourceAttributeRow(this, att);
131
		else if (att.getKind() == IMetaAttribute.IDENTIFIER)
132
			row = new IdAttributeRow(this, att);
128
		else if (att.isTranslatable())
133
		else if (att.isTranslatable())
129
			row = new TranslatableAttributeRow(this, att);
134
			row = new TranslatableAttributeRow(this, att);
130
		else {
135
		else {
(-)src/org/eclipse/pde/internal/ui/editor/schema/SchemaFormPage.java (+3 lines)
Lines 56-61 Link Here
56
			detailsPart.registerPage(SchemaStringAttributeDetails.class, new SchemaStringAttributeDetails(fSection));
56
			detailsPart.registerPage(SchemaStringAttributeDetails.class, new SchemaStringAttributeDetails(fSection));
57
			detailsPart.registerPage(SchemaJavaAttributeDetails.class, new SchemaJavaAttributeDetails(fSection));
57
			detailsPart.registerPage(SchemaJavaAttributeDetails.class, new SchemaJavaAttributeDetails(fSection));
58
			detailsPart.registerPage(SchemaOtherAttributeDetails.class, new SchemaOtherAttributeDetails(fSection));
58
			detailsPart.registerPage(SchemaOtherAttributeDetails.class, new SchemaOtherAttributeDetails(fSection));
59
			detailsPart.registerPage(SchemaIdentifierAttributeDetails.class, new SchemaIdentifierAttributeDetails(fSection));
59
			detailsPart.setPageProvider(this);
60
			detailsPart.setPageProvider(this);
60
		}
61
		}
61
62
Lines 77-82 Link Here
77
					case IMetaAttribute.STRING :
78
					case IMetaAttribute.STRING :
78
						if (att.getType().getName().equals(ISchemaAttribute.TYPES[ISchemaAttribute.STR_IND]))
79
						if (att.getType().getName().equals(ISchemaAttribute.TYPES[ISchemaAttribute.STR_IND]))
79
							return SchemaStringAttributeDetails.class;
80
							return SchemaStringAttributeDetails.class;
81
					case IMetaAttribute.IDENTIFIER :
82
						return SchemaIdentifierAttributeDetails.class;
80
				}
83
				}
81
				return SchemaOtherAttributeDetails.class;
84
				return SchemaOtherAttributeDetails.class;
82
			} else
85
			} else
(-)src/org/eclipse/pde/internal/ui/editor/schema/SchemaIdentifierAttributeDetails.java (+90 lines)
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.schema;
12
13
import org.eclipse.jface.window.Window;
14
import org.eclipse.pde.internal.core.ischema.*;
15
import org.eclipse.pde.internal.core.schema.SchemaAttribute;
16
import org.eclipse.pde.internal.ui.PDEPlugin;
17
import org.eclipse.pde.internal.ui.PDEUIMessages;
18
import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
19
import org.eclipse.pde.internal.ui.parts.FormEntry;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.ui.IActionBars;
22
import org.eclipse.ui.forms.widgets.FormToolkit;
23
24
public class SchemaIdentifierAttributeDetails extends SchemaAttributeDetails {
25
26
	private FormEntry fReferenceEntry;
27
28
	public SchemaIdentifierAttributeDetails(ElementSection section) {
29
		super(section);
30
	}
31
32
	protected void createTypeDetails(Composite parent, FormToolkit toolkit) {
33
		fReferenceEntry = new FormEntry(parent, toolkit, PDEUIMessages.SchemaStringAttributeDetails_reference, PDEUIMessages.SchemaAttributeDetails_browseButton, false, 11);
34
	}
35
36
	public void updateFields(ISchemaObject object) {
37
		if (!(object instanceof SchemaAttribute))
38
			return;
39
		super.updateFields(object);
40
41
		boolean editable = isEditableElement();
42
		fReferenceEntry.setEditable(editable);
43
	}
44
45
	public void hookListeners() {
46
		super.hookListeners();
47
		IActionBars actionBars = getPage().getPDEEditor().getEditorSite().getActionBars();
48
		fReferenceEntry.setFormEntryListener(new FormEntryAdapter(this, actionBars) {
49
			public void textValueChanged(FormEntry entry) {
50
				if (blockListeners())
51
					return;
52
				getAttribute().setBasedOn(entry.getValue());
53
			}
54
55
			public void browseButtonSelected(FormEntry entry) {
56
				if (blockListeners())
57
					return;
58
				doOpenSelectionDialog(fReferenceEntry);
59
			}
60
		});
61
	}
62
63
	private void doOpenSelectionDialog(FormEntry entry) {
64
		FilteredSchemaAttributeSelectionDialog dialog = new FilteredSchemaAttributeSelectionDialog(PDEPlugin.getActiveWorkbenchShell());
65
		int status = dialog.open();
66
		if (status == Window.OK) {
67
			Object[] result = dialog.getResult();
68
			Object object = result[0];
69
			if (object instanceof ISchemaAttribute) {
70
				ISchemaAttribute attribute = (ISchemaAttribute) object;
71
				String schemaId = attribute.getSchema().getQualifiedPointId();
72
				String refId = buildBasedOnValue(attribute);
73
				String id = schemaId + '/' + refId;
74
				entry.setValue(id);
75
			}
76
		}
77
	}
78
79
	// TODO faulty recursion... this doesn't work in all cases probably...
80
	private String buildBasedOnValue(ISchemaObject object) {
81
		if (object instanceof ISchemaElement)
82
			return object.getName() + '/' + buildBasedOnValue(object.getParent());
83
		return ""; //$NON-NLS-1$
84
	}
85
86
	private String buildBasedOnValue(ISchemaAttribute attribute) {
87
		return buildBasedOnValue(attribute.getParent()) + "@" + attribute.getName(); //$NON-NLS-1$
88
	}
89
90
}
(-)src/org/eclipse/pde/internal/ui/editor/plugin/rows/IdAttributeRow.java (+123 lines)
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.LabelProvider;
18
import org.eclipse.jface.window.Window;
19
import org.eclipse.pde.core.plugin.IPluginModelBase;
20
import org.eclipse.pde.core.plugin.PluginRegistry;
21
import org.eclipse.pde.internal.core.PDECore;
22
import org.eclipse.pde.internal.core.ischema.ISchemaAttribute;
23
import org.eclipse.pde.internal.ui.*;
24
import org.eclipse.pde.internal.ui.editor.IContextPart;
25
import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
26
import org.eclipse.swt.graphics.Image;
27
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
28
29
public class IdAttributeRow extends ButtonAttributeRow {
30
31
	private class IdAttributeLabelProvider extends LabelProvider {
32
33
		public Image getImage(Object element) {
34
			return PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_GENERIC_XML_OBJ);
35
		}
36
37
	}
38
39
	public IdAttributeRow(IContextPart part, ISchemaAttribute att) {
40
		super(part, att);
41
	}
42
43
	protected boolean isReferenceModel() {
44
		return !part.getPage().getModel().isEditable();
45
	}
46
47
	/* (non-Javadoc)
48
	 * @see org.eclipse.pde.internal.ui.editor.plugin.rows.ButtonAttributeRow#browse()
49
	 */
50
	protected void browse() {
51
		ElementListSelectionDialog dialog = new ElementListSelectionDialog(PDEPlugin.getActiveWorkbenchShell(), new IdAttributeLabelProvider());
52
		dialog.setTitle(PDEUIMessages.IdAttributeRow_title);
53
		dialog.setMessage(PDEUIMessages.IdAttributeRow_message);
54
		dialog.setEmptyListMessage(PDEUIMessages.IdAttributeRow_emptyMessage);
55
		Map attributeMap = new HashMap();
56
		gatherInfo(attributeMap);
57
		dialog.setElements(attributeMap.keySet().toArray());
58
		if (dialog.open() == Window.OK) {
59
			text.setText(dialog.getFirstResult().toString());
60
		}
61
	}
62
63
	private void gatherInfo(Map attributesInfo) {
64
		String basedOn = getAttribute().getBasedOn();
65
		String[] path = basedOn.split("/"); //$NON-NLS-1$
66
		IExtension[] extensions = PDECore.getDefault().getExtensionsRegistry().findExtensions(path[0], true);
67
		List members = new ArrayList();
68
		for (int i = 0; i < extensions.length; i++) {
69
			IConfigurationElement[] elements = extensions[i].getConfigurationElements();
70
			for (int j = 0; j < elements.length; j++) {
71
				if (elements[j].getName().equals(path[1])) {
72
					members.add(elements[j]);
73
				}
74
			}
75
		}
76
		List parents = members;
77
		for (int i = 2; i < path.length; i++) {
78
			if (path[i].startsWith("@")) { //$NON-NLS-1$
79
				String attName = path[i].substring(1);
80
				for (Iterator iterator = parents.iterator(); iterator.hasNext();) {
81
					IConfigurationElement element = (IConfigurationElement) iterator.next();
82
					String value = element.getAttribute(attName);
83
					if (value != null) {
84
						attributesInfo.put(value, element);
85
					}
86
				}
87
				return;
88
			}
89
			members = new ArrayList();
90
			for (Iterator iterator = parents.iterator(); iterator.hasNext();) {
91
				IConfigurationElement element = (IConfigurationElement) iterator.next();
92
				members.addAll(keepGoing(element, path[i]));
93
			}
94
			parents = members;
95
		}
96
	}
97
98
	private List keepGoing(IConfigurationElement element, String tag) {
99
		return Arrays.asList(element.getChildren(tag));
100
	}
101
102
	/* (non-Javadoc)
103
	 * @see org.eclipse.pde.internal.ui.editor.plugin.rows.ReferenceAttributeRow#openReference()
104
	 */
105
	protected void openReference() {
106
		Map attributeMap = new HashMap();
107
		gatherInfo(attributeMap);
108
		String id = text.getText();
109
		// TODO this is a hack, consider not even supporting openReference
110
		IConfigurationElement element = (IConfigurationElement) attributeMap.get(id);
111
		if (element != null) {
112
			String pluginId = element.getContributor().getName();
113
			IPluginModelBase model = PluginRegistry.findModel(pluginId);
114
//			IExtensions e = model.getExtensions(); // can be null
115
//			IPluginExtension[] extensions = e.getExtensions();
116
//			for (int i = 0; i < extensions.length; i++) {
117
//				IPluginExtension extension = extensions[i];
118
//			}
119
120
			ManifestEditor.openPluginEditor(model, true);
121
		}
122
	}
123
}
(-)src/org/eclipse/pde/internal/ui/editor/schema/FilteredSchemaAttributeSelectionDialog.java (+194 lines)
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.schema;
12
13
import java.util.Comparator;
14
import org.eclipse.core.runtime.*;
15
import org.eclipse.jface.dialogs.IDialogSettings;
16
import org.eclipse.jface.viewers.ILabelDecorator;
17
import org.eclipse.jface.viewers.LabelProvider;
18
import org.eclipse.pde.core.plugin.*;
19
import org.eclipse.pde.internal.core.PDECore;
20
import org.eclipse.pde.internal.core.ischema.*;
21
import org.eclipse.pde.internal.core.schema.SchemaRegistry;
22
import org.eclipse.pde.internal.core.util.IdUtil;
23
import org.eclipse.pde.internal.ui.*;
24
import org.eclipse.swt.graphics.Image;
25
import org.eclipse.swt.widgets.*;
26
import org.eclipse.ui.dialogs.FilteredItemsSelectionDialog;
27
28
public class FilteredSchemaAttributeSelectionDialog extends FilteredItemsSelectionDialog {
29
30
	private static final String DIALOG_SETTINGS = "org.eclipse.pde.ui.dialogs.SchemaAttributeFilteredItemsSelectionDialog"; //$NON-NLS-1$
31
	private final SchemaListLabelProvider listLabelProvider = new SchemaListLabelProvider();
32
	private final SchemaDetailsLabelProvider detailsLabelProvider = new SchemaDetailsLabelProvider();
33
34
	public FilteredSchemaAttributeSelectionDialog(Shell shell) {
35
		super(shell, false);
36
37
		setTitle(PDEUIMessages.FilteredSchemaAttributeSelectionDialog_title);
38
		setMessage(PDEUIMessages.FilteredSchemaAttributeSelectionDialog_message);
39
40
		PDEPlugin.getDefault().getLabelProvider().connect(this);
41
		setListLabelProvider(listLabelProvider);
42
		setListSelectionLabelDecorator(listLabelProvider);
43
		setDetailsLabelProvider(detailsLabelProvider);
44
	}
45
46
	private class SchemaListLabelProvider extends LabelProvider implements ILabelDecorator {
47
		public Image getImage(Object element) {
48
			return PDEPlugin.getDefault().getLabelProvider().getImage(element);
49
		}
50
51
		public String getText(Object element) {
52
			if (element instanceof ISchemaAttribute) {
53
				ISchemaAttribute attribute = (ISchemaAttribute) element;
54
				String text = PDEPlugin.getDefault().getLabelProvider().getText(element);
55
				if (isDuplicateElement(element)) {
56
					ISchemaObject object = attribute.getParent();
57
					if (object != null)
58
						return text + " - " + attribute.getParent().getName(); //$NON-NLS-1$
59
				}
60
			}
61
			return PDEPlugin.getDefault().getLabelProvider().getText(element);
62
		}
63
64
		public Image decorateImage(Image image, Object element) {
65
			return image; // nothing to decorate
66
		}
67
68
		public String decorateText(String text, Object element) {
69
			if (element instanceof ISchemaAttribute) {
70
				ISchemaAttribute attribute = (ISchemaAttribute) element;
71
				ISchemaObject object = attribute.getParent();
72
				if (object != null && !isDuplicateElement(element))
73
					return text + " - " + attribute.getParent().getName(); //$NON-NLS-1$
74
			}
75
			return text;
76
		}
77
78
	}
79
80
	private class SchemaDetailsLabelProvider extends LabelProvider {
81
82
		public Image getImage(Object element) {
83
			return PDEPlugin.getDefault().getLabelProvider().get(PDEPluginImages.DESC_EXT_POINT_OBJ);
84
		}
85
86
		public String getText(Object element) {
87
			if (element instanceof ISchemaAttribute) {
88
				ISchemaAttribute attribute = (ISchemaAttribute) element;
89
				ISchema schema = attribute.getSchema();
90
				return schema.getPointId() + ' ' + '(' + schema.getPluginId() + ')';
91
			}
92
			return super.getText(element);
93
		}
94
	}
95
96
	private class SchemaItemsFilter extends ItemsFilter {
97
98
		public boolean isConsistentItem(Object item) {
99
			return true;
100
		}
101
102
		public boolean matchItem(Object item) {
103
			if (item instanceof ISchemaAttribute) {
104
				ISchemaAttribute attribute = (ISchemaAttribute) item;
105
				return matches(attribute.getName());
106
			}
107
			return false;
108
		}
109
110
	}
111
112
	private class SchemaComparator implements Comparator {
113
114
		public int compare(Object arg0, Object arg1) {
115
			return 0;
116
		}
117
118
	}
119
120
	protected ItemsFilter createFilter() {
121
		return new SchemaItemsFilter();
122
	}
123
124
	protected void fillContentProvider(AbstractContentProvider contentProvider, ItemsFilter itemsFilter, IProgressMonitor progressMonitor) throws CoreException {
125
126
		IPluginModelBase[] models = PluginRegistry.getActiveModels();
127
		SchemaRegistry registry = PDECore.getDefault().getSchemaRegistry();
128
129
		// cycle through all active plug-ins and their extension points
130
		progressMonitor.beginTask(PDEUIMessages.FilteredSchemaAttributeSelectionDialog_searching, models.length);
131
		for (int i = 0; i < models.length; i++) {
132
			IPluginExtensionPoint[] points = models[i].getPluginBase().getExtensionPoints();
133
134
			for (int j = 0; j < points.length; j++) {
135
				String pointID = IdUtil.getFullId(points[j], models[i]);
136
137
				ISchema schema = registry.getSchema(pointID);
138
				if (schema == null) // if we don't find a schema
139
					continue;
140
				ISchemaElement[] elements = schema.getElements();
141
142
				for (int k = 0; k < elements.length; k++) {
143
					ISchemaElement element = elements[k];
144
					ISchemaAttribute[] attributes = element.getAttributes();
145
146
					for (int l = 0; l < attributes.length; l++) {
147
						ISchemaAttribute attribute = attributes[l];
148
						// only add attributes of the string kind, isn't translatable and is required
149
						if (attribute.getKind() == IMetaAttribute.STRING && !attribute.isTranslatable() && attribute.getUse() == ISchemaAttribute.REQUIRED)
150
							contentProvider.add(attribute, itemsFilter);
151
					}
152
				}
153
			}
154
			progressMonitor.worked(1);
155
		}
156
157
		progressMonitor.done();
158
159
	}
160
161
	protected IDialogSettings getDialogSettings() {
162
		IDialogSettings settings = PDEPlugin.getDefault().getDialogSettings().getSection(DIALOG_SETTINGS);
163
		if (settings == null) {
164
			settings = PDEPlugin.getDefault().getDialogSettings().addNewSection(DIALOG_SETTINGS);
165
		}
166
		return settings;
167
	}
168
169
	public String getElementName(Object item) {
170
		if (item instanceof ISchemaAttribute) {
171
			ISchemaAttribute attribute = (ISchemaAttribute) item;
172
			return attribute.getName();
173
		}
174
		return null;
175
	}
176
177
	protected Comparator getItemsComparator() {
178
		return new SchemaComparator();
179
	}
180
181
	protected IStatus validateItem(Object item) {
182
		return new Status(IStatus.OK, "org.eclipse.pde.ui", 0, "", null); //$NON-NLS-1$ //$NON-NLS-2$
183
	}
184
185
	public boolean close() {
186
		PDEPlugin.getDefault().getLabelProvider().disconnect(this);
187
		return super.close();
188
	}
189
190
	protected Control createExtendedContentArea(Composite parent) {
191
		return null;
192
	}
193
194
}

Return to bug 181515