Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilos Kleint2011-01-13 14:01:24 +0000
committerMilos Kleint2011-01-13 14:01:24 +0000
commita2ee42b7baf71c8b0365d4e151da845da4f1b21d (patch)
treef992451818d788c10bf2d616a285df8b1d05d35c /org.eclipse.m2e.editor
parent02b8842dece8b84a52ad56a1e35f21aedfb1c977 (diff)
downloadm2e-core-a2ee42b7baf71c8b0365d4e151da845da4f1b21d.tar.gz
m2e-core-a2ee42b7baf71c8b0365d4e151da845da4f1b21d.tar.xz
m2e-core-a2ee42b7baf71c8b0365d4e151da845da4f1b21d.zip
MNGECLIPSE-2717 show a decorator text/icon for managed versions. had to convert the Table to Tree in the composites thus stopped inheriting from the common list composite
Diffstat (limited to 'org.eclipse.m2e.editor')
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java281
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java64
2 files changed, 320 insertions, 25 deletions
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java
index fffc7fe7..cc2228f4 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java
@@ -13,10 +13,14 @@ package org.eclipse.m2e.editor.composites;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.MavenProject;
@@ -36,13 +40,25 @@ import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.IOpenListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
+
import org.eclipse.jface.window.Window;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.core.MavenLogger;
@@ -66,6 +82,8 @@ import org.eclipse.m2e.model.edit.pom.PomFactory;
import org.eclipse.m2e.model.edit.pom.PomPackage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.events.ControlAdapter;
+import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
@@ -76,6 +94,9 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.FormToolkit;
@@ -122,17 +143,17 @@ public class DependenciesComposite extends Composite {
ValueProvider<DependencyManagement> dependencyManagementProvider;
- final DependencyLabelProvider dependencyLabelProvider = new DependencyLabelProvider();
+ final DependencyLabelProvider dependencyLabelProvider = new DependencyLabelProvider(true);
final DependencyLabelProvider dependencyManagementLabelProvider = new DependencyLabelProvider();
protected boolean showInheritedDependencies = false;
- final ListEditorContentProvider<Object> dependenciesContentProvider = new ListEditorContentProvider<Object>();
+ final DependencyContentProvider<Object> dependenciesContentProvider = new DependencyContentProvider<Object>();
DependenciesComparator<Object> dependenciesComparator;
- final ListEditorContentProvider<Dependency> dependencyManagementContentProvider = new ListEditorContentProvider<Dependency>();
+ final DependencyContentProvider<Dependency> dependencyManagementContentProvider = new DependencyContentProvider<Dependency>();
DependenciesComparator<Dependency> dependencyManagementComparator;
@@ -173,7 +194,7 @@ public class DependenciesComposite extends Composite {
dependenciesContentProvider.setComparator(dependenciesComparator);
dependenciesEditor = new DependenciesListComposite<Object>(dependenciesSection, SWT.NONE, true);
- dependenciesEditor.setLabelProvider(dependencyLabelProvider);
+ dependenciesEditor.setLabelProvider(new DelegatingStyledCellLabelProvider( dependencyLabelProvider));
dependenciesEditor.setContentProvider(dependenciesContentProvider);
dependenciesEditor.setRemoveButtonListener(new SelectionAdapter() {
@@ -330,7 +351,7 @@ public class DependenciesComposite extends Composite {
}
public void run() {
- TableViewer viewer = dependenciesEditor.getViewer();
+ TreeViewer viewer = dependenciesEditor.getViewer();
if(isChecked()) {
viewer.addFilter(searchFilter);
} else {
@@ -472,7 +493,7 @@ public class DependenciesComposite extends Composite {
}
public void run() {
- TableViewer viewer = dependencyManagementEditor.getViewer();
+ TreeViewer viewer = dependencyManagementEditor.getViewer();
if(isChecked()) {
viewer.addFilter(searchFilter);
} else {
@@ -624,16 +645,16 @@ public class DependenciesComposite extends Composite {
}
@SuppressWarnings({"unchecked", "rawtypes"})
- private void selectDepenendencies(ListEditorComposite<?> editor, EObject parent,
+ private void selectDepenendencies(PropertiesListComposite<?> dependencyManagementEditor, EObject parent,
EStructuralFeature feature) {
if(parent != null) {
- editor.setSelection((List) parent.eGet(feature));
- editor.refresh();
+ dependencyManagementEditor.setSelection((List) parent.eGet(feature));
+ dependencyManagementEditor.refresh();
}
}
});
//we add filter here as the default behaviour is to filter..
- TableViewer viewer = dependenciesEditor.getViewer();
+ TreeViewer viewer = dependenciesEditor.getViewer();
viewer.addFilter(searchFilter);
viewer = dependencyManagementEditor.getViewer();
viewer.addFilter(searchFilter);
@@ -752,15 +773,181 @@ public class DependenciesComposite extends Composite {
dependenciesEditor.setInput(deps);
}
- protected class PropertiesListComposite<T> extends ListEditorComposite<T> {
+ //no longer extending ListeEditoComposite because we need a Tree, not Table here..
+ protected class PropertiesListComposite<T> extends Composite {
private static final String PROPERTIES_BUTTON_KEY = "PROPERTIES"; //$NON-NLS-1$
protected Button properties;
+
+ TreeViewer viewer;
+
+ protected Map<String, Button> buttons = new HashMap<String, Button>(5);
+
+ /*
+ * Default button keys
+ */
+ private static final String ADD = "ADD"; //$NON-NLS-1$
+ private static final String CREATE = "CREATE"; //$NON-NLS-1$
+ private static final String REMOVE = "REMOVE"; //$NON-NLS-1$
+ boolean readOnly = false;
+
+ protected FormToolkit toolkit;
+
public PropertiesListComposite(Composite parent, int style, boolean includeSearch) {
- super(parent, style, includeSearch);
+ super(parent, style);
+ toolkit = new FormToolkit(parent.getDisplay());
+
+ GridLayout gridLayout = new GridLayout(2, false);
+ gridLayout.marginWidth = 1;
+ gridLayout.marginHeight = 1;
+ gridLayout.verticalSpacing = 1;
+ setLayout(gridLayout);
+
+ final Tree tree = toolkit.createTree(this, SWT.FULL_SELECTION | SWT.MULTI | style);
+ tree.setData("name", "list-editor-composite-table"); //$NON-NLS-1$ //$NON-NLS-2$
+ viewer = new TreeViewer(tree);
+
+
+ createButtons(includeSearch);
+
+ int vSpan = buttons.size();
+ GridData viewerData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, vSpan);
+ viewerData.widthHint = 100;
+ viewerData.heightHint = includeSearch ? 125 : 50;
+ viewerData.minimumHeight = includeSearch ? 125 : 50;
+ tree.setLayoutData(viewerData);
+ viewer.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.TRUE);
+
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ viewerSelectionChanged();
+ }
+ });
+
+ toolkit.paintBordersFor(this);
}
- @Override
+ public void setLabelProvider(IBaseLabelProvider delegatingStyledCellLabelProvider) {
+ viewer.setLabelProvider(delegatingStyledCellLabelProvider);
+ }
+
+ public void setContentProvider(DependencyContentProvider<T> contentProvider) {
+ viewer.setContentProvider(contentProvider);
+ }
+
+ public void setInput(List<T> input) {
+ viewer.setInput(input);
+ viewer.setSelection(new StructuredSelection());
+ }
+
+ public Object getInput() {
+ return viewer.getInput();
+ }
+
+ public void setOpenListener(IOpenListener listener) {
+ viewer.addOpenListener(listener);
+ }
+
+ public void addSelectionListener(ISelectionChangedListener listener) {
+ viewer.addSelectionChangedListener(listener);
+ }
+
+ public void setAddButtonListener(SelectionListener listener) {
+ if(getAddButton() != null) {
+ getAddButton().addSelectionListener(listener);
+ getAddButton().setEnabled(true);
+ }
+ }
+
+ protected Button getCreateButton() {
+ return buttons.get(CREATE);
+ }
+
+ protected Button getRemoveButton() {
+ return buttons.get(REMOVE);
+ }
+
+ protected Button getAddButton() {
+ return buttons.get(ADD);
+ }
+
+ public void setCreateButtonListener(SelectionListener listener) {
+ getCreateButton().addSelectionListener(listener);
+ getCreateButton().setEnabled(true);
+ }
+
+ public void setRemoveButtonListener(SelectionListener listener) {
+ getRemoveButton().addSelectionListener(listener);
+ }
+
+ public TreeViewer getViewer() {
+ return viewer;
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public List<T> getSelection() {
+ IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
+ return selection == null ? Collections.emptyList() : selection.toList();
+ }
+
+ public void setSelection(List<T> selection) {
+ viewer.setSelection(new StructuredSelection(selection), true);
+ }
+
+ public void refresh() {
+ if(!viewer.getTree().isDisposed()) {
+ viewer.refresh(true);
+ }
+ }
+
+ public void setCellModifier(ICellModifier cellModifier) {
+ viewer.setColumnProperties(new String[] {"?"}); //$NON-NLS-1$
+
+ TextCellEditor editor = new TextCellEditor(viewer.getTree());
+ viewer.setCellEditors(new CellEditor[] {editor});
+ viewer.setCellModifier(cellModifier);
+ }
+
+ public void setDoubleClickListener(IDoubleClickListener listener) {
+ viewer.addDoubleClickListener(listener);
+ }
+
+
+ protected void addButton(String key, Button button) {
+ buttons.put(key, button);
+ }
+
+ protected void createAddButton() {
+ addButton(ADD, createButton(Messages.ListEditorComposite_btnAdd));
+ }
+
+ protected void createCreateButton() {
+ addButton(CREATE, createButton(Messages.ListEditorComposite_btnCreate));
+ }
+
+ protected void createRemoveButton() {
+ addButton(REMOVE, createButton(Messages.ListEditorComposite_btnRemove));
+ }
+
+ protected Button createButton(String text) {
+ Button button = toolkit.createButton(this, text, SWT.FLAT);
+ GridData gd = new GridData(SWT.FILL, SWT.TOP, false, false);
+ gd.verticalIndent = 0;
+ button.setLayoutData(gd);
+ button.setEnabled(false);
+ return button;
+ }
+
+
+ /**
+ * Create the buttons that populate the column to the right of the ListViewer.
+ * Subclasses must call the helper method addButton to add each button to the
+ * composite.
+ *
+ * @param includeSearch true if the search button should be created
+ */
+
protected void createButtons(boolean includeSearch) {
if(includeSearch) {
createAddButton();
@@ -774,9 +961,8 @@ public class DependenciesComposite extends Composite {
properties.addSelectionListener(listener);
}
- @Override
protected void viewerSelectionChanged() {
- super.viewerSelectionChanged();
+ updateRemoveButton();
updatePropertiesButton();
}
@@ -785,15 +971,22 @@ public class DependenciesComposite extends Composite {
properties.setEnabled(!readOnly && enable);
}
- @Override
protected void updateRemoveButton() {
boolean enable = !viewer.getSelection().isEmpty() && !isBadSelection();
getRemoveButton().setEnabled(!readOnly && enable);
}
- @Override
public void setReadOnly(boolean readOnly) {
- super.setReadOnly(readOnly);
+ this.readOnly = readOnly;
+ for (Map.Entry<String, Button> entry : buttons.entrySet()) {
+ if (entry.getKey().equals(REMOVE)) {
+ //Special case, as it makes no sense to enable if it there's nothing selected.
+ updateRemoveButton();
+ } else {
+ //TODO: mkleint this is fairly dangerous thing to do, each button shall be handled individually based on context.
+ entry.getValue().setEnabled(!readOnly);
+ }
+ }
updatePropertiesButton();
}
@@ -832,6 +1025,7 @@ public class DependenciesComposite extends Composite {
super(parent, style, includeSearch);
}
+
@Override
protected void createButtons(boolean includeSearch) {
super.createButtons(includeSearch);
@@ -883,4 +1077,55 @@ public class DependenciesComposite extends Composite {
setDependenciesInput();
}
}
+
+ private static class DependencyContentProvider<T> implements ITreeContentProvider {
+ private final Object[] EMPTY = new Object[0];
+ private boolean shouldSort;
+ private Comparator<T> comparator;
+
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object[] getElements(Object input) {
+ if(input instanceof List) {
+ List<T> list = (List<T>) input;
+ if (shouldSort) {
+ T[] array = (T[]) list.toArray();
+ Arrays.<T>sort(array, comparator);
+ return array;
+ }
+ return list.toArray();
+ }
+ return EMPTY;
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ return null;
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+ public void setShouldSort(boolean shouldSort) {
+ this.shouldSort = shouldSort;
+ }
+
+ public void setComparator(Comparator<T> comparator) {
+ this.comparator = comparator;
+ }
+
+ }
+
}
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java
index 255007ae..1c2ee584 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java
@@ -14,9 +14,13 @@ package org.eclipse.m2e.editor.composites;
import java.util.Collection;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.DependencyManagement;
import org.apache.maven.project.MavenProject;
import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.m2e.core.MavenImages;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.MavenProjectManager;
@@ -29,6 +33,7 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
/**
@@ -36,12 +41,23 @@ import org.eclipse.swt.widgets.Display;
*
* @author Eugene Kuleshov
*/
-public class DependencyLabelProvider extends LabelProvider implements IColorProvider {
+public class DependencyLabelProvider extends LabelProvider implements IColorProvider, DelegatingStyledCellLabelProvider.IStyledLabelProvider {
private MavenPomEditor pomEditor;
private boolean showGroupId = false;
+ private final boolean showManagedOverlay;
+
+ public DependencyLabelProvider() {
+ this(false);
+ }
+
+ public DependencyLabelProvider(boolean showManagedOverlay) {
+ super();
+ this.showManagedOverlay = showManagedOverlay;
+ }
+
public void setPomEditor(MavenPomEditor pomEditor) {
this.pomEditor = pomEditor;
}
@@ -63,7 +79,38 @@ public class DependencyLabelProvider extends LabelProvider implements IColorProv
public Color getBackground(Object element) {
return null;
}
+
+ private String findManagedVersion(Dependency dep) {
+ if (pomEditor != null) {
+ MavenProject mp = pomEditor.getMavenProject();
+ if(mp != null) {
+ DependencyManagement dm = mp.getDependencyManagement();
+ if(dm != null) {
+ for(org.apache.maven.model.Dependency d : dm.getDependencies()) {
+ if(d.getGroupId().equals(dep.getGroupId()) && d.getArtifactId().equals(dep.getArtifactId())) {
+ //TODO based on location, try finding a match in the live Model
+ return d.getVersion();
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+ public StyledString getStyledText(Object element) {
+ if(element instanceof Dependency) {
+ StyledString ss = new StyledString(getText(element));
+ Dependency dep = (Dependency) element;
+ String version = findManagedVersion(dep);
+ if (version != null) {
+ ss.append(" (managed:" + version +")", StyledString.DECORATIONS_STYLER);
+ }
+ return ss;
+ }
+ return new StyledString(getText(element));
+ }
+
// LabelProvider
@Override
@@ -90,22 +137,23 @@ public class DependencyLabelProvider extends LabelProvider implements IColorProv
public Image getImage(Object element) {
if(element instanceof Dependency) {
Dependency dependency = (Dependency) element;
- return getImage(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
+ boolean isManaged = showManagedOverlay && findManagedVersion(dependency) != null;
+ return getImage(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), isManaged);
} else if (element instanceof org.apache.maven.model.Dependency) {
//mkleint: all MavenDependency instances are inherited
return MavenEditorImages.IMG_INHERITED;
}else if(element instanceof Exclusion) {
Exclusion exclusion = (Exclusion) element;
- return getImage(exclusion.getGroupId(), exclusion.getArtifactId(), null);
+ return getImage(exclusion.getGroupId(), exclusion.getArtifactId(), null, false);
} else if(element instanceof Extension) {
Extension extension = (Extension) element;
- return getImage(extension.getGroupId(), extension.getArtifactId(), extension.getVersion());
+ return getImage(extension.getGroupId(), extension.getArtifactId(), extension.getVersion(), false);
}
return null;
}
- private Image getImage(String groupId, String artifactId, String version) {
+ private Image getImage(String groupId, String artifactId, String version, boolean isManaged) {
// XXX need to resolve actual dependencies (i.e. inheritance, dependency management or properties)
// XXX need to handle version ranges
@@ -132,10 +180,10 @@ public class DependencyLabelProvider extends LabelProvider implements IColorProv
MavenProjectManager projectManager = MavenPlugin.getDefault().getMavenProjectManager();
IMavenProjectFacade projectFacade = projectManager.getMavenProject(groupId, artifactId, version);
if(projectFacade != null) {
- return MavenEditorImages.IMG_PROJECT;
+ return isManaged ? MavenImages.getOverlayImage(MavenImages.PATH_PROJECT, MavenImages.PATH_LOCK, IDecoration.BOTTOM_LEFT) : MavenEditorImages.IMG_PROJECT;
}
}
- return MavenEditorImages.IMG_JAR;
+ return isManaged ? MavenImages.getOverlayImage(MavenImages.PATH_JAR, MavenImages.PATH_LOCK, IDecoration.BOTTOM_LEFT) : MavenEditorImages.IMG_JAR;
}
private String getText(String groupId, String artifactId, String version, String classifier, String type, String scope) {
@@ -169,4 +217,6 @@ public class DependencyLabelProvider extends LabelProvider implements IColorProv
return s == null || s.trim().length() == 0;
}
+
+
}

Back to the top