|
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 |
} |