diff options
author | Milos Kleint | 2011-01-12 16:09:25 +0000 |
---|---|---|
committer | Milos Kleint | 2011-01-12 16:09:25 +0000 |
commit | 1c1cc29b2d96973ebb7a6295e8f8d6db3be34706 (patch) | |
tree | 5c78c52db3fe02c9c112d1199eccfc27efcd8e0c /org.eclipse.m2e.editor | |
parent | 1069952db884a3078520c9efca64cb1ca86f0e82 (diff) | |
download | m2e-core-1c1cc29b2d96973ebb7a6295e8f8d6db3be34706.tar.gz m2e-core-1c1cc29b2d96973ebb7a6295e8f8d6db3be34706.tar.xz m2e-core-1c1cc29b2d96973ebb7a6295e8f8d6db3be34706.zip |
MNGECLIPSE-2734 have a field decorator for texts and CCombos that appears when there is an expression and upon hovering shows the resolved value
Diffstat (limited to 'org.eclipse.m2e.editor')
4 files changed, 143 insertions, 2 deletions
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/PluginsComposite.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/PluginsComposite.java index 9c824736..1be56b84 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/PluginsComposite.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/PluginsComposite.java @@ -488,6 +488,7 @@ public class PluginsComposite extends Composite{ gd_groupIdText.horizontalIndent = 4; groupIdText.setLayoutData(gd_groupIdText); groupIdText.setData("name", "groupIdText"); //$NON-NLS-1$ //$NON-NLS-2$ + parentEditorPage.createEvaluatorInfo(groupIdText); ProposalUtil.addGroupIdProposal(parentEditorPage.getProject(), groupIdText, Packaging.PLUGIN); M2EUtils.addRequiredDecoration(groupIdText); @@ -513,6 +514,7 @@ public class PluginsComposite extends Composite{ artifactIdText.setData("name", "artifactIdText"); //$NON-NLS-1$ //$NON-NLS-2$ ProposalUtil.addArtifactIdProposal(parentEditorPage.getProject(), groupIdText, artifactIdText, Packaging.PLUGIN); M2EUtils.addRequiredDecoration(artifactIdText); + parentEditorPage.createEvaluatorInfo(artifactIdText); Label label = toolkit.createLabel(pluginDetailsComposite, Messages.PluginsComposite_lblVersion, SWT.NONE); label.setLayoutData(new GridData()); @@ -524,6 +526,7 @@ public class PluginsComposite extends Composite{ versionText.setLayoutData(versionTextData); versionText.setData("name", "versionText"); //$NON-NLS-1$ //$NON-NLS-2$ ProposalUtil.addVersionProposal(parentEditorPage.getProject(), groupIdText, artifactIdText, versionText, Packaging.PLUGIN); + parentEditorPage.createEvaluatorInfo(versionText); // pluginSelectButton = toolkit.createButton(pluginDetailsComposite, "Select...", SWT.NONE); // pluginSelectButton.addSelectionListener(new SelectionAdapter() { @@ -714,6 +717,7 @@ public class PluginsComposite extends Composite{ executionIdText = toolkit.createText(executionComposite, null, SWT.NONE); executionIdText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + parentEditorPage.createEvaluatorInfo(executionIdText); toolkit.createLabel(executionComposite, Messages.PluginsComposite_lblPhase, SWT.NONE); diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/FormUtils.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/FormUtils.java index 00386856..6f030a68 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/FormUtils.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/FormUtils.java @@ -13,7 +13,14 @@ package org.eclipse.m2e.editor.pom; import java.net.MalformedURLException; import java.net.URL; - +import java.util.Arrays; +import java.util.Properties; + +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.interpolation.InterpolationException; +import org.codehaus.plexus.interpolation.PrefixedObjectValueSource; +import org.codehaus.plexus.interpolation.PropertiesBasedValueSource; +import org.codehaus.plexus.interpolation.RegexBasedInterpolator; import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.m2e.core.core.MavenLogger; @@ -259,5 +266,34 @@ public abstract class FormUtils { } } } + + /** + * copy pas + * @param project + * @param text + * @return + */ + //TODO copy pasted from PomTemplateContext + static String simpleInterpolate(MavenProject project, String text) { + if (text != null && text.contains("${")) { //$NON-NLS-1$ + //when expression is in the version but no project instance around + // just give up. + if(project == null) { + return null; + } + Properties props = project.getProperties(); + RegexBasedInterpolator inter = new RegexBasedInterpolator(); + if (props != null) { + inter.addValueSource(new PropertiesBasedValueSource(props)); + } + inter.addValueSource(new PrefixedObjectValueSource(Arrays.asList( new String[]{ "pom.", "project." } ), project.getModel(), false)); //$NON-NLS-1$ //$NON-NLS-2$ + try { + text = inter.interpolate(text); + } catch(InterpolationException e) { + text = null; + } + } + return text; + } } diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorPage.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorPage.java index 40521af8..2e3ad1e2 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorPage.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorPage.java @@ -19,6 +19,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.apache.maven.project.MavenProject; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; @@ -45,6 +46,9 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.fieldassist.ControlDecoration; +import org.eclipse.jface.fieldassist.FieldDecoration; +import org.eclipse.jface.fieldassist.FieldDecorationRegistry; import org.eclipse.jface.viewers.Viewer; import org.eclipse.m2e.core.MavenPlugin; import org.eclipse.m2e.core.actions.OpenPomAction; @@ -59,9 +63,12 @@ import org.eclipse.m2e.model.edit.pom.Model; import org.eclipse.m2e.model.edit.pom.Parent; import org.eclipse.m2e.model.edit.pom.PomPackage; import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CCombo; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseTrackListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; @@ -358,6 +365,69 @@ public abstract class MavenPomEditorPage extends FormPage implements Adapter { } } } + + /** + * creates a text field/Ccombo decoration that shows the evaluated value + * @param control + */ + public final void createEvaluatorInfo(final Control control) { + if (!(control instanceof Text || control instanceof CCombo)) { + throw new IllegalArgumentException("Not a Text or CCombo"); + } + FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration( + FieldDecorationRegistry.DEC_INFORMATION); + final ControlDecoration decoration = new ControlDecoration(control, SWT.RIGHT | SWT.TOP) { + + /* (non-Javadoc) + * @see org.eclipse.jface.fieldassist.ControlDecoration#getDescriptionText() + */ + @Override + public String getDescriptionText() { + MavenProject mp = getPomEditor().getMavenProject(); + if (mp != null) { + return FormUtils.simpleInterpolate(mp, control instanceof Text ? ((Text)control).getText() : ((CCombo)control).getText()); + } + return "Cannot interpolate expressions, not resolvable file."; + } + + }; + decoration.setShowOnlyOnFocus(false); + decoration.setImage(fieldDecoration.getImage()); + decoration.setShowHover(true); + decoration.hide(); //hide and wait for the value to be set. + decoration.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + decoration.showHoverText(decoration.getDescriptionText()); + } + }); + ModifyListener listener = new ModifyListener() { + public void modifyText(ModifyEvent e) { + String text = control instanceof Text ? ((Text)control).getText() : ((CCombo)control).getText(); + if (text.indexOf("${") != -1 && text.indexOf("}") != -1) { + decoration.show(); + } else { + decoration.hide(); + } + } + }; + if (control instanceof Text) { + ((Text)control).addModifyListener(listener); + } else { + ((CCombo)control).addModifyListener(listener); + } + control.addMouseTrackListener(new MouseTrackListener() { + public void mouseHover(MouseEvent e) { + decoration.showHoverText(decoration.getDescriptionText()); + } + + public void mouseExit(MouseEvent e) { + decoration.hideHover(); + } + + public void mouseEnter(MouseEvent e) { + } + }); + } public void dispose() { inputHistory.save(); diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/OverviewPage.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/OverviewPage.java index 60447cb2..45c13029 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/OverviewPage.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/OverviewPage.java @@ -20,6 +20,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.apache.maven.project.MavenProject; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath; @@ -39,6 +40,9 @@ import org.eclipse.emf.edit.command.SetCommand; import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.fieldassist.ControlDecoration; +import org.eclipse.jface.fieldassist.FieldDecoration; +import org.eclipse.jface.fieldassist.FieldDecorationRegistry; import org.eclipse.jface.viewers.ICellModifier; import org.eclipse.jface.viewers.IOpenListener; import org.eclipse.jface.viewers.OpenEvent; @@ -86,6 +90,7 @@ import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -267,6 +272,7 @@ public class OverviewPage extends MavenPomEditorPage { gd_artifactGroupIdText.horizontalIndent = 4; artifactGroupIdText.setLayoutData(gd_artifactGroupIdText); ProposalUtil.addGroupIdProposal(getProject(), artifactGroupIdText, Packaging.ALL); + createEvaluatorInfo(artifactGroupIdText); Label artifactIdLabel = toolkit.createLabel(artifactComposite, Messages.OverviewPage_lblArtifactId, SWT.NONE); @@ -276,6 +282,7 @@ public class OverviewPage extends MavenPomEditorPage { gd_artifactIdText.horizontalIndent = 4; artifactIdText.setLayoutData(gd_artifactIdText); M2EUtils.addRequiredDecoration(artifactIdText); + createEvaluatorInfo(artifactIdText); Label versionLabel = toolkit.createLabel(artifactComposite, Messages.OverviewPage_lblVersion, SWT.NONE); @@ -285,6 +292,7 @@ public class OverviewPage extends MavenPomEditorPage { gd_versionText.widthHint = 200; artifactVersionText.setLayoutData(gd_versionText); artifactVersionText.setData("name", "version"); //$NON-NLS-1$ //$NON-NLS-2$ + createEvaluatorInfo(artifactVersionText); Label packagingLabel = toolkit.createLabel(artifactComposite, Messages.OverviewPage_lblPackaging, SWT.NONE); @@ -316,6 +324,8 @@ public class OverviewPage extends MavenPomEditorPage { toolkit.paintBordersFor(artifactComposite); } + + private void createParentsection(FormToolkit toolkit, Composite composite, WidthGroup widthGroup) { parentSection = toolkit.createSection(composite, // @@ -415,6 +425,8 @@ public class OverviewPage extends MavenPomEditorPage { parentGroupIdText.setData("name", "parentGroupId"); //$NON-NLS-1$ //$NON-NLS-2$ ProposalUtil.addGroupIdProposal(getProject(), parentGroupIdText, Packaging.POM); M2EUtils.addRequiredDecoration(parentGroupIdText); + createEvaluatorInfo(parentGroupIdText); + final Label parentArtifactIdLabel = toolkit.createLabel(parentComposite, Messages.OverviewPage_lblArtifactId, SWT.NONE); @@ -426,6 +438,7 @@ public class OverviewPage extends MavenPomEditorPage { parentArtifactIdText.setData("name", "parentArtifactId"); //$NON-NLS-1$ //$NON-NLS-2$ ProposalUtil.addArtifactIdProposal(getProject(), parentGroupIdText, parentArtifactIdText, Packaging.POM); M2EUtils.addRequiredDecoration(parentArtifactIdText); + createEvaluatorInfo(parentArtifactIdText); Label parentVersionLabel = toolkit.createLabel(parentComposite, Messages.OverviewPage_lblVersion2, SWT.NONE); parentVersionLabel.setLayoutData(new GridData()); @@ -439,6 +452,8 @@ public class OverviewPage extends MavenPomEditorPage { ProposalUtil.addVersionProposal(getProject(), parentGroupIdText, parentArtifactIdText, parentVersionText, Packaging.POM); M2EUtils.addRequiredDecoration(parentVersionText); + createEvaluatorInfo(parentVersionText); + ModifyListener ml = new ModifyListener() { public void modifyText(ModifyEvent e) { @@ -482,6 +497,7 @@ public class OverviewPage extends MavenPomEditorPage { gd_parentRelativePathText.horizontalIndent = 4; parentRelativePathText.setLayoutData(gd_parentRelativePathText); parentRelativePathText.setData("name", "parentRelativePath"); //$NON-NLS-1$ //$NON-NLS-2$ + createEvaluatorInfo(parentRelativePathText); widthGroup.addControl(parentGroupIdLabel); widthGroup.addControl(parentArtifactIdLabel); @@ -721,6 +737,7 @@ public class OverviewPage extends MavenPomEditorPage { gd_projectNameText.widthHint = 150; projectNameText.setLayoutData(gd_projectNameText); projectNameText.setData("name", "projectName"); //$NON-NLS-1$ //$NON-NLS-2$ + createEvaluatorInfo(projectNameText); Hyperlink urlLabel = toolkit.createHyperlink(projectComposite, Messages.OverviewPage_lblUrl, SWT.NONE); urlLabel.addHyperlinkListener(new HyperlinkAdapter() { @@ -734,6 +751,7 @@ public class OverviewPage extends MavenPomEditorPage { gd_projectUrlText.widthHint = 150; projectUrlText.setLayoutData(gd_projectUrlText); projectUrlText.setData("name", "projectUrl"); //$NON-NLS-1$ //$NON-NLS-2$ + createEvaluatorInfo(projectUrlText); Label descriptionLabel = toolkit.createLabel(projectComposite, Messages.OverviewPage_lblDesc, SWT.NONE); descriptionLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); @@ -745,6 +763,7 @@ public class OverviewPage extends MavenPomEditorPage { gd_descriptionText.minimumHeight = 100; projectDescriptionText.setLayoutData(gd_descriptionText); projectDescriptionText.setData("name", "projectDescription"); //$NON-NLS-1$ //$NON-NLS-2$ + createEvaluatorInfo(projectDescriptionText); Label inceptionYearLabel = toolkit.createLabel(projectComposite, Messages.OverviewPage_lblInception, SWT.NONE); @@ -753,6 +772,7 @@ public class OverviewPage extends MavenPomEditorPage { gd_inceptionYearText.widthHint = 150; inceptionYearText.setLayoutData(gd_inceptionYearText); inceptionYearText.setData("name", "projectInceptionYear"); //$NON-NLS-1$ //$NON-NLS-2$ + createEvaluatorInfo(inceptionYearText); widthGroup.addControl(nameLabel); widthGroup.addControl(urlLabel); @@ -782,6 +802,7 @@ public class OverviewPage extends MavenPomEditorPage { gd_organizationNameText.widthHint = 150; organizationNameText.setLayoutData(gd_organizationNameText); organizationNameText.setData("name", "organizationName"); //$NON-NLS-1$ //$NON-NLS-2$ + createEvaluatorInfo(organizationNameText); Hyperlink organizationUrlLabel = toolkit.createHyperlink(organizationComposite, Messages.OverviewPage_lblUrl, SWT.NONE); @@ -796,6 +817,7 @@ public class OverviewPage extends MavenPomEditorPage { gd_organizationUrlText.widthHint = 150; organizationUrlText.setLayoutData(gd_organizationUrlText); organizationUrlText.setData("name", "organizationUrl"); //$NON-NLS-1$ //$NON-NLS-2$ + createEvaluatorInfo(organizationUrlText); widthGroup.addControl(organizationNameLabel); widthGroup.addControl(organizationUrlLabel); @@ -828,6 +850,7 @@ public class OverviewPage extends MavenPomEditorPage { gd_scmUrlText.widthHint = 150; scmUrlText.setLayoutData(gd_scmUrlText); scmUrlText.setData("name", "scmUrl"); //$NON-NLS-1$ //$NON-NLS-2$ + createEvaluatorInfo(scmUrlText); Label scmConnectionLabel = toolkit.createLabel(scmComposite, Messages.OverviewPage_lblConnection, SWT.NONE); @@ -836,6 +859,7 @@ public class OverviewPage extends MavenPomEditorPage { gd_scmConnectionText.widthHint = 150; scmConnectionText.setLayoutData(gd_scmConnectionText); scmConnectionText.setData("name", "scmConnection"); //$NON-NLS-1$ //$NON-NLS-2$ + createEvaluatorInfo(scmConnectionText); Label scmDevConnectionLabel = toolkit.createLabel(scmComposite, Messages.OverviewPage_lblDev, SWT.NONE); @@ -844,6 +868,7 @@ public class OverviewPage extends MavenPomEditorPage { gd_scmDevConnectionText.widthHint = 150; scmDevConnectionText.setLayoutData(gd_scmDevConnectionText); scmDevConnectionText.setData("name", "scmDevConnection"); //$NON-NLS-1$ //$NON-NLS-2$ + createEvaluatorInfo(scmDevConnectionText); Label scmTagLabel = toolkit.createLabel(scmComposite, Messages.OverviewPage_lblTag, SWT.NONE); @@ -852,7 +877,8 @@ public class OverviewPage extends MavenPomEditorPage { gd_scmTagText.widthHint = 150; scmTagText.setLayoutData(gd_scmTagText); scmTagText.setData("name", "scmTag"); //$NON-NLS-1$ //$NON-NLS-2$ - + createEvaluatorInfo(scmTagText); + widthGroup.addControl(scmUrlLabel); widthGroup.addControl(scmConnectionLabel); widthGroup.addControl(scmDevConnectionLabel); @@ -884,6 +910,7 @@ public class OverviewPage extends MavenPomEditorPage { addToHistory(issueManagementSystemCombo); toolkit.paintBordersFor(issueManagementSystemCombo); toolkit.adapt(issueManagementSystemCombo, true, true); + createEvaluatorInfo(issueManagementSystemCombo); Hyperlink issueManagementUrlLabel = toolkit.createHyperlink(issueManagementComposite, Messages.OverviewPage_lblUrl, SWT.NONE); @@ -902,6 +929,7 @@ public class OverviewPage extends MavenPomEditorPage { addToHistory(issueManagementUrlCombo); toolkit.paintBordersFor(issueManagementUrlCombo); toolkit.adapt(issueManagementUrlCombo, true, true); + createEvaluatorInfo(issueManagementUrlCombo); widthGroup.addControl(issueManagementSystemLabel); widthGroup.addControl(issueManagementUrlLabel); @@ -933,6 +961,7 @@ public class OverviewPage extends MavenPomEditorPage { addToHistory(ciManagementSystemCombo); toolkit.paintBordersFor(ciManagementSystemCombo); toolkit.adapt(ciManagementSystemCombo, true, true); + createEvaluatorInfo(ciManagementSystemCombo); Hyperlink ciManagementUrlLabel = toolkit.createHyperlink(ciManagementComposite, Messages.OverviewPage_lblUrl, SWT.NONE); @@ -951,6 +980,8 @@ public class OverviewPage extends MavenPomEditorPage { addToHistory(ciManagementUrlCombo); toolkit.paintBordersFor(ciManagementUrlCombo); toolkit.adapt(ciManagementUrlCombo, true, true); + createEvaluatorInfo(ciManagementUrlCombo); + widthGroup.addControl(ciManagementSystemLabel); widthGroup.addControl(ciManagementUrlLabel); |