Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilos Kleint2011-01-13 14:24:54 +0000
committerMilos Kleint2011-01-13 14:24:54 +0000
commitf169c9028ca35b1a7aa0b8faa2ea926ef60aaa3a (patch)
treed8b1d83e332a7688e1b54eec0178e888f0f86ce0 /org.eclipse.m2e.editor
parent02b8842dece8b84a52ad56a1e35f21aedfb1c977 (diff)
downloadm2e-core-f169c9028ca35b1a7aa0b8faa2ea926ef60aaa3a.tar.gz
m2e-core-f169c9028ca35b1a7aa0b8faa2ea926ef60aaa3a.tar.xz
m2e-core-f169c9028ca35b1a7aa0b8faa2ea926ef60aaa3a.zip
MNGECLIPSE-2717 show a decorator text/icon for managed versions. reverted the table-> tree conversion. Trees leave ugly space on left side for flat data. found a way to have styled text in tables as well..
Diffstat (limited to 'org.eclipse.m2e.editor')
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java11
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java65
-rw-r--r--org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorComposite.java17
3 files changed, 76 insertions, 17 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..d4dd3742 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
@@ -36,6 +36,7 @@ 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.DelegatingStyledCellLabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -122,7 +123,7 @@ public class DependenciesComposite extends Composite {
ValueProvider<DependencyManagement> dependencyManagementProvider;
- final DependencyLabelProvider dependencyLabelProvider = new DependencyLabelProvider();
+ final DependencyLabelProvider dependencyLabelProvider = new DependencyLabelProvider(true);
final DependencyLabelProvider dependencyManagementLabelProvider = new DependencyLabelProvider();
@@ -173,7 +174,7 @@ public class DependenciesComposite extends Composite {
dependenciesContentProvider.setComparator(dependenciesComparator);
dependenciesEditor = new DependenciesListComposite<Object>(dependenciesSection, SWT.NONE, true);
- dependenciesEditor.setLabelProvider(dependencyLabelProvider);
+ dependenciesEditor.setCellLabelProvider(new DelegatingStyledCellLabelProvider( dependencyLabelProvider));
dependenciesEditor.setContentProvider(dependenciesContentProvider);
dependenciesEditor.setRemoveButtonListener(new SelectionAdapter() {
@@ -755,10 +756,10 @@ public class DependenciesComposite extends Composite {
protected class PropertiesListComposite<T> extends ListEditorComposite<T> {
private static final String PROPERTIES_BUTTON_KEY = "PROPERTIES"; //$NON-NLS-1$
protected Button properties;
-
+
public PropertiesListComposite(Composite parent, int style, boolean includeSearch) {
super(parent, style, includeSearch);
- }
+ }
@Override
protected void createButtons(boolean includeSearch) {
@@ -883,4 +884,4 @@ public class DependenciesComposite extends Composite {
setDependenciesInput();
}
}
-}
+ }
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..e341c093 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;
@@ -25,10 +29,12 @@ import org.eclipse.m2e.editor.pom.MavenPomEditor;
import org.eclipse.m2e.model.edit.pom.Dependency;
import org.eclipse.m2e.model.edit.pom.Exclusion;
import org.eclipse.m2e.model.edit.pom.Extension;
+import org.eclipse.osgi.util.NLS;
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 +42,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 +80,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(NLS.bind(" (managed:{0})", version), StyledString.DECORATIONS_STYLER);
+ }
+ return ss;
+ }
+ return new StyledString(getText(element));
+ }
+
// LabelProvider
@Override
@@ -90,22 +138,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 +181,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 +218,6 @@ public class DependencyLabelProvider extends LabelProvider implements IColorProv
return s == null || s.trim().length() == 0;
}
+
+
}
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorComposite.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorComposite.java
index 45e64d0f..a23217c8 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorComposite.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorComposite.java
@@ -17,6 +17,7 @@ import java.util.List;
import java.util.Map;
import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ILabelProvider;
@@ -26,6 +27,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.m2e.editor.internal.Messages;
import org.eclipse.swt.SWT;
@@ -37,7 +39,6 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.forms.widgets.FormToolkit;
@@ -64,6 +65,8 @@ public class ListEditorComposite<T> extends Composite {
protected FormToolkit toolkit;
+ private TableViewerColumn column;
+
public ListEditorComposite(Composite parent, int style, boolean includeSearch) {
super(parent, style);
toolkit = new FormToolkit(parent.getDisplay());
@@ -76,15 +79,15 @@ public class ListEditorComposite<T> extends Composite {
final Table table = toolkit.createTable(this, SWT.FLAT | SWT.MULTI | style);
table.setData("name", "list-editor-composite-table"); //$NON-NLS-1$ //$NON-NLS-2$
- final TableColumn column = new TableColumn(table, SWT.NONE);
+
+ viewer = new TableViewer(table);
+ column = new TableViewerColumn(viewer, SWT.LEFT);
table.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
- column.setWidth(table.getClientArea().width);
+ column.getColumn().setWidth(table.getClientArea().width);
}
});
- viewer = new TableViewer(table);
-
createButtons(includeSearch);
int vSpan = buttons.size();
@@ -111,6 +114,10 @@ public class ListEditorComposite<T> extends Composite {
public void setLabelProvider(ILabelProvider labelProvider) {
viewer.setLabelProvider(labelProvider);
}
+
+ public void setCellLabelProvider(CellLabelProvider cell) {
+ column.setLabelProvider(cell);
+ }
public void setContentProvider(ListEditorContentProvider<T> contentProvider) {
viewer.setContentProvider(contentProvider);

Back to the top