diff options
author | Pascal Rapicault | 2010-12-06 22:10:52 +0000 |
---|---|---|
committer | Pascal Rapicault | 2010-12-06 22:10:52 +0000 |
commit | fbb4f5902cade92cc1689e73209c60a6413a5ef7 (patch) | |
tree | ace0fb107bafe980fc14fd7f3429e5c9aac2d795 /org.eclipse.m2e.editor/src/org/eclipse | |
parent | a9c878c2624b33d8c74062717bf75302f0ae1fa7 (diff) | |
download | m2e-core-fbb4f5902cade92cc1689e73209c60a6413a5ef7.tar.gz m2e-core-fbb4f5902cade92cc1689e73209c60a6413a5ef7.tar.xz m2e-core-fbb4f5902cade92cc1689e73209c60a6413a5ef7.zip |
Initial commit at Eclipse
Diffstat (limited to 'org.eclipse.m2e.editor/src/org/eclipse')
53 files changed, 16540 insertions, 0 deletions
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/MavenEditorImages.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/MavenEditorImages.java new file mode 100644 index 00000000..2597fa6c --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/MavenEditorImages.java @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +/** + * @author Eugene Kuleshov + */ +public class MavenEditorImages { + + // images + + public static final Image IMG_CLEAR = createImage("clear.gif"); //$NON-NLS-1$ + + public static final Image IMG_CLEAR_DISABLED = createImage("clear_disabled.gif"); //$NON-NLS-1$ + + public static final Image IMG_PROJECT = createImage("project_obj.gif"); //$NON-NLS-1$ + + // object images + + public static final Image IMG_JAR = createImage("jar_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_INHERITED = createImage("inherited_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_REPOSITORY = createImage("repository_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_PLUGIN = createImage("plugin_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_EXECUTION = createImage("execution_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_GOAL = createImage("goal_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_FILTER = createImage("filter_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_RESOURCE = createImage("resource_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_INCLUDE = createImage("include_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_EXCLUDE = createImage("exclude_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_PERSON = createImage("person_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_ROLE = createImage("role_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_PROPERTY = createImage("property_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_REPORT = createImage("report_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_PROFILE = createImage("profile_obj.gif"); //$NON-NLS-1$ + + public static final Image IMG_SCOPE = createImage("scope_obj.gif"); //$NON-NLS-1$ + + // image descriptors + + public static final ImageDescriptor REFRESH = create("refresh.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor COLLAPSE_ALL = create("collapseall.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor EXPAND_ALL = create("expandall.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor SHOW_GROUP = create("show_group.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor SHOW_INHERITED_DEPENDENCIES = create("show_inherited_dependencies.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor ADD_MODULE = create("new_project.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor ADD_ARTIFACT = create("new_jar.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor SELECT_ARTIFACT = create("select_jar.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor ADD_PLUGIN = create("new_plugin.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor SELECT_PLUGIN = create("select_plugin.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor SORT = create("sort.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor FILTER = create("filter.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor EFFECTIVE_POM = create("effective_pom.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor PARENT_POM = create("parent_pom.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor WEB_PAGE = create("web.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor HIERARCHY = create("hierarchy.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor SCOPE = create("scope.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor ADVANCED_TABS = create("advanced_tabs.gif"); //$NON-NLS-1$ + + public static final ImageDescriptor ELEMENT_OBJECT = create("element_obj.gif"); //$NON-NLS-1$ + + + private static ImageDescriptor create(String key) { + try { + ImageDescriptor imageDescriptor = createDescriptor(key); + ImageRegistry imageRegistry = getImageRegistry(); + if(imageRegistry!=null) { + imageRegistry.put(key, imageDescriptor); + } + return imageDescriptor; + } catch (Exception ex) { + MavenLogger.log(key, ex); + return null; + } + } + + private static Image createImage(String key) { + create(key); + ImageRegistry imageRegistry = getImageRegistry(); + return imageRegistry==null ? null : imageRegistry.get(key); + } + + private static ImageRegistry getImageRegistry() { + MavenEditorPlugin plugin = MavenEditorPlugin.getDefault(); + return plugin==null ? null : plugin.getImageRegistry(); + } + + private static ImageDescriptor createDescriptor(String image) { + return AbstractUIPlugin.imageDescriptorFromPlugin(MavenEditorPlugin.PLUGIN_ID, "icons/" + image); //$NON-NLS-1$ + } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/MavenEditorPlugin.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/MavenEditorPlugin.java new file mode 100644 index 00000000..2a1454e8 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/MavenEditorPlugin.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * @author Eugene Kuleshov + */ +public class MavenEditorPlugin extends AbstractUIPlugin { + + public static final String PLUGIN_ID = "org.eclipse.m2e.editor"; //$NON-NLS-1$ + + private static MavenEditorPlugin instance; + + public MavenEditorPlugin() { + } + + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + instance = this; + } + + @Override + public void stop(BundleContext context) throws Exception { + super.stop(context); + instance = null; + } + + public static MavenEditorPlugin getDefault() { + return instance; + } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/BuildComposite.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/BuildComposite.java new file mode 100644 index 00000000..a755dea2 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/BuildComposite.java @@ -0,0 +1,705 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.composites; + +import static org.eclipse.m2e.editor.pom.FormUtils.setButton; +import static org.eclipse.m2e.editor.pom.FormUtils.setText; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.command.RemoveCommand; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.jface.viewers.ICellModifier; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.editor.pom.FormUtils; +import org.eclipse.m2e.editor.pom.MavenPomEditorPage; +import org.eclipse.m2e.editor.pom.ValueProvider; +import org.eclipse.m2e.model.edit.pom.BuildBase; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.m2e.model.edit.pom.PomPackage; +import org.eclipse.m2e.model.edit.pom.Resource; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +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.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Section; + +/** + * @author Eugene Kuleshov + */ +public class BuildComposite extends Composite { + + protected static PomPackage POM_PACKAGE = PomPackage.eINSTANCE; + + private FormToolkit toolkit = new FormToolkit(Display.getCurrent()); + + MavenPomEditorPage parent; + + // controls + Text defaultGoalText; + Text directoryText; + Text finalNameText; + + ListEditorComposite<String> filtersEditor; + + ListEditorComposite<Resource> resourcesEditor; + ListEditorComposite<Resource> testResourcesEditor; + + Text resourceDirectoryText; + Text resourceTargetPathText; + ListEditorComposite<String> resourceIncludesEditor; + ListEditorComposite<String> resourceExcludesEditor; + + Button resourceFilteringButton; + Section resourceDetailsSection; + + // model + Resource currentResource; + + boolean changingSelection = false; + + ValueProvider<BuildBase> buildProvider; + + + public BuildComposite(Composite parent, int flags) { + super(parent, flags); + + toolkit.adapt(this); + + GridLayout layout = new GridLayout(); + layout.marginWidth = 0; + layout.makeColumnsEqualWidth = true; + setLayout(layout); + + createBuildSection(); + } + + private void createBuildSection() { + SashForm horizontalSash = new SashForm(this, SWT.NONE); + toolkit.adapt(horizontalSash); + horizontalSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + Section buildSection = toolkit.createSection(horizontalSash, ExpandableComposite.TITLE_BAR); + buildSection.setText(Messages.BuildComposite_section_build); + + Composite composite = toolkit.createComposite(buildSection, SWT.NONE); + GridLayout compositeLayout = new GridLayout(2, false); + compositeLayout.marginWidth = 1; + compositeLayout.marginHeight = 2; + composite.setLayout(compositeLayout); + toolkit.paintBordersFor(composite); + buildSection.setClient(composite); + + toolkit.createLabel(composite, Messages.BuildComposite_lblDefaultGoal, SWT.NONE); + + defaultGoalText = toolkit.createText(composite, null, SWT.NONE); + defaultGoalText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + toolkit.createLabel(composite, Messages.BuildComposite_lblDirectory, SWT.NONE); + + directoryText = toolkit.createText(composite, null, SWT.NONE); + directoryText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + toolkit.createLabel(composite, Messages.BuildComposite_lblFinalName, SWT.NONE); + + finalNameText = toolkit.createText(composite, null, SWT.NONE); + finalNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + Label filtersLabel = toolkit.createLabel(composite, Messages.BuildComposite_lblFilters, SWT.NONE); + filtersLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); + + filtersEditor = new ListEditorComposite<String>(composite, SWT.NONE); + GridData filtersEditorData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); + filtersEditorData.heightHint = 47; + filtersEditor.setLayoutData(filtersEditorData); + toolkit.adapt(filtersEditor); + toolkit.paintBordersFor(filtersEditor); + + filtersEditor.setContentProvider(new ListEditorContentProvider<String>()); + filtersEditor.setLabelProvider(new StringLabelProvider(MavenEditorImages.IMG_FILTER)); + + filtersEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + boolean created = false; + BuildBase build = createBuildBase(compoundCommand, editingDomain); + EList<String> filters = build.getFilters(); + + String filter = "?"; + + Command addCommand = AddCommand.create(editingDomain, build, POM_PACKAGE.getBuildBase_Filters(), filter); + compoundCommand.append(addCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + + if(created) { + filtersEditor.setInput(filters); + } + filtersEditor.setSelection(Collections.singletonList(filter)); + } + }); + + filtersEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + List<String> selection = filtersEditor.getSelection(); + for(String filter : selection) { + Command removeCommand = RemoveCommand.create(editingDomain, buildProvider.getValue(), // + POM_PACKAGE.getBuildBase_Filters(), filter); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + } + }); + + filtersEditor.setCellModifier(new ICellModifier() { + public boolean canModify(Object element, String property) { + return true; + } + + public Object getValue(Object element, String property) { + return element; + } + + public void modify(Object element, String property, Object value) { + int n = filtersEditor.getViewer().getTable().getSelectionIndex(); + EList<String> filters = buildProvider.getValue().getFilters(); + if(!value.equals(filters.get(n))) { + EditingDomain editingDomain = parent.getEditingDomain(); + Command command = SetCommand.create(editingDomain, buildProvider.getValue(), // + POM_PACKAGE.getBuildBase_Filters(), value, n); + editingDomain.getCommandStack().execute(command); + filtersEditor.refresh(); + } + } + }); + + /// + + SashForm verticalSash = new SashForm(horizontalSash, SWT.VERTICAL); + + createResourceSection(verticalSash); + createTestResourcesSection(verticalSash); + + verticalSash.setWeights(new int[] {1, 1}); + + createResourceDetailsSection(horizontalSash); + + horizontalSash.setWeights(new int[] {1, 1, 1}); + } + + private void createResourceDetailsSection(SashForm horizontalSash) { + resourceDetailsSection = toolkit.createSection(horizontalSash, ExpandableComposite.TITLE_BAR); + resourceDetailsSection.setText(Messages.BuildComposite_sectionResourceDetails); + + Composite resourceDetailsComposite = toolkit.createComposite(resourceDetailsSection, SWT.NONE); + GridLayout gridLayout = new GridLayout(2, false); + gridLayout.marginWidth = 1; + gridLayout.marginHeight = 2; + resourceDetailsComposite.setLayout(gridLayout); + toolkit.paintBordersFor(resourceDetailsComposite); + resourceDetailsSection.setClient(resourceDetailsComposite); + + Label resourceDirectoryLabel = toolkit.createLabel(resourceDetailsComposite, Messages.BuildComposite_lblDirectory, SWT.NONE); + resourceDirectoryLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); + + resourceDirectoryText = toolkit.createText(resourceDetailsComposite, null, SWT.NONE); + resourceDirectoryText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + Label resourceTargetPathLabel = toolkit.createLabel(resourceDetailsComposite, Messages.BuildComposite_lblTargetPath, SWT.NONE); + resourceTargetPathLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); + + resourceTargetPathText = toolkit.createText(resourceDetailsComposite, null, SWT.NONE); + resourceTargetPathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + resourceFilteringButton = toolkit.createButton(resourceDetailsComposite, Messages.BuildComposite_btnFiltering, SWT.CHECK); + resourceFilteringButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)); + + Label includesLabel = toolkit.createLabel(resourceDetailsComposite, Messages.BuildComposite_lblIncludes, SWT.NONE); + includesLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)); + + resourceIncludesEditor = new ListEditorComposite<String>(resourceDetailsComposite, SWT.NONE); + GridData includesEditorData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); + includesEditorData.heightHint = 60; + resourceIncludesEditor.setLayoutData(includesEditorData); + toolkit.adapt(resourceIncludesEditor); + toolkit.paintBordersFor(resourceIncludesEditor); + + resourceIncludesEditor.setContentProvider(new ListEditorContentProvider<String>()); + resourceIncludesEditor.setLabelProvider(new StringLabelProvider(MavenEditorImages.IMG_INCLUDE)); + + resourceIncludesEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + boolean created = false; + EList<String> includes = currentResource.getIncludes(); + + + String include = "?"; + Command addCommand = AddCommand.create(editingDomain, currentResource, POM_PACKAGE.getResource_Includes(), include); + compoundCommand.append(addCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + if(created) { + resourceIncludesEditor.setInput(includes); + } + resourceIncludesEditor.setSelection(Collections.singletonList(include)); + } + }); + + resourceIncludesEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + List<String> selection = resourceIncludesEditor.getSelection(); + for(String include : selection) { + Command removeCommand = RemoveCommand.create(editingDomain, currentResource, // + POM_PACKAGE.getResource_Includes(), include); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + } + }); + + resourceIncludesEditor.setCellModifier(new ICellModifier() { + public boolean canModify(Object element, String property) { + return true; + } + + public Object getValue(Object element, String property) { + return element; + } + + public void modify(Object element, String property, Object value) { + int n = resourceIncludesEditor.getViewer().getTable().getSelectionIndex(); + EList<String> includes = currentResource.getIncludes(); + if(!value.equals(includes.get(n))) { + EditingDomain editingDomain = parent.getEditingDomain(); + Command command = SetCommand.create(editingDomain, currentResource, // + POM_PACKAGE.getResource_Includes(), value, n); + editingDomain.getCommandStack().execute(command); + resourceIncludesEditor.refresh(); + } + } + }); + + Label excludesLabel = toolkit.createLabel(resourceDetailsComposite, Messages.BuildComposite_lblExcludes, SWT.NONE); + excludesLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)); + + resourceExcludesEditor = new ListEditorComposite<String>(resourceDetailsComposite, SWT.NONE); + GridData excludesEditorData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); + excludesEditorData.heightHint = 60; + resourceExcludesEditor.setLayoutData(excludesEditorData); + toolkit.adapt(resourceExcludesEditor); + toolkit.paintBordersFor(resourceExcludesEditor); + + resourceExcludesEditor.setContentProvider(new ListEditorContentProvider<String>()); + resourceExcludesEditor.setLabelProvider(new StringLabelProvider(MavenEditorImages.IMG_EXCLUDE)); + + resourceExcludesEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + boolean created = false; + EList<String> excludes = currentResource.getExcludes(); + + String exclude = "?"; + Command addCommand = AddCommand.create(editingDomain, currentResource, POM_PACKAGE.getResource_Excludes(), exclude); + compoundCommand.append(addCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + + if(created) { + resourceExcludesEditor.setInput(excludes); + } + resourceExcludesEditor.setSelection(Collections.singletonList(exclude)); + } + }); + + resourceExcludesEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + List<String> selection = resourceExcludesEditor.getSelection(); + for(String exclude : selection) { + Command removeCommand = RemoveCommand.create(editingDomain, currentResource, // + POM_PACKAGE.getResource_Excludes(), exclude); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + } + }); + + resourceExcludesEditor.setCellModifier(new ICellModifier() { + public boolean canModify(Object element, String property) { + return true; + } + + public Object getValue(Object element, String property) { + return element; + } + + public void modify(Object element, String property, Object value) { + int n = resourceExcludesEditor.getViewer().getTable().getSelectionIndex(); + EList<String> excludes = currentResource.getExcludes(); + if(!value.equals(excludes.get(n))) { + EditingDomain editingDomain = parent.getEditingDomain(); + Command command = SetCommand.create(editingDomain, currentResource, // + POM_PACKAGE.getResource_Excludes(), value, n); + editingDomain.getCommandStack().execute(command); + resourceExcludesEditor.refresh(); + } + } + }); + + } + + private void createResourceSection(SashForm verticalSash) { + Section resourcesSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR); + resourcesSection.setText(Messages.BuildComposite_sectionResources); + + resourcesEditor = new ListEditorComposite<Resource>(resourcesSection, SWT.NONE); + resourcesSection.setClient(resourcesEditor); + toolkit.adapt(resourcesEditor); + toolkit.paintBordersFor(resourcesEditor); + + resourcesEditor.setContentProvider(new ListEditorContentProvider<Resource>()); + resourcesEditor.setLabelProvider(new ResourceLabelProvider()); + + resourcesEditor.addSelectionListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + List<Resource> selection = resourcesEditor.getSelection(); + loadResourceDetails(selection.size()==1 ? selection.get(0) : null); + + if(!selection.isEmpty()) { + changingSelection = true; + try { + testResourcesEditor.setSelection(Collections.<Resource>emptyList()); + } finally { + changingSelection = false; + } + } + } + }); + + resourcesEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + boolean created = false; + BuildBase build = createBuildBase(compoundCommand, editingDomain); + EList<Resource> resources = build.getResources(); + + Resource resource = PomFactory.eINSTANCE.createResource(); + Command addCommand = AddCommand.create(editingDomain, build, POM_PACKAGE.getBuildBase_Resources(), resource); + compoundCommand.append(addCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + + if(created) { + resourcesEditor.setInput(resources); + } + resourcesEditor.setSelection(Collections.singletonList(resource)); + resourceDirectoryText.setFocus(); + } + }); + + resourcesEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + List<Resource> selection = resourcesEditor.getSelection(); + for(Resource resource : selection) { + Command removeCommand = RemoveCommand.create(editingDomain, buildProvider.getValue(), // + POM_PACKAGE.getBuildBase_Resources(), resource); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + } + }); + } + + private void createTestResourcesSection(SashForm verticalSash) { + Section testResourcesSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR); + testResourcesSection.setText(Messages.BuildComposite_sectionTestResources); + toolkit.adapt(verticalSash, true, true); + + testResourcesEditor = new ListEditorComposite<Resource>(testResourcesSection, SWT.NONE); + testResourcesSection.setClient(testResourcesEditor); + toolkit.adapt(testResourcesEditor); + toolkit.paintBordersFor(testResourcesEditor); + + testResourcesEditor.setContentProvider(new ListEditorContentProvider<Resource>()); + testResourcesEditor.setLabelProvider(new ResourceLabelProvider()); + + testResourcesEditor.addSelectionListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + List<Resource> selection = testResourcesEditor.getSelection(); + loadResourceDetails(selection.size()==1 ? selection.get(0) : null); + + if(!selection.isEmpty()) { + changingSelection = true; + try { + resourcesEditor.setSelection(Collections.<Resource>emptyList()); + } finally { + changingSelection = false; + } + } + } + }); + + testResourcesEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + boolean created = false; + BuildBase build = createBuildBase(compoundCommand, editingDomain); + EList<Resource> testResources = build.getTestResources(); + + Resource resource = PomFactory.eINSTANCE.createResource(); + Command addCommand = AddCommand.create(editingDomain, build, POM_PACKAGE.getBuildBase_TestResources(), resource); + compoundCommand.append(addCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + + if(created) { + testResourcesEditor.setInput(testResources); + } + testResourcesEditor.setSelection(Collections.singletonList(resource)); + resourceDirectoryText.setFocus(); + } + }); + + testResourcesEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + List<Resource> selection = testResourcesEditor.getSelection(); + for(Resource resource : selection) { + Command removeCommand = RemoveCommand.create(editingDomain, buildProvider.getValue(), // + POM_PACKAGE.getBuildBase_TestResources(), resource); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + } + }); + } + + public void loadData(MavenPomEditorPage editorPage, ValueProvider<BuildBase> buildProvider) { + this.parent = editorPage; + this.buildProvider = buildProvider; + + loadBuild(); + loadResources(); + loadTestResources(); + + loadResourceDetails(null); + + filtersEditor.setReadOnly(parent.isReadOnly()); + resourcesEditor.setReadOnly(parent.isReadOnly()); + testResourcesEditor.setReadOnly(parent.isReadOnly()); + + resourceIncludesEditor.setReadOnly(parent.isReadOnly()); + resourceExcludesEditor.setReadOnly(parent.isReadOnly()); + } + + public void updateView(MavenPomEditorPage editorPage, Notification notification) { + Object object = notification.getNotifier(); + + Object feature = notification.getFeature(); + + if(object instanceof BuildBase) { + loadBuild(); + } + + if(feature == PomPackage.Literals.BUILD_BASE__FILTERS) { + filtersEditor.refresh(); + } + + if(feature == PomPackage.Literals.BUILD_BASE__RESOURCES) { + resourcesEditor.refresh(); + } + + if(feature == PomPackage.Literals.BUILD_BASE__TEST_RESOURCES) { + testResourcesEditor.refresh(); + } + + if(object instanceof Resource) { + resourcesEditor.refresh(); + testResourcesEditor.refresh(); + if(object == currentResource) { + Object notificationObject = MavenPomEditorPage.getFromNotification(notification); + if(notificationObject == null || notificationObject instanceof Resource) { + loadResourceDetails((Resource) notificationObject); + } + } + } + + if(feature == PomPackage.Literals.RESOURCE__INCLUDES) { + resourceIncludesEditor.refresh(); + } + + if(feature == PomPackage.Literals.RESOURCE__EXCLUDES) { + resourceExcludesEditor.refresh(); + } + + // XXX handle other notification types + } + + private void loadBuild() { + if(parent != null) { + parent.removeNotifyListener(defaultGoalText); + parent.removeNotifyListener(directoryText); + parent.removeNotifyListener(finalNameText); + } + + BuildBase build = buildProvider.getValue(); + if(build!=null) { + setText(defaultGoalText, build.getDefaultGoal()); + setText(directoryText, build.getDirectory()); + setText(finalNameText, build.getFinalName()); + } else { + setText(defaultGoalText, ""); //$NON-NLS-1$ + setText(directoryText, ""); //$NON-NLS-1$ + setText(finalNameText, ""); //$NON-NLS-1$ + } + + filtersEditor.setInput(build == null // + || build.getFilters() == null ? null : build.getFilters()); + + parent.setModifyListener(defaultGoalText, buildProvider, POM_PACKAGE.getBuildBase_DefaultGoal(), ""); //$NON-NLS-1$ + parent.setModifyListener(directoryText, buildProvider, POM_PACKAGE.getBuildBase_Directory(), ""); //$NON-NLS-1$ + parent.setModifyListener(finalNameText, buildProvider, POM_PACKAGE.getBuildBase_FinalName(), ""); //$NON-NLS-1$ + } + + private void loadResources() { + BuildBase build = buildProvider.getValue(); + resourcesEditor.setInput(build == null // + || build.getResources() == null ? null : build.getResources()); + } + + private void loadTestResources() { + BuildBase build = buildProvider.getValue(); + testResourcesEditor.setInput(build == null // + || build.getTestResources() == null ? null : build.getTestResources()); + } + + void loadResourceDetails(Resource resource) { + if(changingSelection) { + return; + } + + currentResource = resource; + + if(parent != null) { + parent.removeNotifyListener(resourceDirectoryText); + parent.removeNotifyListener(resourceTargetPathText); + parent.removeNotifyListener(resourceFilteringButton); + } + + if(resource == null) { + FormUtils.setEnabled(resourceDetailsSection, false); + + setText(resourceDirectoryText, ""); //$NON-NLS-1$ + setText(resourceTargetPathText, ""); //$NON-NLS-1$ + setButton(resourceFilteringButton, false); + + resourceIncludesEditor.setInput(null); + resourceExcludesEditor.setInput(null); + + return; + } + + FormUtils.setEnabled(resourceDetailsSection, true); + FormUtils.setReadonly(resourceDetailsSection, parent.isReadOnly()); + + setText(resourceDirectoryText, resource.getDirectory()); + setText(resourceTargetPathText, resource.getTargetPath()); + setButton(resourceFilteringButton, "true".equals(resource.getFiltering())); + + resourceIncludesEditor.setInput(resource.getIncludes()==null ? null : resource.getIncludes()); + resourceExcludesEditor.setInput(resource.getExcludes()==null ? null : resource.getExcludes()); + + ValueProvider<Resource> provider = new ValueProvider.DefaultValueProvider<Resource>(resource); + parent.setModifyListener(resourceDirectoryText, provider, POM_PACKAGE.getResource_Directory(), ""); //$NON-NLS-1$ + parent.setModifyListener(resourceTargetPathText, provider, POM_PACKAGE.getResource_TargetPath(), ""); //$NON-NLS-1$ + parent.setModifyListener(resourceFilteringButton, provider, POM_PACKAGE.getResource_Filtering(), "false"); + + parent.registerListeners(); + } + + BuildBase createBuildBase(CompoundCommand compoundCommand, EditingDomain editingDomain) { + BuildBase build = buildProvider.getValue(); + if(build == null) { + build = buildProvider.create(editingDomain, compoundCommand); + } + return build; + } + + /** + * Label provider for {@link Resource} + */ + public class ResourceLabelProvider extends LabelProvider { + + public String getText(Object element) { + if(element instanceof Resource) { + return ((Resource) element).getDirectory(); + } + return super.getText(element); + } + + public Image getImage(Object element) { + return MavenEditorImages.IMG_RESOURCE; + } + + } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComparator.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComparator.java new file mode 100644 index 00000000..dd43add5 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComparator.java @@ -0,0 +1,80 @@ +package org.eclipse.m2e.editor.composites; + +import java.util.Comparator; + +import org.eclipse.m2e.model.edit.pom.Dependency; + +public class DependenciesComparator<T> implements Comparator<T> { + + private boolean sortByGroups = true; + + public int compare(T o1, T o2) { + String[] gav1; + String[] gav2; + + if (o1 instanceof Dependency) { + gav1 = toGAV((Dependency) o1); + } else { + gav1 = toGAV((org.apache.maven.model.Dependency) o1); + } + + if (o2 instanceof Dependency) { + gav2 = toGAV((Dependency) o2); + } else { + gav2 = toGAV((org.apache.maven.model.Dependency) o2); + } + + return compareGAVs(gav1, gav2); + } + + protected String[] toGAV(Dependency dep) { + String[] gav = new String[3]; + gav[0] = dep.getGroupId(); + gav[1] = dep.getArtifactId(); + gav[2] = dep.getVersion(); + return gav; + } + + protected String[] toGAV(org.apache.maven.model.Dependency dep) { + String[] gav = new String[3]; + gav[0] = dep.getGroupId(); + gav[1] = dep.getArtifactId(); + gav[2] = dep.getVersion(); + return gav; + } + + protected int compareGAVs(String[] gav1, String[] gav2) { + + String g1 = gav1[0] == null ? "" : gav1[0]; //$NON-NLS-1$ + String g2 = gav2[0] == null ? "" : gav2[0]; //$NON-NLS-1$ + + String a1 = gav1[1] == null ? "" : gav1[1]; //$NON-NLS-1$ + String a2 = gav2[1] == null ? "" : gav2[1]; //$NON-NLS-1$ + + String v1 = gav1[2] == null ? "" : gav1[2]; //$NON-NLS-1$ + String v2 = gav2[2] == null ? "" : gav2[2]; //$NON-NLS-1$ + + return compareDependencies(g1, a1, v1, g2, a2, v2); + } + + protected int compareDependencies(String group1, String artifact1, String version1, + String group2, String artifact2, String version2) { + int comp = 0; + if (sortByGroups && (comp = group1.compareTo(group2)) != 0) { + return comp; + } + if ((comp = artifact1.compareTo(artifact2)) != 0) { + return comp; + } + + return version1.compareTo(version2); + } + + /** + * Set this to false to ignore groupIDs while sorting + * @param sortByGroups + */ + public void setSortByGroups(boolean sortByGroups) { + this.sortByGroups = sortByGroups; + } +}
\ No newline at end of file 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 new file mode 100644 index 00000000..687462c2 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependenciesComposite.java @@ -0,0 +1,954 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.composites; + +import static org.eclipse.m2e.editor.pom.FormUtils.nvl; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.project.MavenProject; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.command.RemoveCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.window.Window; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.embedder.IMaven; +import org.eclipse.m2e.core.index.IIndex; +import org.eclipse.m2e.core.index.IndexedArtifactFile; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectManager; +import org.eclipse.m2e.core.ui.dialogs.AddDependencyDialog; +import org.eclipse.m2e.core.ui.dialogs.EditDependencyDialog; +import org.eclipse.m2e.core.ui.dialogs.MavenRepositorySearchDialog; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.MavenEditorPlugin; +import org.eclipse.m2e.editor.dialogs.ManageDependenciesDialog; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.editor.pom.MavenPomEditor; +import org.eclipse.m2e.editor.pom.MavenPomEditor.Callback; +import org.eclipse.m2e.editor.pom.MavenPomEditorPage; +import org.eclipse.m2e.editor.pom.SearchControl; +import org.eclipse.m2e.editor.pom.SearchMatcher; +import org.eclipse.m2e.editor.pom.ValueProvider; +import org.eclipse.m2e.model.edit.pom.Dependency; +import org.eclipse.m2e.model.edit.pom.DependencyManagement; +import org.eclipse.m2e.model.edit.pom.Model; +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.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.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Section; +import org.sonatype.aether.graph.DependencyNode; + + +/** + * @author Eugene Kuleshov + */ +public class DependenciesComposite extends Composite { + + protected static PomPackage POM_PACKAGE = PomPackage.eINSTANCE; + + protected MavenPomEditorPage editorPage; + + MavenPomEditor pomEditor; + + private FormToolkit toolkit = new FormToolkit(Display.getCurrent()); + + // controls + + PropertiesListComposite<Dependency> dependencyManagementEditor; + + //This ListComposite takes both m2e and maven Dependencies + DependenciesListComposite<Object> dependenciesEditor; + + Button dependencySelectButton; + + Action dependencySelectAction; + + SearchControl searchControl; + + SearchMatcher searchMatcher; + + DependencyFilter searchFilter; + + Action openWebPageAction; + + // model + + Model model; + + MavenProject mavenProject; + + ValueProvider<DependencyManagement> dependencyManagementProvider; + + DependencyLabelProvider dependencyLabelProvider = new DependencyLabelProvider(); + + DependencyLabelProvider dependencyManagementLabelProvider = new DependencyLabelProvider(); + + protected boolean showInheritedDependencies = false; + IMavenProjectFacade facade = null; + + ListEditorContentProvider<Object> dependenciesContentProvider = new ListEditorContentProvider<Object>(); + + DependenciesComparator<Object> dependenciesComparator; + + ListEditorContentProvider<Dependency> dependencyManagementContentProvider = new ListEditorContentProvider<Dependency>(); + + DependenciesComparator<Dependency> dependencyManagementComparator; + + public DependenciesComposite(Composite composite, MavenPomEditorPage editorPage, int flags, MavenPomEditor pomEditor) { + super(composite, flags); + this.editorPage = editorPage; + this.pomEditor = pomEditor; + createComposite(); + editorPage.initPopupMenu(dependenciesEditor.getViewer(), ".dependencies"); //$NON-NLS-1$ + editorPage.initPopupMenu(dependencyManagementEditor.getViewer(), ".dependencyManagement"); //$NON-NLS-1$ + } + + private void createComposite() { + GridLayout gridLayout = new GridLayout(); + gridLayout.makeColumnsEqualWidth = true; + gridLayout.marginWidth = 0; + setLayout(gridLayout); + toolkit.adapt(this); + + SashForm horizontalSash = new SashForm(this, SWT.NONE); + GridData horizontalCompositeGridData = new GridData(SWT.FILL, SWT.FILL, true, true); + horizontalCompositeGridData.heightHint = 200; + horizontalSash.setLayoutData(horizontalCompositeGridData); + toolkit.adapt(horizontalSash, true, true); + + createDependenciesSection(horizontalSash); + createDependencyManagementSection(horizontalSash); + + horizontalSash.setWeights(new int[] {1, 1}); + } + + private void createDependenciesSection(SashForm verticalSash) { + Section dependenciesSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR); + dependenciesSection.marginWidth = 3; + dependenciesSection.setText(Messages.DependenciesComposite_sectionDependencies); + + dependenciesComparator = new DependenciesComparator<Object>(); + dependenciesContentProvider.setComparator(dependenciesComparator); + + dependenciesEditor = new DependenciesListComposite<Object>(dependenciesSection, SWT.NONE, true); + dependenciesEditor.setLabelProvider(dependencyLabelProvider); + dependenciesEditor.setContentProvider(dependenciesContentProvider); + + dependenciesEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = editorPage.getEditingDomain(); + + List<Object> dependencyList = dependenciesEditor.getSelection(); + for(Object obj : dependencyList) { + if (obj instanceof Dependency) { + Dependency dependency = (Dependency) obj; + Command removeCommand = RemoveCommand.create(editingDomain, model, POM_PACKAGE.getModel_Dependencies(), + dependency); + compoundCommand.append(removeCommand); + } else if (obj instanceof org.apache.maven.model.Dependency) { + /* + * TODO: Support a refactoring of removing an inherited/managed dependency. + */ + } + } + + editingDomain.getCommandStack().execute(compoundCommand); + setDependenciesInput(); + } + }); + + dependenciesEditor.setPropertiesListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + Object selection = dependenciesEditor.getSelection().get(0); + if (selection instanceof Dependency) { + Dependency dependency = (Dependency) selection; + EditDependencyDialog d = new EditDependencyDialog(getShell(), false, editorPage.getEditingDomain(), editorPage + .getProject()); + d.setDependency(dependency); + if(d.open() == Window.OK) { + setDependenciesInput(); + dependenciesEditor.setSelection(Collections.singletonList((Object) dependency)); + } + } else if (selection instanceof org.apache.maven.model.Dependency) { + /* + * TODO: Support editing or displaying of inherited/managed dependencies. + */ + } + } + }); + + dependenciesSection.setClient(dependenciesEditor); + toolkit.adapt(dependenciesEditor); + toolkit.paintBordersFor(dependenciesEditor); + + dependenciesEditor.setManageButtonListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + try { + openManageDependenciesDialog(); + } catch(InvocationTargetException e1) { + MavenEditorPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, "Error: ", e1)); //$NON-NLS-1$ + } catch(InterruptedException e1) { + MavenEditorPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, "Error: ", e1)); //$NON-NLS-1$ + } + } + }); + + dependenciesEditor.setAddButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + final AddDependencyDialog addDepDialog = new AddDependencyDialog(getShell(), false, editorPage.getProject()); + + /* + * Load the dependency tree for the dialog so it can show already + * added transitive dependencies. + */ + Runnable runnable = new Runnable() { + + public void run() { + pomEditor.loadDependencies(new Callback() { + + public void onFinish(DependencyNode node) { + addDepDialog.setDepdencyNode(node); + } + + public void onException(CoreException ex) { + MavenLogger.log(ex); + } + }, Artifact.SCOPE_TEST); + } + }; + + addDepDialog.onLoad(runnable); + + if(addDepDialog.open() == Window.OK) { + List<Dependency> deps = addDepDialog.getDependencies(); + for(Dependency dep : deps) { + setupDependency(new ValueProvider<Model>() { + @Override + public Model getValue() { + return model; + } + }, POM_PACKAGE.getModel_Dependencies(), dep); + } + setDependenciesInput(); + dependenciesEditor.setSelection(Collections.singletonList((Object) deps.get(0))); + } + } + + }); + + ToolBarManager modulesToolBarManager = new ToolBarManager(SWT.FLAT); + + modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_sortAlphabetically, MavenEditorImages.SORT) { + { + setChecked(false); + } + + @Override + public int getStyle() { + return AS_CHECK_BOX; + } + + @Override + public void run() { + dependenciesContentProvider.setShouldSort(isChecked()); + dependenciesEditor.getViewer().refresh(); + } + }); + + modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_showInheritedDependencies, + MavenEditorImages.SHOW_INHERITED_DEPENDENCIES) { + { + setChecked(false); + } + + @Override + public int getStyle() { + return AS_CHECK_BOX; + } + + @Override + public void run() { + if (isChecked()) { + IRunnableWithProgress projectLoader = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + facade = readMavenProject(monitor); + if (facade == null) { + return; + } + dependencyLabelProvider.setFacade(facade); + showInheritedDependencies = true; + + Display.getDefault().asyncExec(new Runnable() { + + public void run() { + ISelection selection = dependenciesEditor.getViewer().getSelection(); + setDependenciesInput(); + dependenciesEditor.getViewer().refresh(); + dependenciesEditor.getViewer().setSelection(selection, true); + } + }); + } catch(CoreException e) { + throw new InvocationTargetException(e); + } + } + }; + + + try { + PlatformUI.getWorkbench().getProgressService().run(true, true, projectLoader); + } catch(InvocationTargetException e) { + MavenEditorPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, null, e)); + } catch(InterruptedException e) { + MavenEditorPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, null, e)); + } + + if (facade == null || facade.getMavenProject() == null + || facade.getMavenProject().getModel() == null) { + /* + * If this is null here, there was an exception thrown during + * readMavenProject above, so we should uncheck the button + */ + setChecked(false); + } + } else { + showInheritedDependencies = false; + ISelection selection = dependenciesEditor.getViewer().getSelection(); + setDependenciesInput(); + dependenciesEditor.getViewer().setSelection(selection, true); + } + } + }); + + modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_showgroupid, + MavenEditorImages.SHOW_GROUP) { + { + setChecked(false); + dependenciesComparator.setSortByGroups(false); + } + + public int getStyle() { + return AS_CHECK_BOX; + } + + public void run() { + dependencyLabelProvider.setShowGroupId(isChecked()); + dependenciesComparator.setSortByGroups(isChecked()); + dependenciesEditor.getViewer().refresh(); + } + }); + + modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_filter, MavenEditorImages.FILTER) { + { + setChecked(true); + } + + public int getStyle() { + return AS_CHECK_BOX; + } + + public void run() { + TableViewer viewer = dependenciesEditor.getViewer(); + if(isChecked()) { + viewer.addFilter(searchFilter); + } else { + viewer.removeFilter(searchFilter); + } + viewer.refresh(); + if(isChecked()) { + searchControl.getSearchText().setFocus(); + } + } + }); + + Composite toolbarComposite = toolkit.createComposite(dependenciesSection); + GridLayout toolbarLayout = new GridLayout(1, true); + toolbarLayout.marginHeight = 0; + toolbarLayout.marginWidth = 0; + toolbarComposite.setLayout(toolbarLayout); + toolbarComposite.setBackground(null); + + modulesToolBarManager.createControl(toolbarComposite); + dependenciesSection.setTextClient(toolbarComposite); + } + + private void createDependencyManagementSection(SashForm verticalSash) { + Section dependencyManagementSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR); + dependencyManagementSection.marginWidth = 3; + dependencyManagementSection.setText(Messages.DependenciesComposite_sectionDependencyManagement); + + dependencyManagementEditor = new PropertiesListComposite<Dependency>(dependencyManagementSection, SWT.NONE, true); + dependencyManagementSection.setClient(dependencyManagementEditor); + + dependencyManagementComparator = new DependenciesComparator<Dependency>(); + dependencyManagementContentProvider.setComparator(dependencyManagementComparator); + dependencyManagementEditor.setLabelProvider(dependencyManagementLabelProvider); + dependencyManagementEditor.setContentProvider(dependencyManagementContentProvider); + + dependencyManagementEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = editorPage.getEditingDomain(); + + List<Dependency> dependencyList = dependencyManagementEditor.getSelection(); + for(Dependency dependency : dependencyList) { + Command removeCommand = RemoveCommand.create(editingDomain, // + dependencyManagementProvider.getValue(), POM_PACKAGE.getDependencyManagement_Dependencies(), dependency); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + } + }); + + dependencyManagementEditor.setPropertiesListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + Dependency dependency = dependencyManagementEditor.getSelection().get(0); + EditDependencyDialog d = new EditDependencyDialog(getShell(), true, editorPage.getEditingDomain(), editorPage + .getProject()); + d.setDependency(dependency); + if(d.open() == Window.OK) { + dependencyManagementEditor.setInput(dependencyManagementProvider.getValue().getDependencies()); + dependencyManagementEditor.setSelection(Collections.singletonList(dependency)); + } + } + }); + + dependencyManagementEditor.addSelectionListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + List<Dependency> selection = dependencyManagementEditor.getSelection(); + + if(!selection.isEmpty()) { + dependenciesEditor.setSelection(Collections.<Object> emptyList()); + } + } + }); + + toolkit.adapt(dependencyManagementEditor); + toolkit.paintBordersFor(dependencyManagementEditor); + + dependencyManagementEditor.setAddButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + // TODO calculate current list of artifacts for the project + Set<ArtifactKey> artifacts = Collections.emptySet(); + MavenRepositorySearchDialog dialog = new MavenRepositorySearchDialog(getShell(), // + Messages.DependenciesComposite_searchDialog_title, IIndex.SEARCH_ARTIFACT, artifacts, true); + if(dialog.open() == Window.OK) { + IndexedArtifactFile af = (IndexedArtifactFile) dialog.getFirstResult(); + if(af != null) { + Dependency dependency = createDependency(dependencyManagementProvider, + POM_PACKAGE.getDependencyManagement_Dependencies(), // + af.group, af.artifact, af.version, af.classifier, "jar".equals(nvl(af.type)) ? "" : nvl(af.type), //$NON-NLS-1$ //$NON-NLS-2$ + "compile".equals(nvl(dialog.getSelectedScope())) ? "" : nvl(dialog.getSelectedScope()));//$NON-NLS-1$ //$NON-NLS-2$ + dependencyManagementEditor.setInput(dependencyManagementProvider.getValue().getDependencies()); + dependencyManagementEditor.setSelection(Collections.singletonList(dependency)); + } + } + } + }); + + ToolBarManager modulesToolBarManager = new ToolBarManager(SWT.FLAT); + + modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_sortAlphabetically, MavenEditorImages.SORT) { + { + setChecked(false); + dependencyManagementContentProvider.setShouldSort(false); + } + + @Override + public int getStyle() { + return AS_CHECK_BOX; + } + + @Override + public void run() { + dependencyManagementContentProvider.setShouldSort(isChecked()); + dependencyManagementEditor.getViewer().refresh(); + } + }); + + modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_showgroupid, + MavenEditorImages.SHOW_GROUP) { + { + setChecked(false); + dependencyManagementComparator.setSortByGroups(false); + } + + public int getStyle() { + return AS_CHECK_BOX; + } + + public void run() { + dependencyManagementLabelProvider.setShowGroupId(isChecked()); + dependencyManagementComparator.setSortByGroups(isChecked()); + dependencyManagementEditor.getViewer().refresh(); + } + }); + + modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_filter, MavenEditorImages.FILTER) { + { + setChecked(true); + } + + public int getStyle() { + return AS_CHECK_BOX; + } + + public void run() { + TableViewer viewer = dependencyManagementEditor.getViewer(); + if(isChecked()) { + viewer.addFilter(searchFilter); + } else { + viewer.removeFilter(searchFilter); + } + viewer.refresh(); + if(isChecked()) { + searchControl.getSearchText().setFocus(); + } + } + }); + + Composite toolbarComposite = toolkit.createComposite(dependencyManagementSection); + GridLayout toolbarLayout = new GridLayout(1, true); + toolbarLayout.marginHeight = 0; + toolbarLayout.marginWidth = 0; + toolbarComposite.setLayout(toolbarLayout); + toolbarComposite.setBackground(null); + + modulesToolBarManager.createControl(toolbarComposite); + dependencyManagementSection.setTextClient(toolbarComposite); + } + + + @SuppressWarnings("unchecked") + public void loadData(Model model, ValueProvider<DependencyManagement> dependencyManagementProvider) { + this.model = model; + this.dependencyManagementProvider = dependencyManagementProvider; + this.dependencyLabelProvider.setPomEditor(editorPage.getPomEditor()); + this.dependencyManagementLabelProvider.setPomEditor(editorPage.getPomEditor()); + + dependenciesEditor.setInput((List<Object>)(List<?>)model.getDependencies()); + + DependencyManagement dependencyManagement = dependencyManagementProvider.getValue(); + dependencyManagementEditor.setInput(dependencyManagement == null ? null : dependencyManagement.getDependencies()); + + dependenciesEditor.setReadOnly(editorPage.isReadOnly()); + dependencyManagementEditor.setReadOnly(editorPage.isReadOnly()); + + if(searchControl != null) { + searchControl.getSearchText().setEditable(true); + } + } + + public void updateView(final MavenPomEditorPage editorPage, final Notification notification) { + Display.getDefault().asyncExec(new Runnable() { + @SuppressWarnings("unchecked") + public void run() { + EObject object = (EObject) notification.getNotifier(); + + // XXX event is not received when <dependencies> is deleted in XML + if(object instanceof Model) { + Model model2 = (Model) object; + + if(model2.getDependencyManagement() != null && dependencyManagementEditor.getInput() == null) { + dependencyManagementEditor.setInput(model2.getDependencyManagement().getDependencies()); + } else if(model2.getDependencyManagement() == null) { + dependencyManagementEditor.setInput(null); + } + + if(model2.getDependencies() != null && dependenciesEditor.getInput() == null) { + dependenciesEditor.setInput((List<Object>)(List<?>)model2.getDependencies()); + } else if(model2.getDependencies() == null) { + dependenciesEditor.setInput(null); + } + + dependenciesEditor.refresh(); + dependencyManagementEditor.refresh(); + } + + if(object instanceof DependencyManagement) { + if(dependenciesEditor.getInput() == null) { + dependenciesEditor.setInput((List<Object>)(List<?>)((DependencyManagement) object).getDependencies()); + } + dependencyManagementEditor.refresh(); + } + } + }); + } + + void setupDependency(ValueProvider<? extends EObject> parentProvider, EReference feature, Dependency dependency) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = editorPage.getEditingDomain(); + + EObject parent = parentProvider.getValue(); + if(parent == null) { + parent = parentProvider.create(editingDomain, compoundCommand); + } + + Command addDependencyCommand = AddCommand.create(editingDomain, parent, feature, dependency); + compoundCommand.append(addDependencyCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + } + + Dependency createDependency(ValueProvider<? extends EObject> parentProvider, EReference feature, String groupId, + String artifactId, String version, String classifier, String type, String scope) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = editorPage.getEditingDomain(); + + EObject parent = parentProvider.getValue(); + if(parent == null) { + parent = parentProvider.create(editingDomain, compoundCommand); + } + + Dependency dependency = PomFactory.eINSTANCE.createDependency(); + dependency.setGroupId(groupId); + dependency.setArtifactId(artifactId); + dependency.setVersion(version); + dependency.setClassifier(classifier); + dependency.setType(type); + dependency.setScope(scope); + + Command addDependencyCommand = AddCommand.create(editingDomain, parent, feature, dependency); + compoundCommand.append(addDependencyCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + + return dependency; + } + + public void setSearchControl(SearchControl searchControl) { + if(this.searchControl != null) { + return; + } + + this.searchMatcher = new SearchMatcher(searchControl); + this.searchFilter = new DependencyFilter(searchMatcher); + this.searchControl = searchControl; + this.searchControl.getSearchText().addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + selectDepenendencies(dependenciesEditor, model, POM_PACKAGE.getModel_Dependencies()); + selectDepenendencies(dependencyManagementEditor, dependencyManagementProvider.getValue(), + POM_PACKAGE.getDependencyManagement_Dependencies()); + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + private void selectDepenendencies(ListEditorComposite<?> editor, EObject parent, + EStructuralFeature feature) { + if(parent != null) { + editor.setSelection((List) parent.eGet(feature)); + editor.refresh(); + } + } + }); + //we add filter here as the default behaviour is to filter.. + TableViewer viewer = dependenciesEditor.getViewer(); + viewer.addFilter(searchFilter); + viewer = dependencyManagementEditor.getViewer(); + viewer.addFilter(searchFilter); + + } + + String getVersion(String groupId, String artifactId, IProgressMonitor monitor) { + try { + MavenProject mavenProject = editorPage.getPomEditor().readMavenProject(false, monitor); + Artifact a = mavenProject.getArtifactMap().get(groupId + ":" + artifactId); //$NON-NLS-1$ + if(a != null) { + return a.getBaseVersion(); + } + } catch(CoreException ex) { + MavenLogger.log(ex); + } + return null; + } + + public static class DependencyFilter extends ViewerFilter { + private SearchMatcher searchMatcher; + + public DependencyFilter(SearchMatcher searchMatcher) { + this.searchMatcher = searchMatcher; + } + + public boolean select(Viewer viewer, Object parentElement, Object element) { + if(element instanceof Dependency) { + Dependency d = (Dependency) element; + return searchMatcher.isMatchingArtifact(d.getGroupId(), d.getArtifactId()); + } else if (element instanceof org.apache.maven.model.Dependency) { + org.apache.maven.model.Dependency dependency = (org.apache.maven.model.Dependency) element; + return searchMatcher.isMatchingArtifact(dependency.getGroupId(), dependency.getArtifactId()); + } + return false; + } + } + + void openManageDependenciesDialog() throws InvocationTargetException, InterruptedException { + /* + * A linked list representing the path from child to root parent pom. + * The head is the child, the tail is the root pom + */ + final LinkedList<MavenProject> hierarchy = new LinkedList<MavenProject>(); + + IRunnableWithProgress projectLoader = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + try { + IMavenProjectFacade projectFacade = readMavenProject(monitor); + hierarchy.addAll(new ParentGatherer(mavenProject, projectFacade).getParentHierarchy(monitor)); + } catch(CoreException e) { + throw new InvocationTargetException(e); + } + } + }; + + PlatformUI.getWorkbench().getProgressService().run(false, true, projectLoader); + + if (hierarchy.isEmpty()) { + //We were unable to read the project metadata above, so there was an error. + //User has already been notified to fix the problem. + return; + } + + final ManageDependenciesDialog manageDepDialog = new ManageDependenciesDialog(getShell(), model, hierarchy, + pomEditor.getEditingDomain()); + manageDepDialog.open(); + } + + /** + * Attempts to completely load the current MavenProject so as to get at the + * effective pom. + * + * In the case where the MavenProject cannot be accessed and markers are present, + * it will inform the user that they need to fix the problems before they can + * proceed. + * + * @param monitor + * @return the IMavenProjectFacade that corresponds to the project, or null if one was not loaded. + * @throws CoreException + */ + protected IMavenProjectFacade readMavenProject(IProgressMonitor monitor) throws CoreException { + IMaven maven = MavenPlugin.getDefault().getMaven(); + MavenProjectManager projectManager = MavenPlugin.getDefault().getMavenProjectManager(); + mavenProject = pomEditor.readMavenProject(false, monitor); + if (mavenProject == null) { + IMarker[] markers = pomEditor.getPomFile().findMarkers(IMavenConstants.MARKER_ID, true, IResource.DEPTH_ZERO); + if (markers != null && markers.length > 0) { + Display.getDefault().asyncExec(new Runnable() { + + public void run() { + MessageDialog.openError(getShell(), Messages.DependenciesComposite_error, Messages.DependenciesComposite_fixProjectErrors); + } + }); + return null; + } else { + Display.getDefault().asyncExec(new Runnable() { + + public void run() { + MessageDialog.openError(getShell(), Messages.DependenciesComposite_error, Messages.DependenciesComposite_checkConsoleForErrors); + } + }); + return null; + } + } else { + maven.detachFromSession(mavenProject); + } + IMavenProjectFacade projectFacade = projectManager.create(pomEditor.getPomFile(), true, monitor); + return projectFacade; + } + + protected void setDependenciesInput() { + List<Object> deps = new ArrayList<Object>(model.getDependencies()); + if (showInheritedDependencies) { + + /* + * Add the inherited dependencies into the bunch. But don't we need to + * filter out the dependencies that are duplicated in the M2E model, so + * we need to run through each list and only add ones that aren't in both. + */ + List<org.apache.maven.model.Dependency> allDeps = new LinkedList<org.apache.maven.model.Dependency>(); + allDeps.addAll(facade.getMavenProject().getModel().getDependencies()); + allDeps.addAll(facade.getMavenProject().getModel().getDependencyManagement().getDependencies()); + for (org.apache.maven.model.Dependency mavenDep : allDeps) { + boolean found = false; + Iterator<Dependency> iter = model.getDependencies().iterator(); + while (!found && iter.hasNext()) { + Dependency m2eDep = iter.next(); + if (mavenDep.getGroupId().equals(m2eDep.getGroupId()) + && mavenDep.getArtifactId().equals(m2eDep.getArtifactId()) + && mavenDep.getVersion().equals(m2eDep.getVersion())) { + found = true; + } + } + if (!found) { + deps.add(mavenDep); + } + } + } + dependenciesEditor.setInput(deps); + } + + 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) { + if(includeSearch) { + createAddButton(); + } + createRemoveButton(); + properties = createButton(Messages.ListEditorComposite_btnProperties); + addButton(PROPERTIES_BUTTON_KEY, properties); + } + + public void setPropertiesListener(SelectionListener listener) { + properties.addSelectionListener(listener); + } + + @Override + protected void viewerSelectionChanged() { + super.viewerSelectionChanged(); + updatePropertiesButton(); + } + + protected void updatePropertiesButton() { + boolean enable = !viewer.getSelection().isEmpty() && !isBadSelection(); + 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); + updatePropertiesButton(); + } + + /** + * Returns true if the viewer has no input or if there is currently + * an inherited dependency selected + * @return + */ + protected boolean isBadSelection() { + @SuppressWarnings("unchecked") + List<Object> deps = (List<Object>) viewer.getInput(); + if (deps == null || deps.isEmpty()) { + return true; + } + boolean bad = false; + IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); + @SuppressWarnings("unchecked") + Iterator<Object> iter = selection.iterator(); + while (iter.hasNext()) { + Object obj = iter.next(); + if (obj instanceof org.apache.maven.model.Dependency) { + bad = true; + break; + } + } + return bad; + } + } + + protected class DependenciesListComposite<T> extends PropertiesListComposite<T> { + + private static final String MANAGE = "MANAGE"; //$NON-NLS-1$ + protected Button manage; + + public DependenciesListComposite(Composite parent, int style, boolean includeSearch) { + super(parent, style, includeSearch); + } + + @Override + protected void createButtons(boolean includeSearch) { + super.createButtons(includeSearch); + manage = createButton(Messages.DependenciesComposite_manageButton); + addButton(MANAGE, manage); + } + + @Override + protected void viewerSelectionChanged() { + super.viewerSelectionChanged(); + updateManageButton(); + } + + @Override + public void setReadOnly(boolean readOnly) { + super.setReadOnly(readOnly); + updateManageButton(); + } + + protected void updateManageButton() { + manage.setEnabled(!readOnly && model.getDependencies() != null && !model.getDependencies().isEmpty()); + } + + public void setManageButtonListener(SelectionListener listener) { + manage.addSelectionListener(listener); + } + } +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyDetailComposite.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyDetailComposite.java new file mode 100644 index 00000000..525af9b8 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyDetailComposite.java @@ -0,0 +1,323 @@ + +package org.eclipse.m2e.editor.composites; + +import static org.eclipse.m2e.editor.pom.FormUtils.nvl; +import static org.eclipse.m2e.editor.pom.FormUtils.setButton; +import static org.eclipse.m2e.editor.pom.FormUtils.setText; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.project.MavenProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.m2e.core.actions.OpenPomAction; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.util.M2EUtils; +import org.eclipse.m2e.core.util.ProposalUtil; +import org.eclipse.m2e.core.util.search.Packaging; +import org.eclipse.m2e.core.wizards.WidthGroup; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.editor.pom.FormUtils; +import org.eclipse.m2e.editor.pom.MavenPomEditorPage; +import org.eclipse.m2e.editor.pom.ValueProvider; +import org.eclipse.m2e.model.edit.pom.Dependency; +import org.eclipse.m2e.model.edit.pom.PomPackage; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.events.HyperlinkAdapter; +import org.eclipse.ui.forms.events.HyperlinkEvent; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Hyperlink; + + +public class DependencyDetailComposite extends Composite { + + protected static PomPackage POM_PACKAGE = PomPackage.eINSTANCE; + + private MavenPomEditorPage editorPage; + + private FormToolkit toolkit; + + private WidthGroup detailsWidthGroup = new WidthGroup(); + + protected Text groupIdText; + + protected Text artifactIdText; + + protected Text versionText; + + private Text classifierText; + + private CCombo typeCombo; + + private CCombo scopeCombo; + + private Text systemPathText; + + private Button selectSystemPathButton; + + private Button optionalButton; + + public DependencyDetailComposite(Composite parent, MavenPomEditorPage editorPage) { + super(parent, SWT.NONE); + + this.editorPage = editorPage; + toolkit = editorPage.getManagedForm().getToolkit(); +// toolkit = new FormToolkit(Display.getCurrent()); + + GridLayout dependencyCompositeLayout = new GridLayout(3, false); + dependencyCompositeLayout.marginWidth = 2; + dependencyCompositeLayout.marginHeight = 2; + setLayout(dependencyCompositeLayout); + addControlListener(detailsWidthGroup); + + createControls(); + + toolkit.paintBordersFor(this); + toolkit.adapt(this); + } + + protected String getVersion(String groupId, String artifactId, IProgressMonitor monitor) { + try { + MavenProject mavenProject = editorPage.getPomEditor().readMavenProject(false, monitor); + Artifact a = mavenProject.getArtifactMap().get(groupId + ":" + artifactId); //$NON-NLS-1$ + if(a != null) { + return a.getBaseVersion(); + } + } catch(CoreException ex) { + MavenLogger.log(ex); + } + return null; + } + + private void createControls() { + Label groupIdLabel = toolkit.createLabel(this, Messages.DependenciesComposite_lblGroupId, SWT.NONE); + groupIdLabel.setLayoutData(new GridData()); + detailsWidthGroup.addControl(groupIdLabel); + + groupIdText = toolkit.createText(this, null, SWT.NONE); + GridData gd_groupIdText = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1); + gd_groupIdText.horizontalIndent = 4; + groupIdText.setLayoutData(gd_groupIdText); + ProposalUtil.addGroupIdProposal(editorPage.getProject(), groupIdText, Packaging.ALL); + M2EUtils.addRequiredDecoration(groupIdText); + + Hyperlink artifactIdHyperlink = toolkit.createHyperlink(this, Messages.DependenciesComposite_lblArtifactId, + SWT.NONE); + artifactIdHyperlink.setLayoutData(new GridData()); + artifactIdHyperlink.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + final String groupId = groupIdText.getText(); + final String artifactId = artifactIdText.getText(); + final String version = versionText.getText(); + new Job("Opening " + groupId + ":" + artifactId + ":" + version) { + protected IStatus run(IProgressMonitor monitor) { + OpenPomAction.openEditor(groupId, artifactId, // + version != null ? version : getVersion(groupId, artifactId, monitor), // + monitor); + return Status.OK_STATUS; + } + }.schedule(); + } + }); + + detailsWidthGroup.addControl(artifactIdHyperlink); + + artifactIdText = toolkit.createText(this, null, SWT.NONE); + GridData gd_artifactIdText = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1); + gd_artifactIdText.horizontalIndent = 4; + artifactIdText.setLayoutData(gd_artifactIdText); + ProposalUtil.addArtifactIdProposal(editorPage.getProject(), groupIdText, artifactIdText, Packaging.ALL); + M2EUtils.addRequiredDecoration(artifactIdText); + + Label versionLabel = toolkit.createLabel(this, Messages.DependenciesComposite_lblVersion, SWT.NONE); + versionLabel.setLayoutData(new GridData()); + detailsWidthGroup.addControl(versionLabel); + + versionText = toolkit.createText(this, null, SWT.NONE); + GridData versionTextData = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1); + versionTextData.horizontalIndent = 4; + versionTextData.widthHint = 200; + versionText.setLayoutData(versionTextData); + ProposalUtil.addVersionProposal(editorPage.getProject(), groupIdText, artifactIdText, versionText, Packaging.ALL); + + Label classifierLabel = toolkit.createLabel(this, Messages.DependenciesComposite_lblClassifier, SWT.NONE); + classifierLabel.setLayoutData(new GridData()); + detailsWidthGroup.addControl(classifierLabel); + + classifierText = toolkit.createText(this, null, SWT.NONE); + GridData gd_classifierText = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1); + gd_classifierText.horizontalIndent = 4; + gd_classifierText.widthHint = 200; + classifierText.setLayoutData(gd_classifierText); + ProposalUtil.addClassifierProposal(editorPage.getProject(), groupIdText, artifactIdText, versionText, + classifierText, Packaging.ALL); + + Label typeLabel = toolkit.createLabel(this, Messages.DependenciesComposite_lblType, SWT.NONE); + typeLabel.setLayoutData(new GridData()); + detailsWidthGroup.addControl(typeLabel); + + typeCombo = new CCombo(this, SWT.FLAT); + // FormUtils.addTypeProposal(groupIdText, artifactIdText, versionText, typeCombo, Packaging.ALL); + + // TODO retrieve artifact type from selected dependency + typeCombo.add("jar"); //$NON-NLS-1$ + typeCombo.add("war"); //$NON-NLS-1$ + typeCombo.add("rar"); //$NON-NLS-1$ + typeCombo.add("ear"); //$NON-NLS-1$ + typeCombo.add("par"); //$NON-NLS-1$ + typeCombo.add("ejb"); //$NON-NLS-1$ + typeCombo.add("ejb-client"); //$NON-NLS-1$ + typeCombo.add("test-jar"); //$NON-NLS-1$ + typeCombo.add("java-source"); //$NON-NLS-1$ + typeCombo.add("javadoc"); //$NON-NLS-1$ + typeCombo.add("maven-plugin"); //$NON-NLS-1$ + typeCombo.add("pom"); //$NON-NLS-1$ + + GridData gd_typeText = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1); + gd_typeText.horizontalIndent = 4; + gd_typeText.widthHint = 120; + typeCombo.setLayoutData(gd_typeText); + typeCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + toolkit.adapt(typeCombo, true, true); + + Label scopeLabel = toolkit.createLabel(this, Messages.DependenciesComposite_lblScope, SWT.NONE); + scopeLabel.setLayoutData(new GridData()); + detailsWidthGroup.addControl(scopeLabel); + + scopeCombo = new CCombo(this, SWT.READ_ONLY | SWT.FLAT); + scopeCombo.add("compile"); //$NON-NLS-1$ + scopeCombo.add("test"); //$NON-NLS-1$ + scopeCombo.add("provided"); //$NON-NLS-1$ + scopeCombo.add("runtime"); //$NON-NLS-1$ + scopeCombo.add("system"); //$NON-NLS-1$ + // TODO should be only used on a dependency of type pom in the <dependencyManagement> section + scopeCombo.add("import"); //$NON-NLS-1$ + + GridData gd_scopeText = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1); + gd_scopeText.horizontalIndent = 4; + gd_scopeText.widthHint = 120; + scopeCombo.setLayoutData(gd_scopeText); + scopeCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + toolkit.adapt(scopeCombo, true, true); + + Label systemPathLabel = toolkit.createLabel(this, Messages.DependenciesComposite_lblSystemPath, SWT.NONE); + systemPathLabel.setLayoutData(new GridData()); + detailsWidthGroup.addControl(systemPathLabel); + + systemPathText = toolkit.createText(this, null, SWT.NONE); + GridData gd_systemPathText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_systemPathText.horizontalIndent = 4; + gd_systemPathText.widthHint = 200; + systemPathText.setLayoutData(gd_systemPathText); + + selectSystemPathButton = toolkit.createButton(this, Messages.DependenciesComposite_btnSelect, SWT.NONE); + new Label(this, SWT.NONE); + + optionalButton = toolkit.createButton(this, Messages.DependenciesComposite_btnOptional, SWT.CHECK); + GridData gd_optionalButton = new GridData(SWT.LEFT, SWT.TOP, false, false, 2, 1); + gd_optionalButton.horizontalIndent = 4; + optionalButton.setLayoutData(gd_optionalButton); + + setTabList(new Control[] {groupIdText, artifactIdText, versionText, classifierText, typeCombo, scopeCombo, + systemPathText, selectSystemPathButton, optionalButton}); + } + + protected void update(Dependency dependency) { + if(editorPage != null) { + editorPage.removeNotifyListener(groupIdText); + editorPage.removeNotifyListener(artifactIdText); + editorPage.removeNotifyListener(versionText); + editorPage.removeNotifyListener(classifierText); + editorPage.removeNotifyListener(typeCombo); + editorPage.removeNotifyListener(scopeCombo); + editorPage.removeNotifyListener(systemPathText); + editorPage.removeNotifyListener(optionalButton); + } + + if(editorPage == null || dependency == null) { + FormUtils.setEnabled(this, true); + + setText(groupIdText, ""); //$NON-NLS-1$ + setText(artifactIdText, ""); //$NON-NLS-1$ + setText(versionText, ""); //$NON-NLS-1$ + setText(classifierText, ""); //$NON-NLS-1$ + setText(typeCombo, ""); //$NON-NLS-1$ + setText(scopeCombo, ""); //$NON-NLS-1$ + setText(systemPathText, ""); //$NON-NLS-1$ + setButton(optionalButton, false); + + return; + } + + FormUtils.setEnabled(this, true); + FormUtils.setReadonly(this, editorPage.isReadOnly()); + + setText(groupIdText, dependency.getGroupId()); + setText(artifactIdText, dependency.getArtifactId()); + setText(versionText, dependency.getVersion()); + setText(classifierText, dependency.getClassifier()); + setText(typeCombo, "".equals(nvl(dependency.getType())) ? "jar" : dependency.getType()); + setText(scopeCombo, "".equals(nvl(dependency.getScope())) ? "compile" : dependency.getScope()); + setText(systemPathText, dependency.getSystemPath()); + + boolean optional = Boolean.parseBoolean(dependency.getOptional()); + if(optionalButton.getSelection() != optional) { + optionalButton.setSelection(optional); + } + + // set new listeners + ValueProvider<Dependency> dependencyProvider = new ValueProvider.DefaultValueProvider<Dependency>(dependency); + editorPage.setModifyListener(groupIdText, dependencyProvider, POM_PACKAGE.getDependency_GroupId(), ""); //$NON-NLS-1$ + editorPage.setModifyListener(artifactIdText, dependencyProvider, POM_PACKAGE.getDependency_ArtifactId(), ""); //$NON-NLS-1$ + editorPage.setModifyListener(versionText, dependencyProvider, POM_PACKAGE.getDependency_Version(), ""); //$NON-NLS-1$ + editorPage.setModifyListener(classifierText, dependencyProvider, POM_PACKAGE.getDependency_Classifier(), ""); //$NON-NLS-1$ + editorPage.setModifyListener(typeCombo, dependencyProvider, POM_PACKAGE.getDependency_Type(), "jar"); //$NON-NLS-1$ + editorPage.setModifyListener(scopeCombo, dependencyProvider, POM_PACKAGE.getDependency_Scope(), "compile"); //$NON-NLS-1$ + editorPage.setModifyListener(systemPathText, dependencyProvider, POM_PACKAGE.getDependency_SystemPath(), ""); //$NON-NLS-1$ + editorPage.setModifyListener(optionalButton, dependencyProvider, POM_PACKAGE.getDependency_Optional(), "false"); + + editorPage.registerListeners(); + } + + public void setGroupId(String groupId) { + groupIdText.setText(nvl(groupId)); + } + + public String getGroupId() { + return groupIdText.getText(); + } + + public void setArtifactId(String artifactId) { + artifactIdText.setText(nvl(artifactId)); + } + + public String getArtifactId() { + return artifactIdText.getText(); + } + + public void setVersion(String version) { + versionText.setText(nvl(version)); + } + + public String getVersion() { + return versionText.getText(); + } + + public void setType(String type) { + typeCombo.setText(nvl(type)); + } + + public void setScope(String scope) { + scopeCombo.setText(nvl(scope)); + } +} 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 new file mode 100644 index 00000000..15280b70 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/DependencyLabelProvider.java @@ -0,0 +1,249 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.composites; + +import java.util.Collection; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Model; +import org.apache.maven.project.MavenProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.viewers.IColorProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectManager; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.MavenEditorPlugin; +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.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; + + +/** + * Label provider for Dependency, Exclusion and Extension elements + * + * @author Eugene Kuleshov + */ +public class DependencyLabelProvider extends LabelProvider implements IColorProvider { + + private MavenPomEditor pomEditor; + + private boolean showGroupId = false; + + private IMavenProjectFacade facade = null; + + public void setPomEditor(MavenPomEditor pomEditor) { + this.pomEditor = pomEditor; + } + + public void setShowGroupId(boolean showGroupId) { + this.showGroupId = showGroupId; + } + + // IColorProvider + + public Color getForeground(Object element) { + if(element instanceof Dependency) { + Dependency dependency = (Dependency) element; + String scope = dependency.getScope(); + if(scope != null && !"compile".equals(scope)) { //$NON-NLS-1$ + return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); + } + } else if (element instanceof org.apache.maven.model.Dependency) { + if (facade == null || facade.getMavenProject() == null + || facade.getMavenProject().getModel() == null) { + //If facade is null and we are getting maven Dependencies, something has gone horribly wrong + return Display.getDefault().getSystemColor(SWT.COLOR_RED); + } + + if(!isInherited((org.apache.maven.model.Dependency) element)) { + return null; + } + + /* + * Element is inherited, therefore we cannot edit it (yet ...) + */ + + return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); + } + return null; + } + + protected boolean isInherited(org.apache.maven.model.Dependency dependency) { + if (dependency.getLocation("") == null) { //$NON-NLS-1$ + MavenEditorPlugin.getDefault().getLog().log( + new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, + "getLocation(\"\") for dependency '"+dependency.toString()+"' is null. This is a bug in Maven.")); //$NON-NLS-1$ //$NON-NLS-2$ + return false; + } + + if (dependency.getLocation("").getSource() == null) { //$NON-NLS-1$ + MavenEditorPlugin.getDefault().getLog().log( + new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, + "getLocation(\"\").getSource() for dependency '"+dependency.toString()+"' is null. This is a bug in Maven.")); //$NON-NLS-1$ //$NON-NLS-2$ + return false; + } + + String modelID = dependency.getLocation("").getSource().getModelId(); //$NON-NLS-1$ + Model model = facade.getMavenProject().getModel(); + String thisModelID = toModelID(model.getGroupId(), model.getArtifactId(), model.getVersion()); + + return (!thisModelID.equals(modelID)); + } + + public static String toModelID(String groupId, String artifactId, String version) { + /* + * Copied straight from package org.apache.maven.model.building.ModelProblemUtils.toId() + * TODO Remove this method when those methods are made public + */ + StringBuilder buffer = new StringBuilder( 96 ); + + buffer.append( ( groupId != null && groupId.length() > 0 ) ? groupId : "[unknown-group-id]" ); //$NON-NLS-1$ + buffer.append( ':' ); + buffer.append( ( artifactId != null && artifactId.length() > 0 ) ? artifactId : "[unknown-artifact-id]" ); //$NON-NLS-1$ + buffer.append( ':' ); + buffer.append( ( version != null && version.length() > 0 ) ? version : "[unknown-version]" ); //$NON-NLS-1$ + + return buffer.toString(); + } + + public Color getBackground(Object element) { + return null; + } + + // LabelProvider + + @Override + public String getText(Object element) { + if(element instanceof Dependency) { + Dependency dependency = (Dependency) element; + return getText(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), // + dependency.getClassifier(), dependency.getType(), dependency.getScope()); + } else if (element instanceof org.apache.maven.model.Dependency) { + org.apache.maven.model.Dependency dependency = (org.apache.maven.model.Dependency) element; + return getText(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), + dependency.getClassifier(), dependency.getType(), dependency.getScope()); + } else if(element instanceof Exclusion) { + Exclusion exclusion = (Exclusion) element; + return getText(exclusion.getGroupId(), exclusion.getArtifactId(), null, null, null, null); + } else if(element instanceof Extension) { + Extension extension = (Extension) element; + return getText(extension.getGroupId(), extension.getArtifactId(), extension.getVersion(), null, null, null); + } + return super.getText(element); + } + + @Override + public Image getImage(Object element) { + if(element instanceof Dependency) { + Dependency dependency = (Dependency) element; + return getImage(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()); + } else if (element instanceof org.apache.maven.model.Dependency) { + org.apache.maven.model.Dependency dependency = (org.apache.maven.model.Dependency) element; + if (isInherited(dependency)) { + return MavenEditorImages.IMG_INHERITED; + } + return getImage(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()); + }else if(element instanceof Exclusion) { + Exclusion exclusion = (Exclusion) element; + return getImage(exclusion.getGroupId(), exclusion.getArtifactId(), null); + } else if(element instanceof Extension) { + Extension extension = (Extension) element; + return getImage(extension.getGroupId(), extension.getArtifactId(), extension.getVersion()); + } + + return null; + } + + private Image getImage(String groupId, String artifactId, String version) { + // XXX need to resolve actual dependencies (i.e. inheritance, dependency management or properties) + // XXX need to handle version ranges + + if((version == null || version.indexOf("${") > -1) && pomEditor != null) { //$NON-NLS-1$ + try { + MavenProject mavenProject = pomEditor.readMavenProject(false, null); + if(mavenProject != null) { + Artifact artifact = mavenProject.getArtifactMap().get(groupId + ":" + artifactId); //$NON-NLS-1$ + if(artifact!=null) { + version = artifact.getVersion(); + } + if(version==null || version.indexOf("${") > -1) { //$NON-NLS-1$ + Collection<Artifact> artifacts = mavenProject.getManagedVersionMap().values(); + for(Artifact a : artifacts) { + if(a.getGroupId().equals(groupId) && a.getArtifactId().equals(artifactId)) { + version = a.getVersion(); + break; + } + } + } + } + } catch(CoreException ex) { + MavenLogger.log(ex); + } + } + + if(groupId != null && artifactId != null && version != null) { + MavenProjectManager projectManager = MavenPlugin.getDefault().getMavenProjectManager(); + IMavenProjectFacade projectFacade = projectManager.getMavenProject(groupId, artifactId, version); + if(projectFacade != null) { + return MavenEditorImages.IMG_PROJECT; + } + } + return MavenEditorImages.IMG_JAR; + } + + private String getText(String groupId, String artifactId, String version, String classifier, String type, String scope) { + StringBuilder sb = new StringBuilder(); + + if(showGroupId) { + sb.append(isEmpty(groupId) ? "?" : groupId).append(" : "); //$NON-NLS-1$ //$NON-NLS-2$ + } + sb.append(isEmpty(artifactId) ? "?" : artifactId); //$NON-NLS-1$ + + if(!isEmpty(version)) { + sb.append(" : ").append(version); //$NON-NLS-1$ + } + + if(!isEmpty(classifier)) { + sb.append(" : ").append(classifier); //$NON-NLS-1$ + } + + if(!isEmpty(type)) { + sb.append(" : ").append(type); //$NON-NLS-1$ + } + + if(!isEmpty(scope)) { + sb.append(" [").append(scope).append(']'); //$NON-NLS-1$ + } + + return sb.toString(); + } + + private boolean isEmpty(String s) { + return s == null || s.trim().length() == 0; + } + + public void setFacade(IMavenProjectFacade facade) { + this.facade = facade; + } + + +} 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 new file mode 100644 index 00000000..f9b12fe4 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorComposite.java @@ -0,0 +1,263 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.composites; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.viewers.CellEditor; +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.ISelectionChangedListener; +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.TextCellEditor; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +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; + + +/** + * List editor composite + * + * @author Eugene Kuleshov + */ +public class ListEditorComposite<T> extends Composite { + + + TableViewer 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 ListEditorComposite(Composite parent, int style, boolean 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 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); + table.addControlListener(new ControlAdapter() { + public void controlResized(ControlEvent e) { + column.setWidth(table.getClientArea().width); + } + }); + + viewer = new TableViewer(table); + + 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; + table.setLayoutData(viewerData); + viewer.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.TRUE); + + viewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + viewerSelectionChanged(); + } + }); + + toolkit.paintBordersFor(this); + } + + public ListEditorComposite(Composite parent, int style) { + this(parent, style, false); + } + + public void setLabelProvider(ILabelProvider labelProvider) { + viewer.setLabelProvider(labelProvider); + } + + public void setContentProvider(ListEditorContentProvider<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 TableViewer getViewer() { + return viewer; + } + + public int getSelectionIndex() { + return viewer.getTable().getSelectionIndex(); + } + + public void setSelectionIndex(int n) { + viewer.getTable().setSelection(n); + } + + @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 setReadOnly(boolean 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 { + entry.getValue().setEnabled(!readOnly); + } + } + } + + protected void viewerSelectionChanged() { + updateRemoveButton(); + } + + protected void updateRemoveButton() { + getRemoveButton().setEnabled(!readOnly && !viewer.getSelection().isEmpty()); + } + + public void refresh() { + if(!viewer.getTable().isDisposed()) { + viewer.refresh(true); + } + } + + public void setCellModifier(ICellModifier cellModifier) { + viewer.setColumnProperties(new String[] {"?"}); //$NON-NLS-1$ + + TextCellEditor editor = new TextCellEditor(viewer.getTable()); + viewer.setCellEditors(new CellEditor[] {editor}); + viewer.setCellModifier(cellModifier); + } + + public void setDoubleClickListener(IDoubleClickListener listener) { + viewer.addDoubleClickListener(listener); + } + + /** + * 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(); + } + createCreateButton(); + createRemoveButton(); + } + + 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; + } +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorContentProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorContentProvider.java new file mode 100644 index 00000000..735755c8 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ListEditorContentProvider.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.composites; + +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/** + * @author Eugene Kuleshov + */ +public class ListEditorContentProvider<T> implements IStructuredContentProvider { + + public static final Object[] EMPTY = new Object[0]; + private boolean shouldSort; + private Comparator<T> comparator; + + @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 void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + public void dispose() { + } + + 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/ManageDependencyLabelProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ManageDependencyLabelProvider.java new file mode 100644 index 00000000..15556e45 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ManageDependencyLabelProvider.java @@ -0,0 +1,14 @@ +package org.eclipse.m2e.editor.composites; + +import org.eclipse.swt.graphics.Color; + +public class ManageDependencyLabelProvider extends DependencyLabelProvider { + @Override + public Color getForeground(Object element) { + /* + * Super class shows scope=compile dependencies as greyed out, which we + * don't want to do here. + */ + return null; + } +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ParentGatherer.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ParentGatherer.java new file mode 100644 index 00000000..6a79c0ce --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ParentGatherer.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.composites; + +import java.util.LinkedList; + +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.project.MavenProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.embedder.IMaven; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectManager; + +/** + * Helper class to get the parent chain given a pom + */ +public class ParentGatherer { + private MavenProject mavenProject; + + private IMavenProjectFacade projectFacade; + + public ParentGatherer(MavenProject leafProject, IMavenProjectFacade facade) { + this.mavenProject = leafProject; + this.projectFacade = facade; + } + + /** + * Return the list of parents for a give pom + * @param monitor + * @return list of {@link MavenProject} from the given project to its ultimate parent. + * The first entry is the given pom, the last one the ultimate parent. + * @throws CoreException + */ + public LinkedList<MavenProject> getParentHierarchy(IProgressMonitor monitor) throws CoreException { + LinkedList<MavenProject> hierarchy = new LinkedList<MavenProject>(); + IMaven maven = MavenPlugin.getDefault().getMaven(); + MavenProjectManager projectManager = MavenPlugin.getDefault().getMavenProjectManager(); + maven.detachFromSession(mavenProject); + + hierarchy.add(mavenProject); + + MavenProject project = mavenProject; + while(project.getModel().getParent() != null) { + if(monitor.isCanceled()) { + return null; + } + MavenExecutionRequest request = projectManager.createExecutionRequest(projectFacade, monitor); + project = maven.resolveParentProject(request, project, monitor); + hierarchy.add(project); + } + return hierarchy; + } +} 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 new file mode 100644 index 00000000..dc3ec33c --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/PluginsComposite.java @@ -0,0 +1,1377 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.composites; + +import static org.eclipse.m2e.editor.pom.FormUtils.isEmpty; +import static org.eclipse.m2e.editor.pom.FormUtils.nvl; +import static org.eclipse.m2e.editor.pom.FormUtils.setButton; +import static org.eclipse.m2e.editor.pom.FormUtils.setText; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.command.RemoveCommand; +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.ActionContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.action.IMenuCreator; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.viewers.ICellModifier; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.window.Window; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.actions.OpenPomAction; +import org.eclipse.m2e.core.actions.OpenUrlAction; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.index.IIndex; +import org.eclipse.m2e.core.index.IndexedArtifactFile; +import org.eclipse.m2e.core.ui.dialogs.MavenRepositorySearchDialog; +import org.eclipse.m2e.core.util.M2EUtils; +import org.eclipse.m2e.core.util.ProposalUtil; +import org.eclipse.m2e.core.util.search.Packaging; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.editor.plugins.DefaultPluginConfigurationEditor; +import org.eclipse.m2e.editor.plugins.IPluginConfigurationExtension; +import org.eclipse.m2e.editor.plugins.PluginExtensionDescriptor; +import org.eclipse.m2e.editor.pom.FormUtils; +import org.eclipse.m2e.editor.pom.MavenPomEditorPage; +import org.eclipse.m2e.editor.pom.SearchControl; +import org.eclipse.m2e.editor.pom.SearchMatcher; +import org.eclipse.m2e.editor.pom.ValueProvider; +import org.eclipse.m2e.model.edit.pom.BuildBase; +import org.eclipse.m2e.model.edit.pom.Configuration; +import org.eclipse.m2e.model.edit.pom.Dependency; +import org.eclipse.m2e.model.edit.pom.Plugin; +import org.eclipse.m2e.model.edit.pom.PluginExecution; +import org.eclipse.m2e.model.edit.pom.PluginManagement; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.m2e.model.edit.pom.PomPackage; +import org.eclipse.m2e.model.edit.pom.ReportPlugin; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.custom.SashForm; +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.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.swt.widgets.Widget; +import org.eclipse.ui.forms.events.HyperlinkAdapter; +import org.eclipse.ui.forms.events.HyperlinkEvent; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Hyperlink; +import org.eclipse.ui.forms.widgets.Section; + +/** + * @author Eugene Kuleshov + */ +public class PluginsComposite extends Composite{ + + protected static PomPackage POM_PACKAGE = PomPackage.eINSTANCE; + public static final String EXTENSION_CONFIGURATION_EDITOR = "org.eclipse.m2e.editor.plugins.configurationEditorContribution"; //$NON-NLS-1$ + public static final String ELEMENT_CONFIGURATION_EDITOR = "editContributor"; //$NON-NLS-1$ + + MavenPomEditorPage parentEditorPage; + + // controls + CCombo executionPhaseCombo; + Text executionIdText; + Hyperlink pluginExecutionConfigurationHyperlink; + Button executionInheritedButton; + FormToolkit toolkit = new FormToolkit(Display.getCurrent()); + + ListEditorComposite<Plugin> pluginsEditor; + ListEditorComposite<Plugin> pluginManagementEditor; + + Text groupIdText; + Text artifactIdText; + Text versionText; + Section pluginDetailsSection; + Button pluginExtensionsButton; + Button pluginInheritedButton; + + ListEditorComposite<Dependency> pluginDependenciesEditor; + ListEditorComposite<String> goalsEditor; + ListEditorComposite<PluginExecution> pluginExecutionsEditor; + + Section pluginConfigurationSection; + IPluginConfigurationExtension configurationEditor; + IAction openConfigurationAction; + + Section pluginExecutionSection; + Section pluginExecutionsSection; + Section pluginDependenciesSection; + + Button pluginSelectButton; + + Action pluginSelectAction; + + PluginSelectAction pluginAddAction; + + PluginSelectAction pluginManagementAddAction; + + Action openWebPageAction; + + ViewerFilter searchFilter; + + SearchControl searchControl; + + SearchMatcher searchMatcher; + + // model + + Plugin currentPlugin; + PluginExecution currentPluginExecution; + + ValueProvider<BuildBase> buildProvider; + + ValueProvider<PluginManagement> pluginManagementProvider; + + Map<String,PluginExtensionDescriptor> pluginConfigurators; + IPluginConfigurationExtension defaultConfigurationEditor; + + boolean changingSelection = false; + + + public PluginsComposite(Composite composite, MavenPomEditorPage page, int style) { + super(composite, style); + this.parentEditorPage = page; + GridLayout gridLayout = new GridLayout(1, false); + gridLayout.marginWidth = 0; + setLayout(gridLayout); + toolkit.adapt(this); + + SashForm horizontalSashForm = new SashForm(this, SWT.NONE); + GridData gd_horizontalSashForm = new GridData(SWT.FILL, SWT.FILL, true, true); + horizontalSashForm.setLayoutData(gd_horizontalSashForm); + toolkit.adapt(horizontalSashForm, true, true); + + SashForm verticalSashForm = new SashForm(horizontalSashForm, SWT.VERTICAL); + toolkit.adapt(verticalSashForm, true, true); + + loadPluginConfigurators(); + + createPluginsSection(verticalSashForm); + createPluginManagementSection(verticalSashForm); + + verticalSashForm.setWeights(new int[] {1, 1}); + + createPluginDetailsSection(horizontalSashForm); + horizontalSashForm.setWeights(new int[] {10, 15 }); + + updatePluginDetails(null); + } + + private void createPluginsSection(SashForm verticalSashForm) { + Section pluginsSection = toolkit.createSection(verticalSashForm, ExpandableComposite.TITLE_BAR | ExpandableComposite.COMPACT); + pluginsSection.setText(Messages.PluginsComposite_section_Plugins); + + pluginsEditor = new ListEditorComposite<Plugin>(pluginsSection, SWT.NONE, true); + pluginsSection.setClient(pluginsEditor); + toolkit.adapt(pluginsEditor); + toolkit.paintBordersFor(pluginsEditor); + + final PluginLabelProvider labelProvider = new PluginLabelProvider(); + pluginsEditor.setLabelProvider(labelProvider); + pluginsEditor.setContentProvider(new ListEditorContentProvider<Plugin>()); + + pluginsEditor.addSelectionListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + List<Plugin> selection = pluginsEditor.getSelection(); + updatePluginDetails(selection.size()==1 ? selection.get(0) : null); + + if(!selection.isEmpty()) { + changingSelection = true; + pluginManagementEditor.setSelection(Collections.<Plugin>emptyList()); + changingSelection = false; + } + } + }); + + pluginsEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + createPlugin(pluginsEditor, buildProvider, POM_PACKAGE.getBuildBase_Plugins(), null, null, null); + } + }); + + pluginsEditor.setAddButtonListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e){ + MavenRepositorySearchDialog dialog = new MavenRepositorySearchDialog(getShell(), // + Messages.PluginsComposite_searchDialog_selectPlugin, IIndex.SEARCH_PLUGIN, Collections.<ArtifactKey>emptySet()); + if(dialog.open() == Window.OK) { + IndexedArtifactFile af = (IndexedArtifactFile) dialog.getFirstResult(); + if(af != null) { + createPlugin(pluginsEditor, buildProvider, POM_PACKAGE.getBuildBase_Plugins(), af.group, af.artifact, af.version); + } + } + } + }); + + pluginsEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parentEditorPage.getEditingDomain(); + + List<Plugin> list = pluginsEditor.getSelection(); + for(Plugin plugin : list) { + Command removeCommand = RemoveCommand.create(editingDomain, buildProvider.getValue(), // + POM_PACKAGE.getBuildBase_Plugins(), plugin); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + updatePluginDetails(null); + } + }); + + pluginAddAction = new PluginSelectAction(pluginsEditor, POM_PACKAGE.getBuildBase_Plugins()); + + ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); + + if(pluginConfigurators.size() > 0) { + toolBarManager.add(pluginAddAction.getItem()); + toolBarManager.add(new Separator()); + } + + toolBarManager.add(new Action(Messages.PluginsComposite_action_showGroupId, MavenEditorImages.SHOW_GROUP) { + { + setChecked(false); + } + public int getStyle() { + return AS_CHECK_BOX; + } + public void run() { + labelProvider.setShowGroupId(isChecked()); + pluginsEditor.getViewer().refresh(); + } + }); + + toolBarManager.add(new Action(Messages.PluginsComposite_action_Filter, MavenEditorImages.FILTER) { + { + setChecked(true); + } + public int getStyle() { + return AS_CHECK_BOX; + } + public void run() { + TableViewer viewer = pluginsEditor.getViewer(); + if(isChecked()) { + viewer.addFilter(searchFilter); + } else { + viewer.removeFilter(searchFilter); + } + viewer.refresh(); + if(isChecked()) { + searchControl.getSearchText().setFocus(); + } + } + }); + + Composite toolbarComposite = toolkit.createComposite(pluginsSection); + GridLayout toolbarLayout = new GridLayout(1, true); + toolbarLayout.marginHeight = 0; + toolbarLayout.marginWidth = 0; + toolbarComposite.setLayout(toolbarLayout); + toolbarComposite.setBackground(null); + + toolBarManager.createControl(toolbarComposite); + pluginsSection.setTextClient(toolbarComposite); + } + + private void createPluginManagementSection(SashForm verticalSashForm) { + Section pluginManagementSection = toolkit.createSection(verticalSashForm, ExpandableComposite.TITLE_BAR); + pluginManagementSection.setText(Messages.PluginsComposite_section_PluginManagent); + + pluginManagementEditor = new ListEditorComposite<Plugin>(pluginManagementSection, SWT.NONE, true); + pluginManagementSection.setClient(pluginManagementEditor); + toolkit.adapt(pluginManagementEditor); + toolkit.paintBordersFor(pluginManagementEditor); + + final PluginLabelProvider labelProvider = new PluginLabelProvider(); + pluginManagementEditor.setLabelProvider(labelProvider); + pluginManagementEditor.setContentProvider(new ListEditorContentProvider<Plugin>()); + + pluginManagementEditor.addSelectionListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + List<Plugin> selection = pluginManagementEditor.getSelection(); + updatePluginDetails(selection.size()==1 ? selection.get(0) : null); + + if(!selection.isEmpty()) { + changingSelection = true; + pluginsEditor.setSelection(Collections.<Plugin>emptyList()); + changingSelection = false; + } + } + }); + + pluginManagementEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + createPlugin(pluginManagementEditor, pluginManagementProvider, POM_PACKAGE.getPluginManagement_Plugins(), null, null, null); + } + }); + + + pluginManagementEditor.setAddButtonListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e){ + MavenRepositorySearchDialog dialog = new MavenRepositorySearchDialog(getShell(), // + Messages.PluginsComposite_seachDialog_selectPlugin, IIndex.SEARCH_PLUGIN, Collections.<ArtifactKey>emptySet()); + if(dialog.open() == Window.OK) { + IndexedArtifactFile af = (IndexedArtifactFile) dialog.getFirstResult(); + if(af != null) { + createPlugin(pluginManagementEditor, pluginManagementProvider, POM_PACKAGE.getPluginManagement_Plugins(), af.group, af.artifact, af.version); + } + } + } + }); + + pluginManagementEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parentEditorPage.getEditingDomain(); + + List<Plugin> list = pluginManagementEditor.getSelection(); + for(Plugin plugin : list) { + Command removeCommand = RemoveCommand.create(editingDomain, // + pluginManagementProvider.getValue(), POM_PACKAGE.getPluginManagement_Plugins(), plugin); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + updatePluginDetails(null); + } + }); + + pluginManagementAddAction = new PluginSelectAction(pluginManagementEditor, POM_PACKAGE.getPluginManagement_Plugins()); + + ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); + + if(pluginConfigurators.size() > 0) { + toolBarManager.add(pluginManagementAddAction.getItem()); + toolBarManager.add(new Separator()); + } + + toolBarManager.add(new Action(Messages.PluginsComposite_action_showGroupId, MavenEditorImages.SHOW_GROUP) { + { + setChecked(false); + } + public int getStyle() { + return AS_CHECK_BOX; + } + public void run() { + labelProvider.setShowGroupId(isChecked()); + pluginManagementEditor.getViewer().refresh(); + } + }); + + toolBarManager.add(new Action(Messages.PluginsComposite_action_Filter, MavenEditorImages.FILTER) { + { + setChecked(true); + } + public int getStyle() { + return AS_CHECK_BOX; + } + public void run() { + TableViewer viewer = pluginManagementEditor.getViewer(); + if(isChecked()) { + viewer.addFilter(searchFilter); + } else { + viewer.removeFilter(searchFilter); + } + viewer.refresh(); + if(isChecked()) { + searchControl.getSearchText().setFocus(); + } + } + }); + + Composite toolbarComposite = toolkit.createComposite(pluginManagementSection); + GridLayout toolbarLayout = new GridLayout(1, true); + toolbarLayout.marginHeight = 0; + toolbarLayout.marginWidth = 0; + toolbarComposite.setLayout(toolbarLayout); + toolbarComposite.setBackground(null); + + toolBarManager.createControl(toolbarComposite); + pluginManagementSection.setTextClient(toolbarComposite); + } + + private void createPluginDetailsSection(Composite horizontalSashForm) { + Composite detailsComposite = toolkit.createComposite(horizontalSashForm, SWT.NONE); + GridLayout detailsCompositeLayout = new GridLayout(); + detailsCompositeLayout.marginWidth = 0; + detailsCompositeLayout.marginHeight = 0; + detailsComposite.setLayout(detailsCompositeLayout); + toolkit.paintBordersFor(detailsComposite); + + pluginDetailsSection = toolkit.createSection(detailsComposite, ExpandableComposite.TITLE_BAR); + pluginDetailsSection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + pluginDetailsSection.setText(Messages.PluginsComposite_section_pluginDetails); + + Composite pluginDetailsComposite = toolkit.createComposite(pluginDetailsSection, SWT.NONE); + GridLayout pluginDetailsLayout = new GridLayout(3, false); + pluginDetailsLayout.marginWidth = 1; + pluginDetailsLayout.marginHeight = 2; + pluginDetailsComposite.setLayout(pluginDetailsLayout); + toolkit.paintBordersFor(pluginDetailsComposite); + pluginDetailsSection.setClient(pluginDetailsComposite); + + toolkit.createLabel(pluginDetailsComposite, Messages.PluginsComposite_lblGroupId, SWT.NONE); + + groupIdText = toolkit.createText(pluginDetailsComposite, null, SWT.NONE); + GridData gd_groupIdText = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1); + gd_groupIdText.horizontalIndent = 4; + groupIdText.setLayoutData(gd_groupIdText); + groupIdText.setData("name", "groupIdText"); //$NON-NLS-1$ //$NON-NLS-2$ + ProposalUtil.addGroupIdProposal(parentEditorPage.getProject(), groupIdText, Packaging.PLUGIN); + M2EUtils.addRequiredDecoration(groupIdText); + + Hyperlink artifactIdHyperlink = toolkit.createHyperlink(pluginDetailsComposite, Messages.PluginsComposite_lblArtifactId, SWT.NONE); + artifactIdHyperlink.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + final String groupId = groupIdText.getText(); + final String artifactId = artifactIdText.getText(); + final String version = versionText.getText(); + new Job("Opening " + groupId + ":" + artifactId + ":" + version) { + protected IStatus run(IProgressMonitor arg0) { + OpenPomAction.openEditor(groupId, artifactId, version, null); + return Status.OK_STATUS; + } + }.schedule(); + } + }); + + artifactIdText = toolkit.createText(pluginDetailsComposite, null, SWT.NONE); + GridData gd_artifactIdText = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1); + gd_artifactIdText.horizontalIndent = 4; + artifactIdText.setLayoutData(gd_artifactIdText); + artifactIdText.setData("name", "artifactIdText"); //$NON-NLS-1$ //$NON-NLS-2$ + ProposalUtil.addArtifactIdProposal(parentEditorPage.getProject(), groupIdText, artifactIdText, Packaging.PLUGIN); + M2EUtils.addRequiredDecoration(artifactIdText); + + Label label = toolkit.createLabel(pluginDetailsComposite, Messages.PluginsComposite_lblVersion, SWT.NONE); + label.setLayoutData(new GridData()); + + versionText = toolkit.createText(pluginDetailsComposite, null, SWT.NONE); + GridData versionTextData = new GridData(SWT.LEFT, SWT.CENTER, true, false); + versionTextData.horizontalIndent = 4; + versionTextData.widthHint = 200; + versionText.setLayoutData(versionTextData); + versionText.setData("name", "versionText"); //$NON-NLS-1$ //$NON-NLS-2$ + ProposalUtil.addVersionProposal(parentEditorPage.getProject(), groupIdText, artifactIdText, versionText, Packaging.PLUGIN); + + // pluginSelectButton = toolkit.createButton(pluginDetailsComposite, "Select...", SWT.NONE); + // pluginSelectButton.addSelectionListener(new SelectionAdapter() { + // public void widgetSelected(SelectionEvent e) { + // Set<Dependency> artifacts = Collections.emptySet(); + // MavenRepositorySearchDialog dialog = new MavenRepositorySearchDialog(parent.getEditorSite().getShell(), + // "Add Plugin", IndexManager.SEARCH_PLUGIN, artifacts); + // if(dialog.open() == Window.OK) { + // IndexedArtifactFile af = (IndexedArtifactFile) dialog.getFirstResult(); + // if(af != null) { + // groupIdText.setText(nvl(af.group)); + // artifactIdText.setText(nvl(af.artifact)); + // versionText.setText(nvl(af.version)); + // } + // } + // } + // }); + + pluginSelectAction = new Action(Messages.PluginsComposite_action_selectPlugin, MavenEditorImages.SELECT_PLUGIN) { + public void run() { + MavenRepositorySearchDialog dialog = new MavenRepositorySearchDialog(getShell(), // + Messages.PluginsComposite_searchDialog_selectPlugin, IIndex.SEARCH_PLUGIN, Collections.<ArtifactKey>emptySet()); + if(dialog.open() == Window.OK) { + IndexedArtifactFile af = (IndexedArtifactFile) dialog.getFirstResult(); + if(af != null) { + groupIdText.setText(nvl(af.group)); + artifactIdText.setText(nvl(af.artifact)); + versionText.setText(nvl(af.version)); + } + } + } + }; + pluginSelectAction.setEnabled(false); + + openWebPageAction = new Action(Messages.PluginsComposite_action_openWeb, MavenEditorImages.WEB_PAGE) { + public void run() { + final String groupId = groupIdText.getText(); + final String artifactId = artifactIdText.getText(); + final String version = versionText.getText(); + new Job("Opening " + groupId + ":" + artifactId + ":" + version) { + protected IStatus run(IProgressMonitor monitor) { + OpenUrlAction.openBrowser(OpenUrlAction.ID_PROJECT, groupId, artifactId, version, monitor); + return Status.OK_STATUS; + } + }.schedule(); + + } + }; + openWebPageAction.setEnabled(false); + + ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); + toolBarManager.add(pluginSelectAction); + toolBarManager.add(new Separator()); + toolBarManager.add(openWebPageAction); + + Composite toolbarComposite = toolkit.createComposite(pluginDetailsSection); + GridLayout toolbarLayout = new GridLayout(1, true); + toolbarLayout.marginHeight = 0; + toolbarLayout.marginWidth = 0; + toolbarComposite.setLayout(toolbarLayout); + toolbarComposite.setBackground(null); + + toolBarManager.createControl(toolbarComposite); + pluginDetailsSection.setTextClient(toolbarComposite); + + Composite composite = new Composite(pluginDetailsComposite, SWT.NONE); + GridLayout compositeLayout = new GridLayout(); + compositeLayout.marginWidth = 0; + compositeLayout.marginHeight = 0; + compositeLayout.numColumns = 3; + composite.setLayout(compositeLayout); + composite.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false, 1, 1)); + toolkit.adapt(composite); + + pluginExtensionsButton = toolkit.createButton(composite, Messages.PluginsComposite_btnExtensions, SWT.CHECK); + pluginExtensionsButton.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); + + pluginInheritedButton = toolkit.createButton(composite, Messages.PluginsComposite_btnInherited, SWT.CHECK); + pluginInheritedButton.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); + + pluginDetailsComposite.setTabList(new Control[] {groupIdText, artifactIdText, versionText, composite}); + + createConfigurationSection(detailsComposite); + + SashForm executionSash = new SashForm(detailsComposite, SWT.NONE); + executionSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + GridLayout executionSashLayout = new GridLayout(); + executionSashLayout.horizontalSpacing = 3; + executionSashLayout.marginWidth = 0; + executionSashLayout.marginHeight = 0; + executionSashLayout.numColumns = 2; + executionSash.setLayout(executionSashLayout); + toolkit.adapt(executionSash); + + pluginExecutionsSection = toolkit.createSection(executionSash, + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + GridData gd_pluginExecutionsSection = new GridData(SWT.FILL, SWT.FILL, true, true); + gd_pluginExecutionsSection.minimumHeight = 50; + pluginExecutionsSection.setLayoutData(gd_pluginExecutionsSection); + pluginExecutionsSection.setText(Messages.PluginsComposite_section_Executions); + + pluginExecutionsEditor = new ListEditorComposite<PluginExecution>(pluginExecutionsSection, SWT.NONE); + pluginExecutionsSection.setClient(pluginExecutionsEditor); + toolkit.adapt(pluginExecutionsEditor); + toolkit.paintBordersFor(pluginExecutionsEditor); + pluginExecutionsEditor.setContentProvider(new ListEditorContentProvider<PluginExecution>()); + pluginExecutionsEditor.setLabelProvider(new LabelProvider() { + public String getText(Object element) { + if(element instanceof PluginExecution) { + PluginExecution pluginExecution = (PluginExecution) element; + String label = isEmpty(pluginExecution.getId()) ? "?" : pluginExecution.getId(); + if(pluginExecution.getPhase()!=null) { + label += " : " + pluginExecution.getPhase(); + } + return label; + } + return ""; //$NON-NLS-1$ + } + public Image getImage(Object element) { + return MavenEditorImages.IMG_EXECUTION; + } + }); + + pluginExecutionsEditor.addSelectionListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + List<PluginExecution> selection = pluginExecutionsEditor.getSelection(); + updatePluginExecution(selection.size()==1 ? selection.get(0) : null); + } + }); + + pluginExecutionsEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parentEditorPage.getEditingDomain(); + + + PluginExecution pluginExecution = PomFactory.eINSTANCE.createPluginExecution(); + Command command = AddCommand.create(editingDomain, currentPlugin, POM_PACKAGE.getPlugin_Executions(), pluginExecution); + compoundCommand.append(command); + + editingDomain.getCommandStack().execute(compoundCommand); + + pluginExecutionsEditor.setSelection(Collections.singletonList(pluginExecution)); + updatePluginExecution(pluginExecution); + executionIdText.setFocus(); + } + }); + + pluginExecutionsEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parentEditorPage.getEditingDomain(); + + List<PluginExecution> list = pluginExecutionsEditor.getSelection(); + Command removeCommand = RemoveCommand.create(editingDomain, // + currentPlugin, POM_PACKAGE.getPlugin_Executions(), list); + compoundCommand.append(removeCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + updatePluginExecution(null); + } + }); + + pluginExecutionSection = toolkit.createSection(executionSash, + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + GridData gd_pluginExecutionSection = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_pluginExecutionSection.minimumHeight = 50; + pluginExecutionSection.setLayoutData(gd_pluginExecutionSection); + pluginExecutionSection.setText(Messages.PluginsComposite_section_executionDetails); + new SectionExpansionAdapter(new Section[]{pluginExecutionSection, pluginExecutionsSection}); + + Composite executionComposite = toolkit.createComposite(pluginExecutionSection, SWT.NONE); + GridLayout executionCompositeLayout = new GridLayout(2, false); + executionCompositeLayout.marginWidth = 2; + executionCompositeLayout.marginHeight = 2; + executionComposite.setLayout(executionCompositeLayout); + pluginExecutionSection.setClient(executionComposite); + toolkit.paintBordersFor(executionComposite); + + toolkit.createLabel(executionComposite, Messages.PluginsComposite_lblId, SWT.NONE); + + executionIdText = toolkit.createText(executionComposite, null, SWT.NONE); + executionIdText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + toolkit.createLabel(executionComposite, Messages.PluginsComposite_lblPhase, SWT.NONE); + + executionPhaseCombo = new CCombo(executionComposite, SWT.FLAT); + executionPhaseCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + executionPhaseCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + executionPhaseCombo.setItems(new String[] { // + "pre-clean", // Clean Lifecycle //$NON-NLS-1$ + "clean", // //$NON-NLS-1$ + "post-clean", // //$NON-NLS-1$ + "validate", // Default Lifecycle //$NON-NLS-1$ + "generate-sources", // //$NON-NLS-1$ + "process-sources", // //$NON-NLS-1$ + "generate-resources", // //$NON-NLS-1$ + "process-resources", // //$NON-NLS-1$ + "compile", // //$NON-NLS-1$ + "process-classes", // //$NON-NLS-1$ + "generate-test-sources", // //$NON-NLS-1$ + "process-test-sources", // //$NON-NLS-1$ + "generate-test-resources", // //$NON-NLS-1$ + "process-test-resources", // //$NON-NLS-1$ + "test-compile", // //$NON-NLS-1$ + "process-test-classes", // //$NON-NLS-1$ + "test", // //$NON-NLS-1$ + "prepare-package", // //$NON-NLS-1$ + "package", // //$NON-NLS-1$ + "pre-integration-test", // //$NON-NLS-1$ + "integration-test", // //$NON-NLS-1$ + "post-integration-test", // //$NON-NLS-1$ + "verify", // //$NON-NLS-1$ + "install", // //$NON-NLS-1$ + "deploy", // //$NON-NLS-1$ + "pre-site", // //$NON-NLS-1$ + "site", // Site Lifecycle //$NON-NLS-1$ + "post-site", // //$NON-NLS-1$ + "site-deploy"}); //$NON-NLS-1$ + toolkit.adapt(executionPhaseCombo, true, true); + + Label goalsLabel = toolkit.createLabel(executionComposite, Messages.PluginsComposite_lblGoals, SWT.NONE); + goalsLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); + + goalsEditor = new ListEditorComposite<String>(executionComposite, SWT.NONE); + goalsEditor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + toolkit.paintBordersFor(goalsEditor); + goalsEditor.setContentProvider(new ListEditorContentProvider<String>()); + goalsEditor.setLabelProvider(new StringLabelProvider(MavenEditorImages.IMG_GOAL)); + + goalsEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parentEditorPage.getEditingDomain(); + + String goal = "?"; + Command command = AddCommand.create(editingDomain, currentPluginExecution, POM_PACKAGE.getPluginExecution_Goals(), goal); + compoundCommand.append(command); + + editingDomain.getCommandStack().execute(compoundCommand); + + goalsEditor.setSelection(Collections.singletonList(goal)); + } + }); + + goalsEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parentEditorPage.getEditingDomain(); + + List<String> list = goalsEditor.getSelection(); + for(String goal : list) { + Command removeCommand = RemoveCommand.create(editingDomain, // + currentPluginExecution, POM_PACKAGE.getPluginExecution_Goals(), goal); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + } + }); + + goalsEditor.setCellModifier(new ICellModifier() { + public boolean canModify(Object element, String property) { + return true; + } + + public Object getValue(Object element, String property) { + return element; + } + + public void modify(Object element, String property, Object value) { + int n = goalsEditor.getViewer().getTable().getSelectionIndex(); + if(!value.equals(currentPluginExecution.getGoals().get(n))) { + EditingDomain editingDomain = parentEditorPage.getEditingDomain(); + Command command = SetCommand.create(editingDomain, currentPluginExecution, // + POM_PACKAGE.getPluginExecution_Goals(), value, n); + editingDomain.getCommandStack().execute(command); + + // currentPluginExecution.getGoals().getGoal().set(n, (String) value); + goalsEditor.update(); + } + } + }); + + Composite executionConfigureComposite = new Composite(executionComposite, SWT.NONE); + executionConfigureComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2, 1)); + GridLayout gridLayout = new GridLayout(2, false); + gridLayout.marginWidth = 0; + gridLayout.marginHeight = 0; + executionConfigureComposite.setLayout(gridLayout); + toolkit.adapt(executionConfigureComposite); + + executionInheritedButton = toolkit.createButton(executionConfigureComposite, Messages.PluginsComposite_btnInherited, SWT.CHECK); + executionInheritedButton.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); + + pluginExecutionConfigurationHyperlink = toolkit.createHyperlink(executionConfigureComposite, Messages.PluginsComposite_linkConfiguration, SWT.NONE); + pluginExecutionConfigurationHyperlink.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, false)); + pluginExecutionConfigurationHyperlink.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + EObject element = currentPluginExecution.getConfiguration(); + parentEditorPage.getPomEditor().showInSourceEditor(element==null ? currentPluginExecution : element); + } + }); + + pluginDependenciesSection = toolkit.createSection(detailsComposite, + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + GridData pluginDependenciesSectionData = new GridData(SWT.FILL, SWT.FILL, true, true); + pluginDependenciesSectionData.minimumHeight = 50; + pluginDependenciesSection.setLayoutData(pluginDependenciesSectionData); + pluginDependenciesSection.setText(Messages.PluginsComposite_section_PluginDependencies); + + pluginDependenciesEditor = new ListEditorComposite<Dependency>(pluginDependenciesSection, SWT.NONE); + pluginDependenciesSection.setClient(pluginDependenciesEditor); + toolkit.adapt(pluginDependenciesEditor); + toolkit.paintBordersFor(pluginDependenciesEditor); + pluginDependenciesEditor.setContentProvider(new ListEditorContentProvider<Dependency>()); + pluginDependenciesEditor.setLabelProvider(new DependencyLabelProvider()); + + pluginDependenciesEditor.setReadOnly(true); + + // XXX implement plugin dependency editor actions and UI + + FormUtils.setEnabled(pluginDependenciesEditor, false); + } + + private void createConfigurationSection(Composite detailsComposite) { + pluginConfigurationSection = toolkit.createSection(detailsComposite, + ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE); + pluginConfigurationSection.setText(Messages.PluginsComposite_section_configuration); + pluginConfigurationSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + pluginConfigurationSection.setEnabled(false); + + defaultConfigurationEditor = new DefaultPluginConfigurationEditor(); + setConfigurationEditor(defaultConfigurationEditor); + + openConfigurationAction = new Action(Messages.PluginsComposite_action_openXml, MavenEditorImages.ELEMENT_OBJECT) { + public void run() { + EObject element = currentPlugin.getConfiguration(); + parentEditorPage.getPomEditor().showInSourceEditor(element==null ? currentPlugin : element); + } + }; + openConfigurationAction.setEnabled(false); + + ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); + toolBarManager.add(openConfigurationAction); + + Composite toolbarComposite = toolkit.createComposite(pluginConfigurationSection); + GridLayout toolbarLayout = new GridLayout(1, true); + toolbarLayout.marginHeight = 0; + toolbarLayout.marginWidth = 0; + toolbarComposite.setLayout(toolbarLayout); + toolbarComposite.setBackground(null); + + toolBarManager.createControl(toolbarComposite); + pluginConfigurationSection.setTextClient(toolbarComposite); + } + + private IPluginConfigurationExtension findConfigurationEditor(String groupId, String artifactId) { + String ga = groupId + ':' + artifactId; + PluginExtensionDescriptor descriptor = pluginConfigurators.get(ga); + return descriptor == null || descriptor.getExtension() == null ? + defaultConfigurationEditor : descriptor.getExtension(); + } + + private void setConfigurationEditor(IPluginConfigurationExtension editor) { + if(configurationEditor == editor) { + return; + } + + if(configurationEditor != null) { + configurationEditor.cleanup(); + } + + boolean expanded = pluginConfigurationSection.isExpanded(); + if(expanded) { + pluginConfigurationSection.setExpanded(false); + } + + Control control = pluginConfigurationSection.getClient(); + if(control != null) { + control.dispose(); + } + configurationEditor = editor; + configurationEditor.setPomEditor(parentEditorPage); + + Composite configurationComposite = configurationEditor.createComposite(pluginConfigurationSection); + configurationComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); + toolkit.adapt(configurationComposite); + pluginConfigurationSection.setClient(configurationComposite); + toolkit.paintBordersFor(configurationComposite); + pluginConfigurationSection.layout(); + + if(expanded) { + pluginConfigurationSection.setExpanded(true); + } + } + + void updatePluginDetails(Plugin plugin) { + if(changingSelection) { + return; + } +// if(plugin!=null && currentPlugin==plugin) { +// return; +// } + this.currentPlugin = plugin; + + if(parentEditorPage!=null) { + parentEditorPage.removeNotifyListener(groupIdText); + parentEditorPage.removeNotifyListener(artifactIdText); + parentEditorPage.removeNotifyListener(versionText); + parentEditorPage.removeNotifyListener(pluginExtensionsButton); + parentEditorPage.removeNotifyListener(pluginInheritedButton); + } + + if(plugin==null) { + pluginConfigurationSection.setExpanded(false); + pluginConfigurationSection.setEnabled(false); + FormUtils.setEnabled(pluginDetailsSection, false); + FormUtils.setEnabled(pluginExecutionsSection, false); + FormUtils.setEnabled(pluginDependenciesSection, false); + pluginSelectAction.setEnabled(false); + openWebPageAction.setEnabled(false); + openConfigurationAction.setEnabled(false); + + setText(groupIdText, ""); //$NON-NLS-1$ + setText(artifactIdText, ""); //$NON-NLS-1$ + setText(versionText, ""); //$NON-NLS-1$ + setButton(pluginExtensionsButton, false); + setButton(pluginInheritedButton, false); + + pluginExecutionsEditor.setInput(null); + pluginDependenciesEditor.setInput(null); + updatePluginExecution(null); + + if(configurationEditor != null) { + configurationEditor.cleanup(); + } + return; + } + + pluginConfigurationSection.setEnabled(true); + FormUtils.setEnabled(pluginDetailsSection, true); + FormUtils.setEnabled(pluginExecutionsSection, true); + FormUtils.setEnabled(pluginDependenciesSection, true); + + FormUtils.setReadonly(pluginDetailsSection, parentEditorPage.isReadOnly()); + FormUtils.setReadonly(pluginConfigurationSection, parentEditorPage.isReadOnly()); + FormUtils.setReadonly(pluginExecutionsSection, parentEditorPage.isReadOnly()); + pluginSelectAction.setEnabled(!parentEditorPage.isReadOnly()); + openWebPageAction.setEnabled(true); + openConfigurationAction.setEnabled(true); + + // XXX implement dependency editing + FormUtils.setReadonly(pluginDependenciesSection, true); + + String groupId = plugin.getGroupId(); + String artifactId = plugin.getArtifactId(); + String version = plugin.getVersion(); + + setText(groupIdText, groupId); + setText(artifactIdText, artifactId); + setText(versionText, version); + + setConfigurationEditor(findConfigurationEditor(groupId, artifactId)); + if(configurationEditor != defaultConfigurationEditor && plugin.getConfiguration() == null) { + // if a configuration editor is available, create the config section right away + Configuration configuration = PomFactory.eINSTANCE.createConfiguration(); + plugin.setConfiguration(configuration); + } + configurationEditor.setPlugin(plugin); + + setButton(pluginInheritedButton, plugin.getInherited()==null || "true".equals(plugin.getInherited())); + setButton(pluginExtensionsButton, "true".equals(plugin.getExtensions())); + + pluginExecutionsEditor.setInput(plugin.getExecutions()); + + pluginDependenciesEditor.setInput(plugin.getDependencies()); + + updatePluginExecution(null); + + // register listeners + + ValueProvider<Plugin> provider = new ValueProvider.DefaultValueProvider<Plugin>(currentPlugin); + parentEditorPage.setModifyListener(groupIdText, provider, POM_PACKAGE.getPlugin_GroupId(), ""); //$NON-NLS-1$ + parentEditorPage.setModifyListener(artifactIdText, provider, POM_PACKAGE.getPlugin_ArtifactId(), ""); //$NON-NLS-1$ + parentEditorPage.setModifyListener(versionText, provider, POM_PACKAGE.getPlugin_Version(), ""); //$NON-NLS-1$ + parentEditorPage.setModifyListener(pluginInheritedButton, provider, POM_PACKAGE.getPlugin_Inherited(), "true"); + parentEditorPage.setModifyListener(pluginExtensionsButton, provider, POM_PACKAGE.getPlugin_Extensions(), "false"); + } + + void updatePluginExecution(PluginExecution pluginExecution) { +// if(pluginExecution!=null && currentPluginExecution==pluginExecution) { +// return; +// } + currentPluginExecution = pluginExecution; + + if(parentEditorPage!=null) { + parentEditorPage.removeNotifyListener(executionIdText); + parentEditorPage.removeNotifyListener(executionPhaseCombo); + parentEditorPage.removeNotifyListener(executionInheritedButton); + } + + if(pluginExecution==null) { + FormUtils.setEnabled(pluginExecutionSection, false); + + setText(executionIdText, ""); //$NON-NLS-1$ + setText(executionPhaseCombo, ""); //$NON-NLS-1$ + setButton(executionInheritedButton, false); + goalsEditor.setInput(null); + + return; + } + + FormUtils.setEnabled(pluginExecutionSection, true); + FormUtils.setReadonly(pluginExecutionSection, parentEditorPage.isReadOnly()); + + setText(executionIdText, pluginExecution.getId()); + setText(executionPhaseCombo, pluginExecution.getPhase()); + setButton(executionInheritedButton, pluginExecution.getInherited()==null || "true".equals(pluginExecution.getInherited())); + + goalsEditor.setInput(pluginExecution.getGoals()); + // goalsEditor.setSelection(Collections.<String>emptyList()); + + // register listeners + ValueProvider<PluginExecution> provider = new ValueProvider.DefaultValueProvider<PluginExecution>(pluginExecution); + parentEditorPage.setModifyListener(executionIdText, provider, POM_PACKAGE.getPluginExecution_Id(), ""); //$NON-NLS-1$ + parentEditorPage.setModifyListener(executionPhaseCombo, provider, POM_PACKAGE.getPluginExecution_Phase(), ""); //$NON-NLS-1$ + parentEditorPage.setModifyListener(executionInheritedButton, provider, POM_PACKAGE.getPluginExecution_Inherited(), "true"); + } + + public void loadData(MavenPomEditorPage editorPage, ValueProvider<BuildBase> buildProvider, + ValueProvider<PluginManagement> pluginManagementProvider) { + this.parentEditorPage = editorPage; + this.buildProvider = buildProvider; + this.pluginManagementProvider = pluginManagementProvider; + + changingSelection = true; + loadPlugins(); + loadPluginManagement(); + changingSelection = false; + + pluginsEditor.setReadOnly(parentEditorPage.isReadOnly()); + pluginManagementEditor.setReadOnly(parentEditorPage.isReadOnly()); + + pluginAddAction.setEnabled(!parentEditorPage.isReadOnly()); + pluginAddAction.setProvider(buildProvider); + pluginManagementAddAction.setEnabled(!parentEditorPage.isReadOnly()); + pluginManagementAddAction.setProvider(pluginManagementProvider); + updatePluginDetails(null); + +// pluginExecutionsEditor.setReadOnly(parent.isReadOnly()); +// goalsEditor.setReadOnly(parent.isReadOnly()); +// pluginDependenciesEditor.setReadOnly(parent.isReadOnly()); + } + + private void loadPlugins() { + BuildBase build = buildProvider.getValue(); + pluginsEditor.setInput(build == null ? null : build.getPlugins()); + } + + private void loadPluginManagement() { + PluginManagement pluginManagement = pluginManagementProvider.getValue(); + pluginManagementEditor.setInput(pluginManagement == null ? null : pluginManagement.getPlugins()); + } + + public void updateView(MavenPomEditorPage editorPage, Notification notification) { + Object object = notification.getNotifier(); + Object feature = notification.getFeature(); + Object notificationObject = MavenPomEditorPage.getFromNotification(notification); + + if(feature == PomPackage.Literals.BUILD_BASE__PLUGINS || feature == PomPackage.Literals.PLUGIN_MANAGEMENT__PLUGINS) { + pluginsEditor.refresh(); + pluginManagementEditor.refresh(); + } + + if(object instanceof PluginManagement) { + pluginManagementEditor.refresh(); + } + + if(object instanceof Plugin) { + pluginsEditor.refresh(); + pluginManagementEditor.refresh(); + if(object == currentPlugin && (notificationObject == null || notificationObject instanceof Plugin)) { + updatePluginDetails((Plugin) notificationObject); + } + } + + if(feature == PomPackage.Literals.PLUGIN__EXECUTIONS) { + pluginExecutionsEditor.refresh(); + goalsEditor.refresh(); + } + + if(object instanceof PluginExecution) { + pluginExecutionsEditor.refresh(); + if(currentPluginExecution == object + && (notificationObject == null || notificationObject instanceof PluginExecution)) { + updatePluginExecution((PluginExecution) notificationObject); + } + } + + if(feature == PomPackage.Literals.PLUGIN_EXECUTION__GOALS) { + goalsEditor.setInput(((PluginExecution) object).getGoals()); + goalsEditor.refresh(); + } + } + + @SuppressWarnings("unchecked") + void createPlugin(ListEditorComposite<Plugin> editor, ValueProvider<? extends EObject> parentObjectProvider, EStructuralFeature feature, String groupId, String artifactId, String version) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parentEditorPage.getEditingDomain(); + + EObject parentObject = parentObjectProvider.getValue(); + boolean created = false; + if(null == parentObject) { + parentObject = parentObjectProvider.create(editingDomain, compoundCommand); + created = true; + } + + Plugin plugin = PomFactory.eINSTANCE.createPlugin(); + plugin.setGroupId(groupId); + plugin.setArtifactId(artifactId); + plugin.setVersion(version); + + if(findConfigurationEditor(groupId, artifactId) != defaultConfigurationEditor) { + // if a configuration editor is available, create the config section right away + Configuration configuration = PomFactory.eINSTANCE.createConfiguration(); + plugin.setConfiguration(configuration); + } + + Command command = AddCommand.create(editingDomain, parentObject, feature, plugin); + compoundCommand.append(command); + + editingDomain.getCommandStack().execute(compoundCommand); + + if(created) { + editor.setInput((EList<Plugin>)parentObject.eGet(feature)); + } + editor.setSelection(Collections.singletonList(plugin)); + updatePluginDetails(plugin); + groupIdText.setFocus(); + } + + /** + * Plugin label provider + */ + static final class PluginLabelProvider extends LabelProvider { + + private boolean showGroupId = false; + + public void setShowGroupId(boolean showGroupId) { + this.showGroupId = showGroupId; + } + + public String getText(Object element) { + if(element instanceof Plugin) { + Plugin plugin = (Plugin) element; + String label = ""; //$NON-NLS-1$ + + if(showGroupId) { + if(!isEmpty(plugin.getGroupId())) { + label += plugin.getGroupId() + " : "; + } + } + + label += isEmpty(plugin.getArtifactId()) ? "?" : plugin.getArtifactId(); + + if(!isEmpty(plugin.getVersion())) { + label += " : " + plugin.getVersion(); + } + + return label; + } + return super.getText(element); + } + + public Image getImage(Object element) { + return MavenEditorImages.IMG_PLUGIN; + } + + } + + public void setSearchControl(SearchControl searchControl) { + if(this.searchControl!=null) { + return; + } + + this.searchMatcher = new SearchMatcher(searchControl); + this.searchFilter = new PluginFilter(searchMatcher); + this.searchControl = searchControl; + this.searchControl.getSearchText().addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + changingSelection = true; + selectPlugins(pluginsEditor, buildProvider.getValue().getPlugins()); + selectPlugins(pluginManagementEditor, pluginManagementProvider.getValue().getPlugins()); + changingSelection = false; + + updatePluginDetails(null); + } + + private void selectPlugins(ListEditorComposite<Plugin> editor, List<Plugin> value) { + List<Plugin> plugins = new ArrayList<Plugin>(); + if(value!=null) { + for(Plugin p : value) { + if(searchMatcher.isMatchingArtifact(p.getGroupId(), p.getArtifactId())) { + plugins.add(p); + } + } + } + editor.setSelection(plugins); + editor.refresh(); + } + }); + //we add filter here as the default behaviour is to filter.. + TableViewer viewer = pluginsEditor.getViewer(); + viewer.addFilter(searchFilter); + viewer = pluginManagementEditor.getViewer(); + viewer.addFilter(searchFilter); + + } + + + public static class PluginFilter extends ViewerFilter { + + private final SearchMatcher searchMatcher; + + public PluginFilter(SearchMatcher searchMatcher) { + this.searchMatcher = searchMatcher; + } + + public boolean select(Viewer viewer, Object parentElement, Object element) { + if(element instanceof Plugin) { + Plugin p = (Plugin) element; + return searchMatcher.isMatchingArtifact(p.getGroupId(), p.getArtifactId()); + } + if(element instanceof ReportPlugin) { + ReportPlugin p = (ReportPlugin) element; + return searchMatcher.isMatchingArtifact(p.getGroupId(), p.getArtifactId()); + } + return false; + } + + } + + private void loadPluginConfigurators() { + pluginConfigurators = new HashMap<String,PluginExtensionDescriptor>(); + + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint configuratorsExtensionPoint = registry.getExtensionPoint(EXTENSION_CONFIGURATION_EDITOR); + if(configuratorsExtensionPoint != null) { + IExtension[] configuratorExtensions = configuratorsExtensionPoint.getExtensions(); + for(IExtension extension : configuratorExtensions) { + IConfigurationElement[] elements = extension.getConfigurationElements(); + for(IConfigurationElement element : elements) { + if(element.getName().equals(ELEMENT_CONFIGURATION_EDITOR)) { + PluginExtensionDescriptor descriptor = new PluginExtensionDescriptor(element); + pluginConfigurators.put(descriptor.toString(), descriptor); + } + } + } + } + } + + // an action button with a list of supported plug-ins + final class PluginSelectAction extends Action implements IMenuCreator { + private Menu menu = null; + private List<IAction> actions = null; + ActionContributionItem item = null; + ValueProvider<? extends EObject> provider = null; + + protected PluginSelectAction(ListEditorComposite<Plugin> editor, EReference pomPackage) { + super("", IAction.AS_DROP_DOWN_MENU); //$NON-NLS-1$ + setImageDescriptor(MavenEditorImages.ADD_PLUGIN); + setMenuCreator(this); + setEnabled(false); + setToolTipText(Messages.PluginsComposite_tooltip_addPlugin); + actions = new ArrayList<IAction>(); + for(PluginExtensionDescriptor descriptor : pluginConfigurators.values()) { + actions.add(createContributedAction(editor, pomPackage, descriptor)); + } + actions.add(createDefaultAction(editor, pomPackage)); + item = new ActionContributionItem(this); + } + + private Action createDefaultAction(final ListEditorComposite<Plugin> editor, final EReference pomPackage) { + return new Action( Messages.PluginsComposite_action_other ) { + public void run() { + MavenRepositorySearchDialog dialog = new MavenRepositorySearchDialog(getShell(), + Messages.PluginsComposite_searchDialog_addPlugin, IIndex.SEARCH_PLUGIN, Collections.<ArtifactKey>emptySet()); + if(dialog.open() == Window.OK) { + IndexedArtifactFile af = (IndexedArtifactFile) dialog.getFirstResult(); + if(af != null) { + createPlugin(editor, provider, pomPackage, af.group, af.artifact, af.version); + } + } + } + }; + } + + private Action createContributedAction(final ListEditorComposite<Plugin> editor, final EReference pomPackage, final PluginExtensionDescriptor descriptor) { + return new Action( descriptor.getName() ) { + public void run() { + String groupId = descriptor.getGroupId(); + String artifactId = descriptor.getArtifactId(); + String version = ""; //$NON-NLS-1$ + try { + Collection<String> versions = MavenPlugin.getDefault().getSearchEngine(parentEditorPage.getProject()).findVersions(groupId, artifactId, null, Packaging.PLUGIN); + if(!versions.isEmpty()) { + version = versions.iterator().next(); + } + } catch(CoreException e) { + // TODO Auto-generated catch block + MavenLogger.log("Error retrieving available versions for " + groupId + ':' + artifactId, e); //$NON-NLS-1$ + } + + createPlugin(editor, provider, pomPackage, groupId, artifactId, version); + } + }; + } + + public Menu getMenu(Menu menu) { + return null; + } + + public Menu getMenu(Control control) { + dispose(); + menu = new Menu(control); + for(IAction action : actions) { + ActionContributionItem item = new ActionContributionItem(action); + item.fill(menu, -1); + } + return menu; + } + + public void dispose() { + if(menu != null) { + menu.dispose(); + } + } + + public IContributionItem getItem() { + return item; + } + + public void run() { + // a drop-down button would have a separate click action which does nothing by default, + // we need to show the same menu as if the user clicked on the chevron + Widget w = item.getWidget(); + if(w != null && w instanceof ToolItem) { + ToolItem ti = (ToolItem)w; + Rectangle r = ti.getBounds(); + Point point = ti.getParent().toDisplay(r.x, r.y + r.height); + Menu m = getMenu(ti.getParent()); + m.setLocation(point.x, point.y); + m.setVisible(true); + } + } + + protected void setProvider(final ValueProvider<? extends EObject> provider) { + this.provider = provider; + } + } +}
\ No newline at end of file diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ReportingComposite.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ReportingComposite.java new file mode 100644 index 00000000..0692ddfd --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/ReportingComposite.java @@ -0,0 +1,885 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.composites; + +import static org.eclipse.m2e.editor.pom.FormUtils.nvl; +import static org.eclipse.m2e.editor.pom.FormUtils.setButton; +import static org.eclipse.m2e.editor.pom.FormUtils.setText; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.command.RemoveCommand; +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.Separator; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.viewers.ICellModifier; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.window.Window; +import org.eclipse.m2e.core.actions.OpenPomAction; +import org.eclipse.m2e.core.actions.OpenUrlAction; +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.index.IIndex; +import org.eclipse.m2e.core.index.IndexedArtifactFile; +import org.eclipse.m2e.core.ui.dialogs.MavenRepositorySearchDialog; +import org.eclipse.m2e.core.util.M2EUtils; +import org.eclipse.m2e.core.util.ProposalUtil; +import org.eclipse.m2e.core.util.search.Packaging; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.composites.PluginsComposite.PluginFilter; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.editor.pom.FormUtils; +import org.eclipse.m2e.editor.pom.MavenPomEditorPage; +import org.eclipse.m2e.editor.pom.SearchControl; +import org.eclipse.m2e.editor.pom.SearchMatcher; +import org.eclipse.m2e.editor.pom.ValueProvider; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.m2e.model.edit.pom.PomPackage; +import org.eclipse.m2e.model.edit.pom.ReportPlugin; +import org.eclipse.m2e.model.edit.pom.ReportSet; +import org.eclipse.m2e.model.edit.pom.Reporting; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +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.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.events.HyperlinkAdapter; +import org.eclipse.ui.forms.events.HyperlinkEvent; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Hyperlink; +import org.eclipse.ui.forms.widgets.Section; + + +/** + * @author Eugene Kuleshov + * @author Dmitry Platonoff + */ +public class ReportingComposite extends Composite { + + protected static PomPackage POM_PACKAGE = PomPackage.eINSTANCE; + + FormToolkit toolkit = new FormToolkit(Display.getCurrent()); + + MavenPomEditorPage editorPage; + + Text outputFolderText; + + Text groupIdText; + + Text artifactIdText; + + Text versionText; + + Button pluginInheritedButton; + + Hyperlink pluginConfigureButton; + + ListEditorComposite<ReportSet> reportSetsEditor; + + ListEditorComposite<String> reportsEditor; + + ListEditorComposite<ReportPlugin> reportPluginsEditor; + + Section pluginDetailsSection; + + Button reportSetInheritedButton; + + Hyperlink reportSetConfigureButton; + + Button excludeDefaultsButton; + + Section reportSetDetailsSection; + + Section reportSetsSection; + + Action openWebPageAction; + +// Action reportPluginAddAction; + + Action reportPluginSelectAction; + + ViewerFilter searchFilter; + + SearchControl searchControl; + + SearchMatcher searchMatcher; + + // model + + ValueProvider<Reporting> reportingProvider; + + ReportPlugin currentReportPlugin = null; + + ReportSet currentReportSet = null; + + + public ReportingComposite(Composite parent, MavenPomEditorPage page, int style) { + super(parent, style); + this.editorPage = page; + GridLayout gridLayout = new GridLayout(1, false); + gridLayout.marginWidth = 0; + setLayout(gridLayout); + toolkit.adapt(this); + + SashForm horizontalSash = new SashForm(this, SWT.NONE); + horizontalSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + toolkit.adapt(horizontalSash, true, true); + + createContentSection(horizontalSash); + + Composite verticalSash = toolkit.createComposite(horizontalSash); + GridLayout reportingPluginDetailsLayout = new GridLayout(); + reportingPluginDetailsLayout.marginWidth = 0; + reportingPluginDetailsLayout.marginHeight = 0; + verticalSash.setLayout(reportingPluginDetailsLayout); + + createPluginDetailsSection(verticalSash); + createReportSetDetails(verticalSash); + + horizontalSash.setWeights(new int[] {1, 1}); + } + + private void createContentSection(SashForm horizontalSash) { + Composite composite_1 = toolkit.createComposite(horizontalSash, SWT.NONE); + GridLayout gridLayout = new GridLayout(); + gridLayout.marginWidth = 0; + gridLayout.marginHeight = 0; + composite_1.setLayout(gridLayout); + toolkit.paintBordersFor(composite_1); + + Section contentSection = toolkit.createSection(composite_1, ExpandableComposite.TITLE_BAR); + contentSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + contentSection.setText(Messages.ReportingComposite_section_Content); + + Composite composite = toolkit.createComposite(contentSection, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + contentSection.setClient(composite); + toolkit.paintBordersFor(composite); + + toolkit.createLabel(composite, Messages.ReportingComposite_lblOutputFolder, SWT.NONE); + + outputFolderText = toolkit.createText(composite, null, SWT.NONE); + outputFolderText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + excludeDefaultsButton = toolkit.createButton(composite, Messages.ReportingComposite_btnExcludeDefaults, SWT.CHECK); + excludeDefaultsButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2, 1)); + + Section reportingPluginsSection = toolkit.createSection(composite_1, ExpandableComposite.TITLE_BAR); + reportingPluginsSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true)); + reportingPluginsSection.setText(Messages.ReportingComposite_sectionReportingPlugins); + + reportPluginsEditor = new ListEditorComposite<ReportPlugin>(reportingPluginsSection, SWT.NONE, true); + reportingPluginsSection.setClient(reportPluginsEditor); + toolkit.paintBordersFor(reportPluginsEditor); + toolkit.adapt(reportPluginsEditor); + + final ReportPluginsLabelProvider labelProvider = new ReportPluginsLabelProvider(); + reportPluginsEditor.setLabelProvider(labelProvider); + reportPluginsEditor.setContentProvider(new ListEditorContentProvider<ReportPlugin>()); + + reportPluginsEditor.addSelectionListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + List<ReportPlugin> selection = reportPluginsEditor.getSelection(); + updateReportPluginDetails(selection.size() == 1 ? selection.get(0) : null); + } + }); + + reportPluginsEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + createReportingPlugin(null, null, null); + } + }); + + reportPluginsEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = editorPage.getEditingDomain(); + + Reporting reporting = reportingProvider.getValue(); + + if(reporting != null) { + List<ReportPlugin> pluginList = reportPluginsEditor.getSelection(); + for(ReportPlugin reportPlugin : pluginList) { + Command removeCommand = RemoveCommand.create(editingDomain, reporting, POM_PACKAGE + .getReporting_Plugins(), reportPlugin); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + updateContent(reporting); + } + } + }); + + reportPluginsEditor.setAddButtonListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e){ + MavenRepositorySearchDialog dialog = new MavenRepositorySearchDialog(getShell(), // + Messages.ReportingComposite_searchDialog_addPlugin, IIndex.SEARCH_PLUGIN, Collections.<ArtifactKey>emptySet()); + if(dialog.open() == Window.OK) { + IndexedArtifactFile af = (IndexedArtifactFile) dialog.getFirstResult(); + if(af != null) { + createReportingPlugin(af.group, af.artifact, af.version); + } + } + } + }); +// reportPluginAddAction = new Action("Add Report Plugin", MavenEditorImages.ADD_PLUGIN) { +// public void run() { +// +// } +// }; +// reportPluginAddAction.setEnabled(false); +// toolBarManager.add(reportPluginAddAction); +// toolBarManager.add(new Separator()); + ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); + + + toolBarManager.add(new Action(Messages.ReportingComposite_action_showGroupId, MavenEditorImages.SHOW_GROUP) { + { + setChecked(true); + } + public int getStyle() { + return AS_CHECK_BOX; + } + public void run() { + labelProvider.setShowGroupId(isChecked()); + reportPluginsEditor.getViewer().refresh(); + } + }); + + toolBarManager.add(new Action(Messages.ReportingComposite_action_filter, MavenEditorImages.FILTER) { + { + setChecked(true); + } + public int getStyle() { + return AS_CHECK_BOX; + } + public void run() { + TableViewer viewer = reportPluginsEditor.getViewer(); + if(isChecked()) { + viewer.addFilter(searchFilter); + } else { + viewer.removeFilter(searchFilter); + } + viewer.refresh(); + if(isChecked()) { + searchControl.getSearchText().setFocus(); + } + } + }); + + Composite toolbarComposite = toolkit.createComposite(reportingPluginsSection); + GridLayout toolbarLayout = new GridLayout(1, true); + toolbarLayout.marginHeight = 0; + toolbarLayout.marginWidth = 0; + toolbarComposite.setLayout(toolbarLayout); + toolbarComposite.setBackground(null); + + toolBarManager.createControl(toolbarComposite); + reportingPluginsSection.setTextClient(toolbarComposite); + + } + + private void createPluginDetailsSection(Composite verticalSash) { + pluginDetailsSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR); + pluginDetailsSection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + pluginDetailsSection.setText(Messages.ReportingComposite_section_reportingPluginDetails); + + Composite pluginDetailsComposite = toolkit.createComposite(pluginDetailsSection, SWT.NONE); + GridLayout gridLayout_1 = new GridLayout(2, false); + gridLayout_1.marginWidth = 2; + gridLayout_1.marginHeight = 2; + pluginDetailsComposite.setLayout(gridLayout_1); + pluginDetailsSection.setClient(pluginDetailsComposite); + toolkit.paintBordersFor(pluginDetailsComposite); + + toolkit.createLabel(pluginDetailsComposite, Messages.ReportingComposite_lblGroupId, SWT.NONE); + + groupIdText = toolkit.createText(pluginDetailsComposite, null, SWT.NONE); + GridData gd_groupIdText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_groupIdText.horizontalIndent = 4; + groupIdText.setLayoutData(gd_groupIdText); + groupIdText.setData("name", "groupIdText"); //$NON-NLS-1$ //$NON-NLS-2$ + ProposalUtil.addGroupIdProposal(editorPage.getProject(), groupIdText, Packaging.ALL); + M2EUtils.addRequiredDecoration(groupIdText); + + Hyperlink artifactIdHyperlink = toolkit.createHyperlink(pluginDetailsComposite, Messages.ReportingComposite_lblArtifactId, SWT.NONE); + artifactIdHyperlink.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + final String groupId = groupIdText.getText(); + final String artifactId = artifactIdText.getText(); + final String version = versionText.getText(); + new Job("Opening " + groupId + ":" + artifactId + ":" + version) { + protected IStatus run(IProgressMonitor arg0) { + OpenPomAction.openEditor(groupId, artifactId, version, null); + return Status.OK_STATUS; + } + }.schedule(); + } + }); + + artifactIdText = toolkit.createText(pluginDetailsComposite, null, SWT.NONE); + GridData gd_artifactIdText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_artifactIdText.horizontalIndent = 4; + artifactIdText.setLayoutData(gd_artifactIdText); + artifactIdText.setData("name", "artifactIdText"); //$NON-NLS-1$ //$NON-NLS-2$ + ProposalUtil.addArtifactIdProposal(editorPage.getProject(), groupIdText, artifactIdText, Packaging.ALL); + M2EUtils.addRequiredDecoration(artifactIdText); + + toolkit.createLabel(pluginDetailsComposite, Messages.ReportingComposite_lblVersion, SWT.NONE); + + versionText = toolkit.createText(pluginDetailsComposite, null, SWT.NONE); + GridData gd_versionText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_versionText.horizontalIndent = 4; + versionText.setLayoutData(gd_versionText); + versionText.setData("name", "versionText"); //$NON-NLS-1$ //$NON-NLS-2$ + ProposalUtil.addVersionProposal(editorPage.getProject(), groupIdText, artifactIdText, versionText, Packaging.ALL); + + Composite pluginConfigureComposite = toolkit.createComposite(pluginDetailsComposite, SWT.NONE); + GridData pluginConfigureCompositeData = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2, 1); + pluginConfigureComposite.setLayoutData(pluginConfigureCompositeData); + GridLayout pluginConfigureCompositeLayout = new GridLayout(2, false); + pluginConfigureCompositeLayout.marginWidth = 0; + pluginConfigureCompositeLayout.marginHeight = 0; + pluginConfigureComposite.setLayout(pluginConfigureCompositeLayout); + toolkit.paintBordersFor(pluginConfigureComposite); + + pluginInheritedButton = toolkit.createButton(pluginConfigureComposite, Messages.ReportingComposite_btnInherited, SWT.CHECK); + pluginInheritedButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); + + pluginConfigureButton = toolkit.createHyperlink(pluginConfigureComposite, Messages.ReportingComposite_link_Configuration, SWT.NONE); + pluginConfigureButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); + pluginConfigureButton.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + if(currentReportPlugin != null) { + EObject element = currentReportPlugin.getConfiguration(); + editorPage.getPomEditor().showInSourceEditor(element == null ? currentReportPlugin : element); + } + } + }); + pluginDetailsComposite.setTabList(new Control[] {groupIdText, artifactIdText, versionText, pluginConfigureComposite}); + + openWebPageAction = new Action(Messages.ReportingComposite_action_openWeb, MavenEditorImages.WEB_PAGE) { + public void run() { + final String groupId = groupIdText.getText(); + final String artifactId = artifactIdText.getText(); + final String version = versionText.getText(); + new Job("Opening " + groupId + ":" + artifactId + ":" + version) { + protected IStatus run(IProgressMonitor monitor) { + OpenUrlAction.openBrowser(OpenUrlAction.ID_PROJECT, groupId, artifactId, version, monitor); + return Status.OK_STATUS; + } + }.schedule(); + + } + }; + openWebPageAction.setEnabled(false); + + reportPluginSelectAction = new Action(Messages.ReportingComposite_action_selectReportingPlugin, MavenEditorImages.SELECT_PLUGIN) { + public void run() { + MavenRepositorySearchDialog dialog = new MavenRepositorySearchDialog(getShell(), // + Messages.ReportingComposite_searchDialog_selectPlugin, IIndex.SEARCH_PLUGIN, Collections.<ArtifactKey>emptySet()); + if(dialog.open() == Window.OK) { + IndexedArtifactFile af = (IndexedArtifactFile) dialog.getFirstResult(); + if(af != null) { + groupIdText.setText(nvl(af.group)); + artifactIdText.setText(nvl(af.artifact)); + versionText.setText(nvl(af.version)); + } + } + } + }; + reportPluginSelectAction.setEnabled(false); + + ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); + toolBarManager.add(reportPluginSelectAction); + toolBarManager.add(new Separator()); + toolBarManager.add(openWebPageAction); + + Composite toolbarComposite = toolkit.createComposite(pluginDetailsSection); + GridLayout toolbarLayout = new GridLayout(1, true); + toolbarLayout.marginHeight = 0; + toolbarLayout.marginWidth = 0; + toolbarComposite.setLayout(toolbarLayout); + toolbarComposite.setBackground(null); + + toolBarManager.createControl(toolbarComposite); + pluginDetailsSection.setTextClient(toolbarComposite); + + } + + private void createReportSetDetails(Composite verticalSash) { + reportSetsSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR); + reportSetsSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + reportSetsSection.setText(Messages.ReportingComposite_section_reportSets); + + reportSetsEditor = new ListEditorComposite<ReportSet>(reportSetsSection, SWT.NONE); + reportSetsSection.setClient(reportSetsEditor); + toolkit.paintBordersFor(reportSetsEditor); + toolkit.adapt(reportSetsEditor); + + reportSetsEditor.setContentProvider(new ListEditorContentProvider<ReportSet>()); + reportSetsEditor.setLabelProvider(new LabelProvider() { + public String getText(Object element) { + if(element instanceof ReportSet) { + ReportSet reportSet = (ReportSet) element; + String id = reportSet.getId(); + return id == null || id.length() == 0 ? "?" : id; + } + return ""; //$NON-NLS-1$ + } + + public Image getImage(Object element) { + // TODO add icon for report set + return null; + } + }); + + reportSetsEditor.addSelectionListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + List<ReportSet> selection = reportSetsEditor.getSelection(); + updateReportSetDetails(selection.size() == 1 ? selection.get(0) : null); + } + }); + + reportSetsEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if(currentReportPlugin == null) { + return; + } + + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = editorPage.getEditingDomain(); + + boolean reportSetsCreated = false; + + ReportSet reportSet = PomFactory.eINSTANCE.createReportSet(); + Command addReportSet = AddCommand.create(editingDomain, currentReportPlugin, POM_PACKAGE.getReportPlugin_ReportSets(), + reportSet); + compoundCommand.append(addReportSet); + editingDomain.getCommandStack().execute(compoundCommand); + + if(reportSetsCreated) { + updateReportPluginDetails(currentReportPlugin); + } + reportSetsEditor.setSelection(Collections.singletonList(reportSet)); + } + }); + + reportSetsEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if(currentReportPlugin == null) { + return; + } + + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = editorPage.getEditingDomain(); + + + List<ReportSet> reportSetList = reportSetsEditor.getSelection(); + for(ReportSet reportSet : reportSetList) { + Command removeCommand = RemoveCommand.create(editingDomain, currentReportPlugin, POM_PACKAGE + .getReportPlugin_ReportSets(), reportSet); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + updateReportPluginDetails(currentReportPlugin); + } + }); + + reportSetsEditor.setCellModifier(new ICellModifier() { + public boolean canModify(Object element, String property) { + return true; + } + + public Object getValue(Object element, String property) { + if(element instanceof ReportSet) { + String id = ((ReportSet) element).getId(); + return id == null ? "" : id; //$NON-NLS-1$ + } + return element; + } + + public void modify(Object element, String property, Object value) { + EditingDomain editingDomain = editorPage.getEditingDomain(); + if(!value.equals(currentReportSet.getId())) { + Command command = SetCommand.create(editingDomain, currentReportSet, POM_PACKAGE.getReportSet_Id(), value); + editingDomain.getCommandStack().execute(command); + } + } + }); + + reportSetDetailsSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR); + reportSetDetailsSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + reportSetDetailsSection.setText(Messages.ReportingComposite_section_reportSetReports); + + Composite reportSetDetailsComposite = toolkit.createComposite(reportSetDetailsSection, SWT.NONE); + GridLayout gridLayout = new GridLayout(1, false); + gridLayout.marginWidth = 1; + gridLayout.marginHeight = 1; + reportSetDetailsComposite.setLayout(gridLayout); + reportSetDetailsSection.setClient(reportSetDetailsComposite); + toolkit.paintBordersFor(reportSetDetailsComposite); + + reportsEditor = new ListEditorComposite<String>(reportSetDetailsComposite, SWT.NONE); + reportsEditor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + toolkit.paintBordersFor(reportsEditor); + toolkit.adapt(reportsEditor); + + reportsEditor.setContentProvider(new ListEditorContentProvider<String>()); + reportsEditor.setLabelProvider(new StringLabelProvider(MavenEditorImages.IMG_REPORT)); + + reportsEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if(currentReportSet == null) { + return; + } + + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = editorPage.getEditingDomain(); + + Command addReport = AddCommand.create(editingDomain, currentReportSet, POM_PACKAGE.getReportSet_Reports(), "?"); + compoundCommand.append(addReport); + editingDomain.getCommandStack().execute(compoundCommand); + + reportsEditor.refresh(); + } + }); + + reportsEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if(currentReportSet == null) { + return; + } + + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = editorPage.getEditingDomain(); + + List<String> reportList = reportsEditor.getSelection(); + for(String report : reportList) { + Command removeCommand = RemoveCommand.create(editingDomain, currentReportSet, POM_PACKAGE.getReportSet_Reports(), + report); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + } + }); + + reportsEditor.setCellModifier(new ICellModifier() { + public boolean canModify(Object element, String property) { + return true; + } + + public Object getValue(Object element, String property) { + return element; + } + + public void modify(Object element, String property, Object value) { + EditingDomain editingDomain = editorPage.getEditingDomain(); + Command command = SetCommand.create(editingDomain, currentReportSet, POM_PACKAGE + .getReportSet_Reports(), value, reportsEditor.getViewer().getTable().getSelectionIndex()); + editingDomain.getCommandStack().execute(command); + } + }); + + Composite reportSetConfigureComposite = toolkit.createComposite(reportSetDetailsComposite, SWT.NONE); + reportSetConfigureComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, false)); + GridLayout reportSetConfigureCompositeLayout = new GridLayout(); + reportSetConfigureCompositeLayout.numColumns = 2; + reportSetConfigureCompositeLayout.marginWidth = 0; + reportSetConfigureCompositeLayout.marginHeight = 0; + reportSetConfigureComposite.setLayout(reportSetConfigureCompositeLayout); + toolkit.paintBordersFor(reportSetConfigureComposite); + + reportSetInheritedButton = toolkit.createButton(reportSetConfigureComposite, Messages.ReportingComposite_btnInherited, SWT.CHECK); + reportSetInheritedButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); + + reportSetConfigureButton = toolkit.createHyperlink(reportSetConfigureComposite, Messages.ReportingComposite_link_Configuration, SWT.NONE); + reportSetConfigureButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false)); + reportSetConfigureButton.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + if(currentReportSet != null) { + EObject element = currentReportSet.getConfiguration(); + editorPage.getPomEditor().showInSourceEditor(element == null ? currentReportSet : element); + } + } + }); + + // XXX implement editor actions + } + + protected void updateReportPluginDetails(ReportPlugin reportPlugin) { + currentReportPlugin = reportPlugin; + + if(editorPage != null) { + editorPage.removeNotifyListener(groupIdText); + editorPage.removeNotifyListener(artifactIdText); + editorPage.removeNotifyListener(versionText); + editorPage.removeNotifyListener(pluginInheritedButton); + } + + if(editorPage == null || reportPlugin == null) { + FormUtils.setEnabled(pluginDetailsSection, false); + FormUtils.setEnabled(reportSetsSection, false); + reportPluginSelectAction.setEnabled(false); + openWebPageAction.setEnabled(false); + + setText(groupIdText, ""); //$NON-NLS-1$ + setText(artifactIdText, ""); //$NON-NLS-1$ + setText(versionText, ""); //$NON-NLS-1$ + + pluginInheritedButton.setSelection(false); + + reportSetsEditor.setInput(null); + + updateReportSetDetails(null); + + return; + } + + FormUtils.setEnabled(pluginDetailsSection, true); + FormUtils.setEnabled(reportSetsSection, true); + FormUtils.setReadonly(pluginDetailsSection, editorPage.isReadOnly()); + FormUtils.setReadonly(reportSetsSection, editorPage.isReadOnly()); + reportPluginSelectAction.setEnabled(!editorPage.isReadOnly()); + openWebPageAction.setEnabled(true); + + setText(groupIdText, reportPlugin.getGroupId()); + setText(artifactIdText, reportPlugin.getArtifactId()); + setText(versionText, reportPlugin.getVersion()); + + pluginInheritedButton.setSelection(Boolean.parseBoolean(reportPlugin.getInherited())); + + ValueProvider<ReportPlugin> provider = new ValueProvider.DefaultValueProvider<ReportPlugin>(reportPlugin); + editorPage.setModifyListener(groupIdText, provider, POM_PACKAGE.getReportPlugin_GroupId(), ""); //$NON-NLS-1$ + editorPage.setModifyListener(artifactIdText, provider, POM_PACKAGE.getReportPlugin_ArtifactId(), ""); //$NON-NLS-1$ + editorPage.setModifyListener(versionText, provider, POM_PACKAGE.getReportPlugin_Version(), ""); //$NON-NLS-1$ + editorPage.setModifyListener(pluginInheritedButton, provider, POM_PACKAGE.getReportPlugin_Inherited(), "false"); + editorPage.registerListeners(); + + reportSetsEditor.setInput(reportPlugin.getReportSets()); + + updateReportSetDetails(null); + } + + protected void updateReportSetDetails(ReportSet reportSet) { + if(editorPage != null) { + editorPage.removeNotifyListener(reportSetInheritedButton); + } + + currentReportSet = reportSet; + + if(reportSet == null || editorPage == null) { + FormUtils.setEnabled(reportSetDetailsSection, false); + reportSetInheritedButton.setSelection(false); + reportsEditor.setInput(null); + return; + } + + FormUtils.setEnabled(reportSetDetailsSection, true); + FormUtils.setReadonly(reportSetDetailsSection, editorPage.isReadOnly()); + + reportSetInheritedButton.setSelection(Boolean.parseBoolean(reportSet.getInherited())); + ValueProvider<ReportSet> provider = new ValueProvider.DefaultValueProvider<ReportSet>(reportSet); + editorPage.setModifyListener(reportSetInheritedButton, provider, POM_PACKAGE.getReportSet_Inherited(), "false"); + editorPage.registerListeners(); + + reportsEditor.setInput(reportSet.getReports()); + } + + public void loadData(MavenPomEditorPage editorPage, ValueProvider<Reporting> reportingProvider) { + this.editorPage = editorPage; + this.reportingProvider = reportingProvider; + +// reportPluginAddAction.setEnabled(!parent.getPomEditor().isReadOnly()); + + updateContent(reportingProvider.getValue()); + } + + void updateContent(Reporting reporting) { + if(editorPage != null) { + editorPage.removeNotifyListener(outputFolderText); + editorPage.removeNotifyListener(excludeDefaultsButton); + } + + if(reporting == null) { + setText(outputFolderText,""); //$NON-NLS-1$ + setButton(excludeDefaultsButton, false); + reportPluginsEditor.setInput(null); + } else { + setText(outputFolderText,reporting.getOutputDirectory()); + setButton(excludeDefaultsButton, "true".equals(reporting.getExcludeDefaults())); + reportPluginsEditor.setInput(reporting.getPlugins()); + } + + editorPage.setModifyListener(outputFolderText, reportingProvider, POM_PACKAGE.getReporting_OutputDirectory(), ""); //$NON-NLS-1$ + editorPage.setModifyListener(excludeDefaultsButton, reportingProvider, POM_PACKAGE.getReporting_ExcludeDefaults(), "false"); + editorPage.registerListeners(); + + updateReportPluginDetails(null); + } + + public void updateView(MavenPomEditorPage editorPage, Notification notification) { + EObject object = (EObject) notification.getNotifier(); + Object feature = notification.getFeature(); + + if(object instanceof Reporting || feature == PomPackage.Literals.REPORTING__PLUGINS) { + reportPluginsEditor.refresh(); + } else if(object instanceof ReportPlugin) { + reportPluginsEditor.refresh(); + + Object notificationObject = MavenPomEditorPage.getFromNotification(notification); + if(object == currentReportPlugin && (notificationObject == null || notificationObject instanceof ReportPlugin)) { + updateReportPluginDetails((ReportPlugin) notificationObject); + } + } else if(feature == PomPackage.Literals.REPORT_PLUGIN__REPORT_SETS || object instanceof ReportSet) { + reportSetsEditor.refresh(); + } else if(feature == PomPackage.Literals.REPORT_SET__REPORTS) { + reportsEditor.refresh(); + } + } + + void createReportingPlugin(String groupId, String artifactId, String version) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = editorPage.getEditingDomain(); + + boolean reportsCreated = false; + + Reporting reporting = reportingProvider.getValue(); + if(reporting == null) { + reporting = reportingProvider.create(editingDomain, compoundCommand); + reportsCreated = true; + } + + + ReportPlugin reportPlugin = PomFactory.eINSTANCE.createReportPlugin(); + reportPlugin.setGroupId(groupId); + reportPlugin.setArtifactId(artifactId); + reportPlugin.setVersion(version); + + Command addReportPlugin = AddCommand.create(editingDomain, reporting, + POM_PACKAGE.getReporting_Plugins(), reportPlugin); + compoundCommand.append(addReportPlugin); + + editingDomain.getCommandStack().execute(compoundCommand); + + if(reportsCreated) { + updateContent(reporting); + } else { + updateReportPluginDetails(reportPlugin); + } + reportPluginsEditor.setSelection(Collections.singletonList(reportPlugin)); + groupIdText.setFocus(); + } + + public void setSearchControl(SearchControl searchControl) { + if(this.searchControl!=null) { + return; + } + + this.searchMatcher = new SearchMatcher(searchControl); + this.searchFilter = new PluginFilter(searchMatcher); + this.searchControl = searchControl; + this.searchControl.getSearchText().addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + selectPlugins(reportPluginsEditor, reportingProvider); + updateReportPluginDetails(null); + } + + private void selectPlugins(ListEditorComposite<ReportPlugin> editor, ValueProvider<Reporting> provider) { + List<ReportPlugin> plugins = new ArrayList<ReportPlugin>(); + Reporting value = provider.getValue(); + if(value != null) { + for(ReportPlugin p : value.getPlugins()) { + if(searchMatcher.isMatchingArtifact(p.getGroupId(), p.getArtifactId())) { + plugins.add(p); + } + } + } + editor.setSelection(plugins); + editor.refresh(); + } + }); + //we add filter here as the default behaviour is to filter.. + TableViewer viewer = reportPluginsEditor.getViewer(); + viewer.addFilter(searchFilter); + + } + + final class ReportPluginsLabelProvider extends LabelProvider { + + private boolean showGroupId = true; + + public void setShowGroupId(boolean showGroupId) { + this.showGroupId = showGroupId; + } + + public String getText(Object element) { + if(element instanceof ReportPlugin) { + ReportPlugin reportPlugin = (ReportPlugin) element; + + String groupId = reportPlugin.getGroupId(); + String artifactId = reportPlugin.getArtifactId(); + String version = reportPlugin.getVersion(); + + String label = ""; //$NON-NLS-1$ + + if(showGroupId) { + label = (groupId == null ? "?" : groupId) + " : "; + } + + label += artifactId == null ? "?" : artifactId; + + if(version != null) { + label += " : " + version; + } + + return label; + } + return super.getText(element); + } + + public Image getImage(Object element) { + return MavenEditorImages.IMG_PLUGIN; + } + + } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/RepositoriesComposite.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/RepositoriesComposite.java new file mode 100644 index 00000000..1e3d12b4 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/RepositoriesComposite.java @@ -0,0 +1,1287 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.composites; + +import static org.eclipse.m2e.editor.pom.FormUtils.isEmpty; +import static org.eclipse.m2e.editor.pom.FormUtils.setButton; +import static org.eclipse.m2e.editor.pom.FormUtils.setText; +import static org.eclipse.m2e.editor.pom.FormUtils.nvl; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.command.RemoveCommand; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.m2e.core.actions.OpenPomAction; +import org.eclipse.m2e.core.wizards.WidthGroup; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.editor.pom.FormUtils; +import org.eclipse.m2e.editor.pom.MavenPomEditorPage; +import org.eclipse.m2e.editor.pom.ValueProvider; +import org.eclipse.m2e.model.edit.pom.DeploymentRepository; +import org.eclipse.m2e.model.edit.pom.DistributionManagement; +import org.eclipse.m2e.model.edit.pom.Model; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.m2e.model.edit.pom.PomPackage; +import org.eclipse.m2e.model.edit.pom.Relocation; +import org.eclipse.m2e.model.edit.pom.Repository; +import org.eclipse.m2e.model.edit.pom.RepositoryPolicy; +import org.eclipse.m2e.model.edit.pom.Site; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.events.ExpansionAdapter; +import org.eclipse.ui.forms.events.ExpansionEvent; +import org.eclipse.ui.forms.events.HyperlinkAdapter; +import org.eclipse.ui.forms.events.HyperlinkEvent; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Hyperlink; +import org.eclipse.ui.forms.widgets.Section; + + +/** + * @author Eugene Kuleshov + */ +public class RepositoriesComposite extends Composite { + + static PomPackage POM_PACKAGE = PomPackage.eINSTANCE; + + MavenPomEditorPage parent; + + FormToolkit toolkit = new FormToolkit(Display.getCurrent()); + + // controls + + ListEditorComposite<Repository> repositoriesEditor; + + ListEditorComposite<Repository> pluginRepositoriesEditor; + + Section repositoryDetailsSection; + + Section releaseRepositorySection; + + Section snapshotRepositorySection; + + Section projectSiteSection; + + Section relocationSection; + + Text repositoryIdText; + + Text repositoryNameText; + + Text repositoryUrlText; + + CCombo repositoryLayoutCombo; + + Button releasesEnabledButton; + + CCombo releasesUpdatePolicyCombo; + + CCombo releasesChecksumPolicyCombo; + + Label releasesChecksumPolicyLabel; + + Label releasesUpdatePolicyLabel; + + Button snapshotsEnabledButton; + + CCombo snapshotsUpdatePolicyCombo; + + CCombo snapshotsChecksumPolicyCombo; + + Label snapshotsChecksumPolicyLabel; + + Label snapshotsUpdatePolicyLabel; + + Text projectSiteIdText; + + Text projectSiteNameText; + + Text projectSiteUrlText; + + Text projectDownloadUrlText; + + Text relocationGroupIdText; + + Text relocationArtifactIdText; + + Text relocationVersionText; + + Text relocationMessageText; + + Text snapshotRepositoryIdText; + + Text snapshotRepositoryNameText; + + Text snapshotRepositoryUrlText; + + CCombo snapshotRepositoryLayoutCombo; + + Button snapshotRepositoryUniqueVersionButton; + + Text releaseRepositoryIdText; + + Text releaseRepositoryNameText; + + Text releaseRepositoryUrlText; + + CCombo releaseRepositoryLayoutCombo; + + Button releaseRepositoryUniqueVersionButton; + + WidthGroup leftWidthGroup = new WidthGroup(); + + WidthGroup rightWidthGroup = new WidthGroup(); + + Composite projectSiteComposite; + + Composite releaseDistributionRepositoryComposite; + + Composite relocationComposite; + + Composite snapshotRepositoryComposite; + + boolean changingSelection = false; + + // model + + // Model model; + Repository currentRepository; + + Model model; + + ValueProvider<DistributionManagement> distributionManagementProvider; + + public RepositoriesComposite(Composite parent, int flags) { + super(parent, flags); + + toolkit.adapt(this); + + GridLayout gridLayout = new GridLayout(1, true); + gridLayout.marginWidth = 0; + setLayout(gridLayout); + + SashForm horizontalSash = new SashForm(this, SWT.NONE); + horizontalSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + SashForm verticalSash = new SashForm(horizontalSash, SWT.VERTICAL); + toolkit.adapt(verticalSash, true, true); + + createRepositoriesSection(verticalSash); + createPluginRepositoriesSection(verticalSash); + + verticalSash.setWeights(new int[] {1, 1}); + + createRepositoryDetailsSection(horizontalSash); + + toolkit.adapt(horizontalSash, true, true); + horizontalSash.setWeights(new int[] {1, 1}); + + SashForm repositoriesSash = new SashForm(this, SWT.NONE); + repositoriesSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + toolkit.adapt(repositoriesSash, true, true); + + createReleaseRepositorySection(repositoriesSash); + createSnapshotRepositorySection(repositoriesSash); + + repositoriesSash.setWeights(new int[] {1, 1}); + + SashForm projectSiteSash = new SashForm(this, SWT.NONE); + projectSiteSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + toolkit.adapt(projectSiteSash, true, true); + + createProjectSiteSection(projectSiteSash); + createRelocationSection(projectSiteSash); + + projectSiteSash.setWeights(new int[] {1, 1}); + } + + public void dispose() { + // projectSiteComposite.removeControlListener(leftWidthGroup); + // releaseDistributionRepositoryComposite.removeControlListener(leftWidthGroup); + + // snapshotRepositoryComposite.removeControlListener(rightWidthGroup); + // relocationComposite.removeControlListener(rightWidthGroup); + + super.dispose(); + } + + private void createRepositoriesSection(SashForm verticalSash) { + Section repositoriesSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR | ExpandableComposite.COMPACT); + repositoriesSection.setText(Messages.RepositoriesComposite_section_repositories); + + repositoriesEditor = new ListEditorComposite<Repository>(repositoriesSection, SWT.NONE); + + repositoriesEditor.setLabelProvider(new RepositoryLabelProvider()); + repositoriesEditor.setContentProvider(new ListEditorContentProvider<Repository>()); + + repositoriesEditor.addSelectionListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + List<Repository> selection = repositoriesEditor.getSelection(); + updateRepositoryDetailsSection(selection.size() == 1 ? selection.get(0) : null); + + if(!selection.isEmpty()) { + changingSelection = true; + pluginRepositoriesEditor.setSelection(Collections.<Repository> emptyList()); + changingSelection = false; + } + } + }); + + repositoriesEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + Repository repository = PomFactory.eINSTANCE.createRepository(); + Command addCommand = AddCommand.create(editingDomain, model, POM_PACKAGE.getModel_Repositories(), + repository); + compoundCommand.append(addCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + + repositoriesEditor.setSelection(Collections.singletonList(repository)); + updateRepositoryDetailsSection(repository); + repositoryIdText.setFocus(); + } + }); + + repositoriesEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + List<Repository> list = repositoriesEditor.getSelection(); + for(Repository repository : list) { + Command removeCommand = RemoveCommand.create(editingDomain, model, POM_PACKAGE + .getModel_Repositories(), repository); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + updateRepositoryDetailsSection(null); + } + }); + + toolkit.paintBordersFor(repositoriesEditor); + toolkit.adapt(repositoriesEditor); + repositoriesSection.setClient(repositoriesEditor); + } + + private void createPluginRepositoriesSection(SashForm verticalSash) { + Section pluginRepositoriesSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR | ExpandableComposite.COMPACT); + pluginRepositoriesSection.setText(Messages.RepositoriesComposite_section_pluginRepositories); + + pluginRepositoriesEditor = new ListEditorComposite<Repository>(pluginRepositoriesSection, SWT.NONE); + + pluginRepositoriesEditor.setLabelProvider(new RepositoryLabelProvider()); + pluginRepositoriesEditor.setContentProvider(new ListEditorContentProvider<Repository>()); + + pluginRepositoriesEditor.addSelectionListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + List<Repository> selection = pluginRepositoriesEditor.getSelection(); + updateRepositoryDetailsSection(selection.size() == 1 ? selection.get(0) : null); + + if(!selection.isEmpty()) { + changingSelection = true; + repositoriesEditor.setSelection(Collections.<Repository> emptyList()); + changingSelection = false; + } + } + }); + + pluginRepositoriesEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + Repository pluginRepository = PomFactory.eINSTANCE.createRepository(); + Command addCommand = AddCommand.create(editingDomain, model, POM_PACKAGE + .getModel_PluginRepositories(), pluginRepository); + compoundCommand.append(addCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + + pluginRepositoriesEditor.setSelection(Collections.singletonList(pluginRepository)); + updateRepositoryDetailsSection(pluginRepository); + repositoryIdText.setFocus(); + } + }); + + pluginRepositoriesEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + List<Repository> list = pluginRepositoriesEditor.getSelection(); + for(Repository repository : list) { + Command removeCommand = RemoveCommand.create(editingDomain, model, + POM_PACKAGE.getModel_PluginRepositories(), repository); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + updateRepositoryDetailsSection(null); + } + }); + + toolkit.paintBordersFor(pluginRepositoriesEditor); + toolkit.adapt(pluginRepositoriesEditor); + pluginRepositoriesSection.setClient(pluginRepositoriesEditor); + } + + private void createRepositoryDetailsSection(Composite parent) { + repositoryDetailsSection = toolkit.createSection(parent, ExpandableComposite.TITLE_BAR); + repositoryDetailsSection.setText(Messages.RepositoriesComposite_section_repositoryDetails); + + Composite repositoryDetailsComposite = toolkit.createComposite(repositoryDetailsSection); + repositoryDetailsComposite.setLayout(new GridLayout(2, false)); + repositoryDetailsSection.setClient(repositoryDetailsComposite); + toolkit.paintBordersFor(repositoryDetailsComposite); + + Label idLabel = new Label(repositoryDetailsComposite, SWT.NONE); + idLabel.setText(Messages.RepositoriesComposite_lblId); + + repositoryIdText = toolkit.createText(repositoryDetailsComposite, ""); //$NON-NLS-1$ + GridData gd_repositoryIdText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_repositoryIdText.widthHint = 100; + repositoryIdText.setLayoutData(gd_repositoryIdText); + + Label nameLabel = new Label(repositoryDetailsComposite, SWT.NONE); + nameLabel.setText(Messages.RepositoriesComposite_lblName); + + repositoryNameText = toolkit.createText(repositoryDetailsComposite, ""); //$NON-NLS-1$ + repositoryNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + Hyperlink repositoryUrlHyperlink = toolkit.createHyperlink(repositoryDetailsComposite, Messages.RepositoriesComposite_lblUrl, SWT.NONE); + repositoryUrlHyperlink.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + FormUtils.openHyperlink(repositoryUrlText.getText()); + } + }); + + repositoryUrlText = toolkit.createText(repositoryDetailsComposite, ""); //$NON-NLS-1$ + GridData gd_repositoryUrlText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_repositoryUrlText.widthHint = 100; + repositoryUrlText.setLayoutData(gd_repositoryUrlText); + + Label layoutLabel = new Label(repositoryDetailsComposite, SWT.NONE); + layoutLabel.setText(Messages.RepositoriesComposite_lblLayout); + + repositoryLayoutCombo = new CCombo(repositoryDetailsComposite, SWT.FLAT); + repositoryLayoutCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + repositoryLayoutCombo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); + repositoryLayoutCombo.setItems(new String[] {"default", "legacy"}); + + Composite composite = new Composite(repositoryDetailsComposite, SWT.NONE); + composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)); + toolkit.adapt(composite, true, true); + toolkit.paintBordersFor(composite); + GridLayout compositeLayout = new GridLayout(); + compositeLayout.marginBottom = 2; + compositeLayout.marginWidth = 2; + compositeLayout.marginHeight = 0; + compositeLayout.numColumns = 2; + composite.setLayout(compositeLayout); + + releasesEnabledButton = toolkit.createButton(composite, Messages.RepositoriesComposite_btnEnableRelease, SWT.CHECK | SWT.FLAT); + GridData releasesEnabledButtonData = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1); + releasesEnabledButtonData.verticalIndent = 5; + releasesEnabledButton.setLayoutData(releasesEnabledButtonData); + releasesEnabledButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + boolean isEnabled = releasesEnabledButton.getSelection(); + releasesUpdatePolicyLabel.setEnabled(isEnabled); + releasesUpdatePolicyCombo.setEnabled(isEnabled); + releasesChecksumPolicyLabel.setEnabled(isEnabled); + releasesChecksumPolicyCombo.setEnabled(isEnabled); + } + }); + + releasesUpdatePolicyLabel = new Label(composite, SWT.NONE); + releasesUpdatePolicyLabel.setText(Messages.RepositoriesComposite_lblUpdatePolicy); + GridData releasesUpdatePolicyLabelData = new GridData(); + releasesUpdatePolicyLabelData.horizontalIndent = 15; + releasesUpdatePolicyLabel.setLayoutData(releasesUpdatePolicyLabelData); + + releasesUpdatePolicyCombo = new CCombo(composite, SWT.FLAT); + releasesUpdatePolicyCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + releasesUpdatePolicyCombo.setItems(new String[] {"daily", "always", "interval:30", "never"}); + releasesUpdatePolicyCombo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); + toolkit.adapt(releasesUpdatePolicyCombo, true, true); + + releasesChecksumPolicyLabel = new Label(composite, SWT.NONE); + releasesChecksumPolicyLabel.setText(Messages.RepositoriesComposite_lblChecksumPolicy); + GridData releasesChecksumPolicyLabelData = new GridData(); + releasesChecksumPolicyLabelData.horizontalIndent = 15; + releasesChecksumPolicyLabel.setLayoutData(releasesChecksumPolicyLabelData); + + releasesChecksumPolicyCombo = new CCombo(composite, SWT.READ_ONLY | SWT.FLAT); + toolkit.adapt(releasesChecksumPolicyCombo, true, true); + releasesChecksumPolicyCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + releasesChecksumPolicyCombo.setItems(new String[] {"ignore", "fail", "warn"}); + releasesChecksumPolicyCombo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); + + snapshotsEnabledButton = toolkit.createButton(composite, Messages.RepositoriesComposite_btnEnableSnapshots, SWT.CHECK | SWT.FLAT); + GridData snapshotsEnabledButtonData = new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1); + snapshotsEnabledButtonData.verticalIndent = 5; + snapshotsEnabledButton.setLayoutData(snapshotsEnabledButtonData); + snapshotsEnabledButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + boolean isEnabled = releasesEnabledButton.getSelection(); + snapshotsUpdatePolicyLabel.setEnabled(isEnabled); + snapshotsUpdatePolicyCombo.setEnabled(isEnabled); + snapshotsChecksumPolicyLabel.setEnabled(isEnabled); + snapshotsChecksumPolicyCombo.setEnabled(isEnabled); + } + }); + + snapshotsUpdatePolicyLabel = new Label(composite, SWT.NONE); + snapshotsUpdatePolicyLabel.setText(Messages.RepositoriesComposite_lblUpdatePolicy); + GridData snapshotsUpdatePolicyLabelData = new GridData(); + snapshotsUpdatePolicyLabelData.horizontalIndent = 15; + snapshotsUpdatePolicyLabel.setLayoutData(snapshotsUpdatePolicyLabelData); + + snapshotsUpdatePolicyCombo = new CCombo(composite, SWT.FLAT); + snapshotsUpdatePolicyCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + snapshotsUpdatePolicyCombo.setItems(new String[] {"daily", "always", "interval:30", "never"}); + snapshotsUpdatePolicyCombo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); + toolkit.adapt(snapshotsUpdatePolicyCombo, true, true); + toolkit.paintBordersFor(snapshotsUpdatePolicyCombo); + + snapshotsChecksumPolicyLabel = new Label(composite, SWT.NONE); + snapshotsChecksumPolicyLabel.setText(Messages.RepositoriesComposite_lblChecksumPolicy); + GridData checksumPolicyLabelData = new GridData(); + checksumPolicyLabelData.horizontalIndent = 15; + snapshotsChecksumPolicyLabel.setLayoutData(checksumPolicyLabelData); + toolkit.adapt(snapshotsChecksumPolicyLabel, true, true); + + snapshotsChecksumPolicyCombo = new CCombo(composite, SWT.READ_ONLY | SWT.FLAT); + snapshotsChecksumPolicyCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + snapshotsChecksumPolicyCombo.setItems(new String[] {"ignore", "fail", "warn"}); + snapshotsChecksumPolicyCombo.setLayoutData(new GridData()); + toolkit.adapt(snapshotsChecksumPolicyCombo, true, true); + toolkit.paintBordersFor(snapshotsChecksumPolicyCombo); + repositoryDetailsComposite.setTabList(new Control[] {repositoryIdText, repositoryNameText, repositoryUrlText, repositoryLayoutCombo, composite}); + + updateRepositoryDetailsSection(null); + } + + private void createRelocationSection(SashForm sashForm) { + relocationSection = toolkit.createSection(sashForm, ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + relocationSection.setText(Messages.RepositoriesComposite_sectionRelocation); + + relocationComposite = toolkit.createComposite(relocationSection, SWT.NONE); + relocationComposite.setLayout(new GridLayout(2, false)); + toolkit.paintBordersFor(relocationComposite); + relocationSection.setClient(relocationComposite); + relocationComposite.addControlListener(rightWidthGroup); + + Label relocationGroupIdLabel = toolkit.createLabel(relocationComposite, Messages.RepositoriesComposite_lblGroupId, SWT.NONE); + rightWidthGroup.addControl(relocationGroupIdLabel); + + relocationGroupIdText = toolkit.createText(relocationComposite, null, SWT.NONE); + GridData gd_relocationGroupIdText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_relocationGroupIdText.widthHint = 100; + relocationGroupIdText.setLayoutData(gd_relocationGroupIdText); + + Hyperlink relocationArtifactIdHyperlink = toolkit.createHyperlink(relocationComposite, Messages.RepositoriesComposite_lblArtifactid, SWT.NONE); + relocationArtifactIdHyperlink.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + final String groupId = relocationGroupIdText.getText(); + final String artifactId = relocationArtifactIdText.getText(); + final String version = relocationVersionText.getText(); + new Job("Opening " + groupId + ":" + artifactId + ":" + version) { + protected IStatus run(IProgressMonitor arg0) { + OpenPomAction.openEditor(groupId, artifactId, version, null); + return Status.OK_STATUS; + } + }.schedule(); + } + }); + + rightWidthGroup.addControl(relocationArtifactIdHyperlink); + + relocationArtifactIdText = toolkit.createText(relocationComposite, null, SWT.NONE); + GridData gd_relocationArtifactIdText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_relocationArtifactIdText.widthHint = 100; + relocationArtifactIdText.setLayoutData(gd_relocationArtifactIdText); + + Label relocationVersionLabel = toolkit.createLabel(relocationComposite, Messages.RepositoriesComposite_lblVersion, SWT.NONE); + rightWidthGroup.addControl(relocationVersionLabel); + + relocationVersionText = toolkit.createText(relocationComposite, null, SWT.NONE); + GridData gd_relocationVersionText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_relocationVersionText.widthHint = 100; + relocationVersionText.setLayoutData(gd_relocationVersionText); + + Label relocationMessageLabel = toolkit.createLabel(relocationComposite, Messages.RepositoriesComposite_lblMessage, SWT.NONE); + rightWidthGroup.addControl(relocationMessageLabel); + + relocationMessageText = toolkit.createText(relocationComposite, null, SWT.NONE); + GridData gd_relocationMessageText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_relocationMessageText.widthHint = 100; + relocationMessageText.setLayoutData(gd_relocationMessageText); + relocationComposite.setTabList(new Control[] {relocationGroupIdText, relocationArtifactIdText, relocationVersionText, relocationMessageText}); + } + + private void createProjectSiteSection(SashForm sashForm) { + projectSiteSection = toolkit.createSection(sashForm, ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + projectSiteSection.setText(Messages.RepositoriesComposite_section_projectSite); + + projectSiteComposite = toolkit.createComposite(projectSiteSection, SWT.NONE); + projectSiteComposite.setLayout(new GridLayout(2, false)); + toolkit.paintBordersFor(projectSiteComposite); + projectSiteSection.setClient(projectSiteComposite); + projectSiteComposite.addControlListener(leftWidthGroup); + + Label siteIdLabel = toolkit.createLabel(projectSiteComposite, Messages.RepositoriesComposite_lblSiteId, SWT.NONE); + leftWidthGroup.addControl(siteIdLabel); + + projectSiteIdText = toolkit.createText(projectSiteComposite, null, SWT.NONE); + GridData gd_projectSiteIdText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_projectSiteIdText.widthHint = 100; + projectSiteIdText.setLayoutData(gd_projectSiteIdText); + + Label siteNameLabel = toolkit.createLabel(projectSiteComposite, Messages.RepositoriesComposite_lblName, SWT.NONE); + leftWidthGroup.addControl(siteNameLabel); + + projectSiteNameText = toolkit.createText(projectSiteComposite, null, SWT.NONE); + GridData gd_projectSiteNameText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_projectSiteNameText.widthHint = 100; + projectSiteNameText.setLayoutData(gd_projectSiteNameText); + + Hyperlink projectSiteUrlHyperlink = toolkit.createHyperlink(projectSiteComposite, Messages.RepositoriesComposite_lblUrl2, SWT.NONE); + projectSiteUrlHyperlink.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + FormUtils.openHyperlink(projectSiteUrlText.getText()); + } + }); + leftWidthGroup.addControl(projectSiteUrlHyperlink); + + projectSiteUrlText = toolkit.createText(projectSiteComposite, null, SWT.NONE); + GridData gd_projectSiteUrlText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_projectSiteUrlText.widthHint = 100; + projectSiteUrlText.setLayoutData(gd_projectSiteUrlText); + sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + toolkit.adapt(sashForm, true, true); + + Hyperlink projectDownloadUrlHyperlink = toolkit.createHyperlink(projectSiteComposite, Messages.RepositoriesComposite_lblDownload, SWT.NONE); + projectDownloadUrlHyperlink.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + FormUtils.openHyperlink(projectDownloadUrlText.getText()); + } + }); + leftWidthGroup.addControl(projectDownloadUrlHyperlink); + + projectDownloadUrlText = toolkit.createText(projectSiteComposite, null, SWT.NONE); + GridData gd_projectDownloadUrlText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_projectDownloadUrlText.widthHint = 100; + projectDownloadUrlText.setLayoutData(gd_projectDownloadUrlText); + projectSiteComposite.setTabList(new Control[] {projectSiteIdText, projectSiteNameText, projectSiteUrlText, projectDownloadUrlText}); + } + + private void createSnapshotRepositorySection(SashForm distributionManagementSash) { + snapshotRepositorySection = toolkit.createSection(distributionManagementSash, // + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + snapshotRepositorySection.setText(Messages.RepositoriesComposite_section_snapshotDistRepo); + + snapshotRepositoryComposite = toolkit.createComposite(snapshotRepositorySection, SWT.NONE); + snapshotRepositoryComposite.setLayout(new GridLayout(2, false)); + toolkit.paintBordersFor(snapshotRepositoryComposite); + snapshotRepositorySection.setClient(snapshotRepositoryComposite); + snapshotRepositoryComposite.addControlListener(rightWidthGroup); + + Label snapshotRepositoryIdLabel = toolkit.createLabel(snapshotRepositoryComposite, Messages.RepositoriesComposite_lblRepoId, SWT.NONE); + rightWidthGroup.addControl(snapshotRepositoryIdLabel); + + snapshotRepositoryIdText = toolkit.createText(snapshotRepositoryComposite, null, SWT.NONE); + GridData gd_snapshotRepositoryIdText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_snapshotRepositoryIdText.widthHint = 100; + snapshotRepositoryIdText.setLayoutData(gd_snapshotRepositoryIdText); + + Label snapshotRepositoryNameLabel = toolkit.createLabel(snapshotRepositoryComposite, Messages.RepositoriesComposite_lblName, SWT.NONE); + rightWidthGroup.addControl(snapshotRepositoryNameLabel); + + snapshotRepositoryNameText = toolkit.createText(snapshotRepositoryComposite, null, SWT.NONE); + GridData gd_snapshotRepositoryNameText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_snapshotRepositoryNameText.widthHint = 100; + snapshotRepositoryNameText.setLayoutData(gd_snapshotRepositoryNameText); + + Hyperlink snapshotRepositoryUrlHyperlink = toolkit.createHyperlink(snapshotRepositoryComposite, Messages.RepositoriesComposite_lblUrl2, SWT.NONE); + snapshotRepositoryUrlHyperlink.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + FormUtils.openHyperlink(snapshotRepositoryUrlText.getText()); + } + }); + rightWidthGroup.addControl(snapshotRepositoryUrlHyperlink); + + snapshotRepositoryUrlText = toolkit.createText(snapshotRepositoryComposite, null, SWT.NONE); + GridData gd_snapshotRepositoryUrlText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_snapshotRepositoryUrlText.widthHint = 100; + snapshotRepositoryUrlText.setLayoutData(gd_snapshotRepositoryUrlText); + + Label snapshotRepositoryLayoutLabel = toolkit.createLabel(snapshotRepositoryComposite, Messages.RepositoriesComposite_lblLayout, SWT.NONE); + snapshotRepositoryLayoutLabel.setLayoutData(new GridData()); + rightWidthGroup.addControl(snapshotRepositoryLayoutLabel); + + snapshotRepositoryLayoutCombo = new CCombo(snapshotRepositoryComposite, SWT.FLAT); + snapshotRepositoryLayoutCombo.setItems(new String[] {"default", "legacy"}); + snapshotRepositoryLayoutCombo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); + snapshotRepositoryLayoutCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + toolkit.adapt(snapshotRepositoryLayoutCombo, true, true); + new Label(snapshotRepositoryComposite, SWT.NONE); + + snapshotRepositoryUniqueVersionButton = toolkit.createButton(snapshotRepositoryComposite, // + Messages.RepositoriesComposite_btnUniqueVersion, SWT.CHECK); + snapshotRepositoryUniqueVersionButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); + snapshotRepositoryComposite.setTabList(new Control[] {snapshotRepositoryIdText, snapshotRepositoryNameText, snapshotRepositoryUrlText, snapshotRepositoryLayoutCombo, snapshotRepositoryUniqueVersionButton}); + } + + private void createReleaseRepositorySection(SashForm distributionManagementSash) { + releaseRepositorySection = toolkit.createSection(distributionManagementSash, // + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + releaseRepositorySection.setText(Messages.RepositoriesComposite_section_releaseDistRepo); + + releaseDistributionRepositoryComposite = toolkit.createComposite(releaseRepositorySection, SWT.NONE); + releaseDistributionRepositoryComposite.setLayout(new GridLayout(2, false)); + toolkit.paintBordersFor(releaseDistributionRepositoryComposite); + releaseRepositorySection.setClient(releaseDistributionRepositoryComposite); + releaseDistributionRepositoryComposite.addControlListener(leftWidthGroup); + + Label releaseRepositoryIdLabel = toolkit.createLabel(releaseDistributionRepositoryComposite, Messages.RepositoriesComposite_lblRepoId, SWT.NONE); + leftWidthGroup.addControl(releaseRepositoryIdLabel); + + releaseRepositoryIdText = toolkit.createText(releaseDistributionRepositoryComposite, null, SWT.NONE); + GridData gd_releaseRepositoryIdText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_releaseRepositoryIdText.widthHint = 100; + releaseRepositoryIdText.setLayoutData(gd_releaseRepositoryIdText); + + Label releaseRepositoryNameLabel = toolkit.createLabel(releaseDistributionRepositoryComposite, Messages.RepositoriesComposite_lblName, SWT.NONE); + leftWidthGroup.addControl(releaseRepositoryNameLabel); + + releaseRepositoryNameText = toolkit.createText(releaseDistributionRepositoryComposite, null, SWT.NONE); + GridData gd_releaseRepositoryNameText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_releaseRepositoryNameText.widthHint = 100; + releaseRepositoryNameText.setLayoutData(gd_releaseRepositoryNameText); + + Hyperlink releaseRepositoryUrlHyperlink = toolkit.createHyperlink(releaseDistributionRepositoryComposite, Messages.RepositoriesComposite_lblUrl2, + SWT.NONE); + releaseRepositoryUrlHyperlink.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + FormUtils.openHyperlink(releaseRepositoryUrlText.getText()); + } + }); + leftWidthGroup.addControl(releaseRepositoryUrlHyperlink); + + releaseRepositoryUrlText = toolkit.createText(releaseDistributionRepositoryComposite, null, SWT.NONE); + GridData gd_releaseRepositoryUrlText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_releaseRepositoryUrlText.widthHint = 100; + releaseRepositoryUrlText.setLayoutData(gd_releaseRepositoryUrlText); + + Label releaseRepositoryLayoutLabel = toolkit.createLabel(releaseDistributionRepositoryComposite, Messages.RepositoriesComposite_lblLayout, + SWT.NONE); + releaseRepositoryLayoutLabel.setLayoutData(new GridData()); + leftWidthGroup.addControl(releaseRepositoryLayoutLabel); + + releaseRepositoryLayoutCombo = new CCombo(releaseDistributionRepositoryComposite, SWT.FLAT); + releaseRepositoryLayoutCombo.setItems(new String[] {"default", "legacy"}); + releaseRepositoryLayoutCombo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); + releaseRepositoryLayoutCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + toolkit.adapt(releaseRepositoryLayoutCombo, true, true); + new Label(releaseDistributionRepositoryComposite, SWT.NONE); + + releaseRepositoryUniqueVersionButton = toolkit.createButton(releaseDistributionRepositoryComposite, + Messages.RepositoriesComposite_btnUniqueVersion, SWT.CHECK); + releaseRepositoryUniqueVersionButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); + releaseDistributionRepositoryComposite.setTabList(new Control[] {releaseRepositoryIdText, releaseRepositoryNameText, releaseRepositoryUrlText, releaseRepositoryLayoutCombo, releaseRepositoryUniqueVersionButton}); + } + + public void loadData(MavenPomEditorPage editorPage, Model model, + ValueProvider<DistributionManagement> distributionManagementProvider) { + this.parent = editorPage; + this.model = model; + this.distributionManagementProvider = distributionManagementProvider; + + loadRepositories(); + loadPluginRepositories(); + + loadReleaseDistributionRepository(); + loadSnapshotDistributionRepository(); + loadProjectSite(); + loadRelocation(); + + registerReleaseRepositoryListeners(); + registerSnapshotRepositoryListeners(); + registerProjectListeners(); + registerRelocationListeners(); + + repositoriesEditor.setReadOnly(parent.isReadOnly()); + pluginRepositoriesEditor.setReadOnly(parent.isReadOnly()); + + expandSections(); + } + + private void expandSections() { + DistributionManagement dm = distributionManagementProvider.getValue(); + if(dm != null) { + boolean isRepositoriesExpanded = false; + + if(dm.getRepository() != null) { + DeploymentRepository r = dm.getRepository(); + isRepositoriesExpanded |= !isEmpty(r.getId()) || !isEmpty(r.getName()) || !isEmpty(r.getUrl()) + || !isEmpty(r.getLayout()) || !isEmpty(r.getUniqueVersion()); + } + + if(dm.getSnapshotRepository() != null) { + DeploymentRepository r = dm.getSnapshotRepository(); + isRepositoriesExpanded |= !isEmpty(r.getId()) || !isEmpty(r.getName()) || !isEmpty(r.getUrl()) + || !isEmpty(r.getLayout()) || !isEmpty(r.getUniqueVersion()); + } + + releaseRepositorySection.setExpanded(isRepositoriesExpanded); + snapshotRepositorySection.setExpanded(isRepositoriesExpanded); + + boolean isSiteExpanded = false; + + Site s = dm.getSite(); + if(s != null) { + isSiteExpanded |= !isEmpty(s.getId()) || !isEmpty(s.getName()) || !isEmpty(s.getUrl()) + || !isEmpty(dm.getDownloadUrl()); + } else { + isSiteExpanded |= !isEmpty(dm.getDownloadUrl()); + } + + if(dm.getRelocation() != null) { + Relocation r = dm.getRelocation(); + isSiteExpanded |= !isEmpty(r.getGroupId()) || !isEmpty(r.getArtifactId()) || !isEmpty(r.getVersion()) + || !isEmpty(r.getMessage()); + } + + projectSiteSection.setExpanded(isSiteExpanded); + relocationSection.setExpanded(isSiteExpanded); + + } else { + releaseRepositorySection.setExpanded(false); + snapshotRepositorySection.setExpanded(false); + projectSiteSection.setExpanded(false); + relocationSection.setExpanded(false); + } + + relocationSection.addExpansionListener(new ExpansionAdapter() { + boolean isExpanding = false; + + public void expansionStateChanged(ExpansionEvent e) { + if(!isExpanding) { + isExpanding = true; + projectSiteSection.setExpanded(relocationSection.isExpanded()); + isExpanding = false; + } + } + }); + projectSiteSection.addExpansionListener(new ExpansionAdapter() { + boolean isExpanding = false; + + public void expansionStateChanged(ExpansionEvent e) { + if(!isExpanding) { + isExpanding = true; + relocationSection.setExpanded(projectSiteSection.isExpanded()); + isExpanding = false; + } + } + }); + + releaseRepositorySection.addExpansionListener(new ExpansionAdapter() { + boolean isExpanding = false; + + public void expansionStateChanged(ExpansionEvent e) { + if(!isExpanding) { + isExpanding = true; + snapshotRepositorySection.setExpanded(releaseRepositorySection.isExpanded()); + isExpanding = false; + } + } + }); + snapshotRepositorySection.addExpansionListener(new ExpansionAdapter() { + boolean isExpanding = false; + + public void expansionStateChanged(ExpansionEvent e) { + if(!isExpanding) { + isExpanding = true; + releaseRepositorySection.setExpanded(snapshotRepositorySection.isExpanded()); + isExpanding = false; + } + } + }); + } + + private void registerReleaseRepositoryListeners() { + ValueProvider<DeploymentRepository> repositoryProvider = new ValueProvider.ParentValueProvider<DeploymentRepository>( + releaseRepositoryIdText, releaseRepositoryNameText, releaseRepositoryUrlText) { + public DeploymentRepository getValue() { + DistributionManagement dm = distributionManagementProvider.getValue(); + return dm == null ? null : dm.getRepository(); + } + + public DeploymentRepository create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + DistributionManagement dm = createDistributionManagement(editingDomain, compoundCommand); + DeploymentRepository r = dm.getRepository(); + if(r == null) { + r = PomFactory.eINSTANCE.createDeploymentRepository(); + Command command = SetCommand.create(editingDomain, dm, POM_PACKAGE.getDistributionManagement_Repository(), r); + compoundCommand.append(command); + } + return r; + } + }; + parent.setModifyListener(releaseRepositoryIdText, repositoryProvider, POM_PACKAGE.getDeploymentRepository_Id(), ""); //$NON-NLS-1$ + parent.setModifyListener(releaseRepositoryNameText, repositoryProvider, POM_PACKAGE.getDeploymentRepository_Name(), + ""); //$NON-NLS-1$ + parent.setModifyListener(releaseRepositoryUrlText, repositoryProvider, POM_PACKAGE.getDeploymentRepository_Url(), + ""); //$NON-NLS-1$ + parent.setModifyListener(releaseRepositoryLayoutCombo, repositoryProvider, POM_PACKAGE + .getDeploymentRepository_Layout(), "default"); + parent.setModifyListener(releaseRepositoryUniqueVersionButton, repositoryProvider, POM_PACKAGE + .getDeploymentRepository_UniqueVersion(), "true"); + } + + private void registerSnapshotRepositoryListeners() { + ValueProvider<DeploymentRepository> repositoryProvider = new ValueProvider.ParentValueProvider<DeploymentRepository>( + snapshotRepositoryIdText, snapshotRepositoryNameText, snapshotRepositoryUrlText) { + public DeploymentRepository getValue() { + DistributionManagement dm = distributionManagementProvider.getValue(); + return dm == null ? null : dm.getSnapshotRepository(); + } + + public DeploymentRepository create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + DistributionManagement dm = createDistributionManagement(editingDomain, compoundCommand); + DeploymentRepository r = dm.getSnapshotRepository(); + if(r == null) { + r = PomFactory.eINSTANCE.createDeploymentRepository(); + Command command = SetCommand.create(editingDomain, dm, POM_PACKAGE + .getDistributionManagement_SnapshotRepository(), r); + compoundCommand.append(command); + } + return r; + } + }; + parent + .setModifyListener(snapshotRepositoryIdText, repositoryProvider, POM_PACKAGE.getDeploymentRepository_Id(), ""); //$NON-NLS-1$ + parent.setModifyListener(snapshotRepositoryNameText, repositoryProvider, + POM_PACKAGE.getDeploymentRepository_Name(), ""); //$NON-NLS-1$ + parent.setModifyListener(snapshotRepositoryUrlText, repositoryProvider, POM_PACKAGE.getDeploymentRepository_Url(), + ""); //$NON-NLS-1$ + parent.setModifyListener(snapshotRepositoryLayoutCombo, repositoryProvider, POM_PACKAGE + .getDeploymentRepository_Layout(), "default"); + parent.setModifyListener(snapshotRepositoryUniqueVersionButton, repositoryProvider, POM_PACKAGE + .getDeploymentRepository_UniqueVersion(), "true"); + } + + private void registerProjectListeners() { + //do not use ParentValueProvider here as it renders the other providers useless (siteProvider etc) + ValueProvider<DistributionManagement> dmProvider = new ValueProvider.DefaultValueProvider<DistributionManagement>(distributionManagementProvider.getValue()) + { + public DistributionManagement getValue() { + return distributionManagementProvider.getValue(); + } + + public DistributionManagement create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + return createDistributionManagement(editingDomain, compoundCommand); + } + }; + parent.setModifyListener(projectDownloadUrlText, dmProvider, POM_PACKAGE.getDistributionManagement_DownloadUrl(), + ""); //$NON-NLS-1$ + + ValueProvider<Site> siteProvider = new ValueProvider.ParentValueProvider<Site>(projectSiteIdText, + projectSiteNameText, projectSiteUrlText) { + public Site getValue() { + DistributionManagement dm = distributionManagementProvider.getValue(); + return dm == null ? null : dm.getSite(); + } + + public Site create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + DistributionManagement dm = createDistributionManagement(editingDomain, compoundCommand); + Site s = dm.getSite(); + if(s == null) { + s = PomFactory.eINSTANCE.createSite(); + Command command = SetCommand.create(editingDomain, dm, POM_PACKAGE.getDistributionManagement_Site(), s); + compoundCommand.append(command); + } + return s; + } + }; + parent.setModifyListener(projectSiteIdText, siteProvider, POM_PACKAGE.getSite_Id(), ""); //$NON-NLS-1$ + parent.setModifyListener(projectSiteNameText, siteProvider, POM_PACKAGE.getSite_Name(), ""); //$NON-NLS-1$ + parent.setModifyListener(projectSiteUrlText, siteProvider, POM_PACKAGE.getSite_Url(), ""); //$NON-NLS-1$ + } + + private void registerRelocationListeners() { + ValueProvider<Relocation> relocationProvider = new ValueProvider.ParentValueProvider<Relocation>( + relocationGroupIdText, relocationArtifactIdText, relocationVersionText, relocationMessageText) { + public Relocation getValue() { + DistributionManagement dm = distributionManagementProvider.getValue(); + return dm == null ? null : dm.getRelocation(); + } + + public Relocation create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + DistributionManagement dm = createDistributionManagement(editingDomain, compoundCommand); + Relocation r = dm.getRelocation(); + if(r == null) { + r = PomFactory.eINSTANCE.createRelocation(); + Command command = SetCommand.create(editingDomain, dm, POM_PACKAGE.getDistributionManagement_Relocation(), r); + compoundCommand.append(command); + } + return r; + } + }; + parent.setModifyListener(relocationGroupIdText, relocationProvider, POM_PACKAGE.getRelocation_GroupId(), ""); //$NON-NLS-1$ + parent.setModifyListener(relocationArtifactIdText, relocationProvider, POM_PACKAGE.getRelocation_ArtifactId(), ""); //$NON-NLS-1$ + parent.setModifyListener(relocationVersionText, relocationProvider, POM_PACKAGE.getRelocation_Version(), ""); //$NON-NLS-1$ + parent.setModifyListener(relocationMessageText, relocationProvider, POM_PACKAGE.getRelocation_Message(), ""); //$NON-NLS-1$ + } + + private void loadReleaseDistributionRepository() { + DistributionManagement dm = distributionManagementProvider.getValue(); + DeploymentRepository repository = dm == null ? null : dm.getRepository(); + if(repository != null) { + setText(releaseRepositoryIdText, repository.getId()); + setText(releaseRepositoryNameText, repository.getName()); + setText(releaseRepositoryUrlText, repository.getUrl()); + setText(releaseRepositoryLayoutCombo, "".equals(nvl(repository.getLayout())) ? "default" : nvl(repository.getLayout())); //$NON-NLS-1$ //$NON-NLS-2$ + setButton(releaseRepositoryUniqueVersionButton, "true".equals(repository.getUniqueVersion())); + } else { + setText(releaseRepositoryIdText, ""); //$NON-NLS-1$ + setText(releaseRepositoryNameText, ""); //$NON-NLS-1$ + setText(releaseRepositoryUrlText, ""); //$NON-NLS-1$ + setText(releaseRepositoryLayoutCombo, ""); //$NON-NLS-1$ + setButton(releaseRepositoryUniqueVersionButton, true); // default + } + } + + private void loadSnapshotDistributionRepository() { + DistributionManagement dm = distributionManagementProvider.getValue(); + DeploymentRepository repository = dm == null ? null : dm.getSnapshotRepository(); + if(repository != null) { + setText(snapshotRepositoryIdText, repository.getId()); + setText(snapshotRepositoryNameText, repository.getName()); + setText(snapshotRepositoryUrlText, repository.getUrl()); + setText(snapshotRepositoryLayoutCombo, "".equals(nvl(repository.getLayout())) ? "default" : nvl(repository.getLayout())); //$NON-NLS-1$ //$NON-NLS-2$ + setButton(snapshotRepositoryUniqueVersionButton, "true".equals(repository.getUniqueVersion())); + } else { + setText(snapshotRepositoryIdText, ""); //$NON-NLS-1$ + setText(snapshotRepositoryNameText, ""); //$NON-NLS-1$ + setText(snapshotRepositoryUrlText, ""); //$NON-NLS-1$ + setText(snapshotRepositoryLayoutCombo, ""); //$NON-NLS-1$ + setButton(snapshotRepositoryUniqueVersionButton, true); // default + } + } + + private void loadProjectSite() { + DistributionManagement dm = distributionManagementProvider.getValue(); + Site site = dm == null ? null : dm.getSite(); + if(site != null) { + setText(projectSiteIdText, site.getId()); + setText(projectSiteNameText, site.getName()); + setText(projectSiteUrlText, site.getUrl()); + } else { + setText(projectSiteIdText, ""); //$NON-NLS-1$ + setText(projectSiteNameText, ""); //$NON-NLS-1$ + setText(projectSiteUrlText, ""); //$NON-NLS-1$ + } + + setText(projectDownloadUrlText, dm == null ? null : dm.getDownloadUrl()); + } + + private void loadRelocation() { + DistributionManagement dm = distributionManagementProvider.getValue(); + Relocation relocation = dm == null ? null : dm.getRelocation(); + if(relocation != null) { + setText(relocationGroupIdText, relocation.getGroupId()); + setText(relocationArtifactIdText, relocation.getArtifactId()); + setText(relocationVersionText, relocation.getVersion()); + setText(relocationMessageText, relocation.getMessage()); + } else { + setText(relocationGroupIdText, ""); //$NON-NLS-1$ + setText(relocationArtifactIdText, ""); //$NON-NLS-1$ + setText(relocationVersionText, ""); //$NON-NLS-1$ + setText(relocationMessageText, ""); //$NON-NLS-1$ + } + } + + private void loadRepositories() { + repositoriesEditor.setInput(model.getRepositories()); + repositoriesEditor.setReadOnly(parent.isReadOnly()); + changingSelection = true; + updateRepositoryDetailsSection(null); + changingSelection = false; + } + + private void loadPluginRepositories() { + pluginRepositoriesEditor.setInput(model.getPluginRepositories()); + pluginRepositoriesEditor.setReadOnly(parent.isReadOnly()); + changingSelection = true; + updateRepositoryDetailsSection(null); + changingSelection = false; + } + + public void updateView(MavenPomEditorPage editorPage, Notification notification) { + EObject object = (EObject) notification.getNotifier(); + Object feature = notification.getFeature(); + if(PomPackage.Literals.MODEL__REPOSITORIES == feature) { + repositoriesEditor.refresh(); + } + + if(PomPackage.Literals.MODEL__PLUGIN_REPOSITORIES == feature) { + pluginRepositoriesEditor.refresh(); + } + + if(object instanceof Repository) { + repositoriesEditor.refresh(); + pluginRepositoriesEditor.refresh(); + + Object notificationObject = MavenPomEditorPage.getFromNotification(notification); + if(currentRepository == object && (notificationObject == null || notificationObject instanceof Repository)) { + updateRepositoryDetailsSection((Repository) notificationObject); + } + } + + if(object instanceof DistributionManagement) { + if(object == distributionManagementProvider.getValue()) { + loadProjectSite(); + loadRelocation(); + loadReleaseDistributionRepository(); + loadSnapshotDistributionRepository(); + } + } + + if(object instanceof Site) { + if(object.eContainer() == distributionManagementProvider.getValue()) { + loadProjectSite(); + } + } + + if(object instanceof Relocation) { + if(object.eContainer() == distributionManagementProvider.getValue()) { + loadRelocation(); + } + } + + if(object instanceof DeploymentRepository) { + if(object.eContainer() == distributionManagementProvider.getValue()) { + loadReleaseDistributionRepository(); + loadSnapshotDistributionRepository(); + } + } + + // XXX + } + + protected void updateRepositoryDetailsSection(final Repository repository) { + if(changingSelection) { + return; + } +// if(repository != null && currentRepository == repository) { +// return; +// } + currentRepository = repository; + + if(parent != null) { + parent.removeNotifyListener(repositoryIdText); + parent.removeNotifyListener(repositoryNameText); + parent.removeNotifyListener(repositoryUrlText); + parent.removeNotifyListener(repositoryLayoutCombo); + + parent.removeNotifyListener(releasesEnabledButton); + parent.removeNotifyListener(releasesChecksumPolicyCombo); + parent.removeNotifyListener(releasesUpdatePolicyCombo); + + parent.removeNotifyListener(snapshotsEnabledButton); + parent.removeNotifyListener(snapshotsChecksumPolicyCombo); + parent.removeNotifyListener(snapshotsUpdatePolicyCombo); + } + + if(repository == null) { + FormUtils.setEnabled(repositoryDetailsSection, false); + + setText(repositoryIdText, ""); //$NON-NLS-1$ + setText(repositoryNameText, ""); //$NON-NLS-1$ + setText(repositoryLayoutCombo, ""); //$NON-NLS-1$ + setText(repositoryUrlText, ""); //$NON-NLS-1$ + + setButton(releasesEnabledButton, false); + setText(releasesChecksumPolicyCombo, ""); //$NON-NLS-1$ + setText(releasesUpdatePolicyCombo, ""); //$NON-NLS-1$ + + setButton(snapshotsEnabledButton, false); + setText(snapshotsChecksumPolicyCombo, ""); // move into listener //$NON-NLS-1$ + setText(snapshotsUpdatePolicyCombo, ""); //$NON-NLS-1$ + + // XXX swap repository details panel + + return; + } + +// repositoryIdText.setEnabled(true); +// repositoryNameText.setEnabled(true); +// repositoryLayoutCombo.setEnabled(true); +// repositoryUrlText.setEnabled(true); +// releasesEnabledButton.setEnabled(true); +// snapshotsEnabledButton.setEnabled(true); + + setText(repositoryIdText, repository.getId()); + setText(repositoryNameText, repository.getName()); + setText(repositoryLayoutCombo, "".equals(nvl(repository.getLayout())) ? "default" : nvl(repository.getLayout()));//$NON-NLS-1$ //$NON-NLS-2$ + setText(repositoryUrlText, repository.getUrl()); + + { + RepositoryPolicy releases = repository.getReleases(); + if(releases != null) { + setButton(releasesEnabledButton, releases.getEnabled() == null || "true".equals(releases.getEnabled())); + setText(releasesChecksumPolicyCombo, releases.getChecksumPolicy()); + setText(releasesUpdatePolicyCombo, releases.getUpdatePolicy()); + } else { + setButton(releasesEnabledButton, true); + } + boolean isReleasesEnabled = releasesEnabledButton.getSelection(); + releasesChecksumPolicyCombo.setEnabled(isReleasesEnabled); + releasesUpdatePolicyCombo.setEnabled(isReleasesEnabled); + releasesChecksumPolicyLabel.setEnabled(isReleasesEnabled); + releasesUpdatePolicyLabel.setEnabled(isReleasesEnabled); + } + + { + RepositoryPolicy snapshots = repository.getSnapshots(); + if(snapshots != null) { + setButton(snapshotsEnabledButton, snapshots.getEnabled() == null || "true".equals(snapshots.getEnabled())); + setText(snapshotsChecksumPolicyCombo, snapshots.getChecksumPolicy()); + setText(snapshotsUpdatePolicyCombo, snapshots.getUpdatePolicy()); + } else { + setButton(snapshotsEnabledButton, true); + } + boolean isSnapshotsEnabled = snapshotsEnabledButton.getSelection(); + snapshotsChecksumPolicyCombo.setEnabled(isSnapshotsEnabled); + snapshotsUpdatePolicyCombo.setEnabled(isSnapshotsEnabled); + snapshotsChecksumPolicyLabel.setEnabled(isSnapshotsEnabled); + snapshotsUpdatePolicyLabel.setEnabled(isSnapshotsEnabled); + } + + FormUtils.setEnabled(repositoryDetailsSection, true); + FormUtils.setReadonly(repositoryDetailsSection, parent.isReadOnly()); + + ValueProvider<Repository> repositoryProvider = new ValueProvider.DefaultValueProvider<Repository>(repository); + parent.setModifyListener(repositoryIdText, repositoryProvider, POM_PACKAGE.getRepository_Id(), ""); //$NON-NLS-1$ + parent.setModifyListener(repositoryNameText, repositoryProvider, POM_PACKAGE.getRepository_Name(), ""); //$NON-NLS-1$ + parent.setModifyListener(repositoryUrlText, repositoryProvider, POM_PACKAGE.getRepository_Url(), ""); //$NON-NLS-1$ + parent.setModifyListener(repositoryLayoutCombo, repositoryProvider, POM_PACKAGE.getRepository_Layout(), "default"); + + ValueProvider<RepositoryPolicy> releasesProvider = new ValueProvider.ParentValueProvider<RepositoryPolicy>( + releasesEnabledButton, releasesChecksumPolicyCombo, releasesUpdatePolicyCombo) { + public RepositoryPolicy getValue() { + return repository.getReleases(); + } + + public RepositoryPolicy create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + RepositoryPolicy policy = getValue(); + if(policy == null) { + policy = PomFactory.eINSTANCE.createRepositoryPolicy(); + Command command = SetCommand.create(editingDomain, repository, POM_PACKAGE.getRepository_Releases(), policy); + compoundCommand.append(command); + } + return policy; + } + }; + parent + .setModifyListener(releasesEnabledButton, releasesProvider, POM_PACKAGE.getRepositoryPolicy_Enabled(), "true"); + parent.setModifyListener(releasesChecksumPolicyCombo, releasesProvider, POM_PACKAGE + .getRepositoryPolicy_ChecksumPolicy(), ""); //$NON-NLS-1$ + parent.setModifyListener(releasesUpdatePolicyCombo, releasesProvider, POM_PACKAGE + .getRepositoryPolicy_UpdatePolicy(), ""); //$NON-NLS-1$ + + ValueProvider<RepositoryPolicy> snapshotsProvider = new ValueProvider.ParentValueProvider<RepositoryPolicy>( + snapshotsEnabledButton, snapshotsChecksumPolicyCombo, snapshotsUpdatePolicyCombo) { + public RepositoryPolicy getValue() { + return repository.getSnapshots(); + } + + public RepositoryPolicy create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + RepositoryPolicy policy = getValue(); + if(policy == null) { + policy = PomFactory.eINSTANCE.createRepositoryPolicy(); + Command command = SetCommand.create(editingDomain, repository, POM_PACKAGE.getRepository_Snapshots(), policy); + compoundCommand.append(command); + } + return policy; + } + }; + parent.setModifyListener(snapshotsEnabledButton, snapshotsProvider, POM_PACKAGE.getRepositoryPolicy_Enabled(), + "true"); + parent.setModifyListener(snapshotsChecksumPolicyCombo, snapshotsProvider, POM_PACKAGE + .getRepositoryPolicy_ChecksumPolicy(), ""); //$NON-NLS-1$ + parent.setModifyListener(snapshotsUpdatePolicyCombo, snapshotsProvider, POM_PACKAGE + .getRepositoryPolicy_UpdatePolicy(), ""); //$NON-NLS-1$ + } + + DistributionManagement createDistributionManagement(EditingDomain editingDomain, CompoundCommand compoundCommand) { + DistributionManagement dm = distributionManagementProvider.getValue(); + if(dm == null) { + dm = distributionManagementProvider.create(editingDomain, compoundCommand); + } + return dm; + } + + /** + * Repository label provider + */ + public class RepositoryLabelProvider extends LabelProvider { + + public String getText(Object element) { + if(element instanceof Repository) { + Repository r = (Repository) element; + return (isEmpty(r.getId()) ? "?" : r.getId()) + " : " + (isEmpty(r.getUrl()) ? "?" : r.getUrl()); + } + return super.getText(element); + } + + public Image getImage(Object element) { + return MavenEditorImages.IMG_REPOSITORY; + } + + } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/SectionExpansionAdapter.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/SectionExpansionAdapter.java new file mode 100644 index 00000000..1f34cec0 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/SectionExpansionAdapter.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.composites; + +import org.eclipse.ui.forms.events.ExpansionAdapter; +import org.eclipse.ui.forms.events.ExpansionEvent; +import org.eclipse.ui.forms.widgets.Section; + +/** + * An expansion adapter that collapses all the sections in the same row. + */ +public class SectionExpansionAdapter extends ExpansionAdapter { + private boolean inProgress = false; + private Section[] sections; + + public SectionExpansionAdapter(Section[] sections) { + this.sections = sections; + for(Section section : sections) { + section.addExpansionListener(this); + } + } + + public void expansionStateChanged(ExpansionEvent e) { + if(!inProgress && e.getSource() instanceof Section) { + inProgress = true; + boolean expand = ((Section)e.getSource()).isExpanded(); + + for(Section section : sections) { + section.setExpanded(expand); + } + + inProgress = false; + } + } +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/StringLabelProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/StringLabelProvider.java new file mode 100644 index 00000000..270be049 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/StringLabelProvider.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.composites; + +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; + +/** + * Label provider for <code>String</code> entries + * + * @author Eugene Kuleshov + */ +public class StringLabelProvider extends LabelProvider { + private final Image img; + + public StringLabelProvider(Image img) { + this.img = img; + } + + public String getText(Object element) { + if(element instanceof String) { + return (String) element; + } + return ""; //$NON-NLS-1$ + } + + public Image getImage(Object element) { + return img; + } +}
\ No newline at end of file diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/TeamComposite.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/TeamComposite.java new file mode 100644 index 00000000..0b634366 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/TeamComposite.java @@ -0,0 +1,630 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.composites; + +import static org.eclipse.m2e.editor.pom.FormUtils.setText; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.command.RemoveCommand; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.jface.viewers.ICellModifier; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.m2e.core.wizards.WidthGroup; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.editor.pom.FormUtils; +import org.eclipse.m2e.editor.pom.MavenPomEditorPage; +import org.eclipse.m2e.editor.pom.PropertiesSection; +import org.eclipse.m2e.editor.pom.ValueProvider; +import org.eclipse.m2e.model.edit.pom.Contributor; +import org.eclipse.m2e.model.edit.pom.Developer; +import org.eclipse.m2e.model.edit.pom.Model; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.m2e.model.edit.pom.PomPackage; +import org.eclipse.m2e.model.edit.pom.PropertyElement; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.events.HyperlinkAdapter; +import org.eclipse.ui.forms.events.HyperlinkEvent; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Hyperlink; +import org.eclipse.ui.forms.widgets.Section; + + +/** + * @author Dmitry Platonoff + */ +public class TeamComposite extends Composite { + + protected static PomPackage POM_PACKAGE = PomPackage.eINSTANCE; + + private FormToolkit toolkit = new FormToolkit(Display.getCurrent()); + + MavenPomEditorPage parent; + + // controls + + Model model; + + ListEditorComposite<Developer> developersEditor; + + ListEditorComposite<Contributor> contributorsEditor; + + Composite detailsComposite; + + Text userIdText; + + Text userNameText; + + Text userEmailText; + + Text userUrlText; + + CCombo userTimezoneText; + + Text organizationNameText; + + Text organizationUrlText; + + ListEditorComposite<String> rolesEditor; + + Label userIdLabel; + + // model + EObject currentSelection; + + boolean changingSelection = false; + + private PropertiesSection propertiesSection; + + public TeamComposite(MavenPomEditorPage editorPage, Composite composite, int flags) { + super(composite, flags); + this.parent = editorPage; + createComposite(); + } + + private void createComposite() { + GridLayout gridLayout = new GridLayout(); + gridLayout.makeColumnsEqualWidth = true; + gridLayout.marginWidth = 0; + setLayout(gridLayout); + toolkit.adapt(this); + + SashForm horizontalSash = new SashForm(this, SWT.NONE); + horizontalSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + toolkit.adapt(horizontalSash, true, true); + + SashForm verticalSash = new SashForm(horizontalSash, SWT.VERTICAL); + toolkit.adapt(verticalSash, true, true); + + createDevelopersSection(toolkit, verticalSash); + createContributorsSection(toolkit, verticalSash); + + verticalSash.setWeights(new int[] {1, 1}); + + createDetailsPanel(toolkit, horizontalSash); + + horizontalSash.setWeights(new int[] {1, 1}); + } + + private void createDevelopersSection(FormToolkit toolkit, SashForm verticalSash) { + Section developersSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR); + developersSection.setText(Messages.TeamComposite_section_developers); + + developersEditor = new ListEditorComposite<Developer>(developersSection, SWT.NONE); + + developersEditor.setContentProvider(new ListEditorContentProvider<Developer>()); + developersEditor.setLabelProvider(new TeamLabelProvider()); + + developersEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + Developer developer = PomFactory.eINSTANCE.createDeveloper(); + Command addDependencyCommand = AddCommand.create(editingDomain, model, POM_PACKAGE + .getModel_Developers(), developer); + compoundCommand.append(addDependencyCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + + developersEditor.setSelection(Collections.singletonList(developer)); + updateDetails(developer); + userIdText.setFocus(); + } + }); + + developersEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + List<Developer> developerList = developersEditor.getSelection(); + for(Developer developer : developerList) { + Command removeCommand = RemoveCommand.create(editingDomain, model, POM_PACKAGE + .getModel_Developers(), developer); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + updateDetails(null); + } + }); + + developersEditor.addSelectionListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + List<Developer> selection = developersEditor.getSelection(); + updateDetails(selection.size() == 1 ? selection.get(0) : null); + + if(!selection.isEmpty()) { + changingSelection = true; + try { + contributorsEditor.setSelection(Collections.<Contributor> emptyList()); + } finally { + changingSelection = false; + } + } + } + }); + + developersSection.setClient(developersEditor); + toolkit.paintBordersFor(developersEditor); + toolkit.adapt(developersEditor); + } + + private void createContributorsSection(FormToolkit toolkit, SashForm verticalSash) { + Section contributorsSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR); + contributorsSection.setText(Messages.TeamComposite_section_contributors); + + contributorsEditor = new ListEditorComposite<Contributor>(contributorsSection, SWT.NONE); + contributorsEditor.setContentProvider(new ListEditorContentProvider<Contributor>()); + contributorsEditor.setLabelProvider(new TeamLabelProvider()); + + contributorsEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + Contributor contributor = PomFactory.eINSTANCE.createContributor(); + Command addDependencyCommand = AddCommand.create(editingDomain, model, POM_PACKAGE + .getModel_Contributors(), contributor); + compoundCommand.append(addDependencyCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + + contributorsEditor.setSelection(Collections.singletonList(contributor)); + updateDetails(contributor); + userNameText.setFocus(); + } + }); + + contributorsEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + List<Contributor> contributorList = contributorsEditor.getSelection(); + for(Contributor contributor : contributorList) { + Command removeCommand = RemoveCommand.create(editingDomain, model, POM_PACKAGE + .getModel_Contributors(), contributor); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + updateDetails(null); + } + }); + + contributorsEditor.addSelectionListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + List<Contributor> selection = contributorsEditor.getSelection(); + updateDetails(selection.size() == 1 ? selection.get(0) : null); + + if(!selection.isEmpty()) { + changingSelection = true; + try { + developersEditor.setSelection(Collections.<Developer> emptyList()); + } finally { + changingSelection = false; + } + } + } + }); + + contributorsSection.setClient(contributorsEditor); + toolkit.paintBordersFor(contributorsEditor); + toolkit.adapt(contributorsEditor); + } + + private void createDetailsPanel(FormToolkit toolkit, SashForm horizontalSash) { + detailsComposite = toolkit.createComposite(horizontalSash, SWT.NONE); + GridLayout detailsCompositeGridLayout = new GridLayout(); + detailsCompositeGridLayout.marginLeft = 5; + detailsCompositeGridLayout.marginWidth = 0; + detailsCompositeGridLayout.marginHeight = 0; + detailsComposite.setLayout(detailsCompositeGridLayout); + toolkit.paintBordersFor(detailsComposite); + + Section userDetailsSection = toolkit.createSection(detailsComposite, ExpandableComposite.TITLE_BAR); + GridData gd_userDetailsSection = new GridData(SWT.FILL, SWT.CENTER, true, false); + userDetailsSection.setLayoutData(gd_userDetailsSection); + userDetailsSection.setText(Messages.TeamComposite_section_userdetails); + + Composite userDetailsComposite = toolkit.createComposite(userDetailsSection, SWT.NONE); + userDetailsComposite.setLayout(new GridLayout(2, false)); + toolkit.paintBordersFor(userDetailsComposite); + userDetailsSection.setClient(userDetailsComposite); + + userIdLabel = toolkit.createLabel(userDetailsComposite, Messages.TeamComposite_lblId, SWT.NONE); + + userIdText = toolkit.createText(userDetailsComposite, null, SWT.NONE); + userIdText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + Label userNameLabel = toolkit.createLabel(userDetailsComposite, Messages.TeamComposite_lblName, SWT.NONE); + + userNameText = toolkit.createText(userDetailsComposite, null, SWT.NONE); + userNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + Label userEmailLabel = toolkit.createLabel(userDetailsComposite, Messages.TeamComposite_lblEmail, SWT.NONE); + + userEmailText = toolkit.createText(userDetailsComposite, null, SWT.NONE); + userEmailText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + Hyperlink userUrlLabel = toolkit.createHyperlink(userDetailsComposite, Messages.TeamComposite_lblUrl, SWT.NONE); + userUrlLabel.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + FormUtils.openHyperlink(userUrlText.getText()); + } + }); + + userUrlText = toolkit.createText(userDetailsComposite, null, SWT.NONE); + userUrlText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + Label userTimezoneLabel = toolkit.createLabel(userDetailsComposite, Messages.TeamComposite_lblTimezone, SWT.NONE); + + userTimezoneText = new CCombo(userDetailsComposite, SWT.FLAT); + userTimezoneText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + userTimezoneText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + + Section organizationSection = toolkit.createSection(detailsComposite, ExpandableComposite.TITLE_BAR); + organizationSection.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + organizationSection.setText(Messages.TeamComposite_section_organization); + + Composite organizationComposite = toolkit.createComposite(organizationSection, SWT.NONE); + organizationComposite.setLayout(new GridLayout(2, false)); + toolkit.paintBordersFor(organizationComposite); + organizationSection.setClient(organizationComposite); + + Label organizationNameLabel = toolkit.createLabel(organizationComposite, Messages.TeamComposite_lblName, SWT.NONE); + + organizationNameText = toolkit.createText(organizationComposite, null, SWT.NONE); + organizationNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + Hyperlink organizationUrlLabel = toolkit.createHyperlink(organizationComposite, Messages.TeamComposite_lblUrl, SWT.NONE); + organizationUrlLabel.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + FormUtils.openHyperlink(organizationUrlText.getText()); + } + }); + + organizationUrlText = toolkit.createText(organizationComposite, null, SWT.NONE); + organizationUrlText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + WidthGroup widthGroup = new WidthGroup(); + widthGroup.addControl(userIdLabel); + widthGroup.addControl(userNameLabel); + widthGroup.addControl(userEmailLabel); + widthGroup.addControl(userUrlLabel); + widthGroup.addControl(userTimezoneLabel); + widthGroup.addControl(organizationNameLabel); + widthGroup.addControl(organizationUrlLabel); + userDetailsComposite.addControlListener(widthGroup); + userDetailsComposite.setTabList(new Control[] {userIdText, userNameText, userEmailText, userUrlText, userTimezoneText}); + organizationComposite.addControlListener(widthGroup); + organizationComposite.setTabList(new Control[] {organizationNameText, organizationUrlText}); + + createRolesSection(toolkit, detailsComposite); + createPropertiesSection(toolkit, detailsComposite); + } + + private void createRolesSection(FormToolkit toolkit, Composite detailsComposite) { + Section rolesSection = toolkit.createSection(detailsComposite, ExpandableComposite.TITLE_BAR); + rolesSection.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); + rolesSection.setText(Messages.TeamComposite_section_roles); + + rolesEditor = new ListEditorComposite<String>(rolesSection, SWT.NONE); + toolkit.paintBordersFor(rolesEditor); + toolkit.adapt(rolesEditor); + rolesSection.setClient(rolesEditor); + + rolesEditor.setContentProvider(new ListEditorContentProvider<String>()); + rolesEditor.setLabelProvider(new StringLabelProvider(MavenEditorImages.IMG_ROLE)); + + rolesEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + EObject parentObject = currentSelection; + EStructuralFeature feature = null; + if(currentSelection != null) { + if(currentSelection instanceof Contributor) { + feature = POM_PACKAGE.getContributor_Roles(); + } else if(currentSelection instanceof Developer) { + feature = POM_PACKAGE.getDeveloper_Roles(); + } + } + + Command addRoleCommand = AddCommand.create(editingDomain, parentObject, feature, "?"); + compoundCommand.append(addRoleCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + + updateRoles((EList<String>)parentObject.eGet(feature)); + } + }); + + rolesEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = parent.getEditingDomain(); + + EObject parentObject = currentSelection; + EStructuralFeature feature = null; + if(currentSelection != null) { + if(currentSelection instanceof Contributor) { + feature = POM_PACKAGE.getContributor_Roles(); + } else if(currentSelection instanceof Developer) { + feature = POM_PACKAGE.getDeveloper_Roles(); + } + } + List<String> roleList = rolesEditor.getSelection(); + for(String role : roleList) { + Command removeCommand = RemoveCommand.create(editingDomain, parentObject, feature, role); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + } + }); + + rolesEditor.setCellModifier(new ICellModifier() { + public boolean canModify(Object element, String property) { + return true; + } + + public Object getValue(Object element, String property) { + return element; + } + + public void modify(Object element, String property, Object value) { + int n = rolesEditor.getViewer().getTable().getSelectionIndex(); + if(!value.equals(getRoles().get(n))) { + EditingDomain editingDomain = parent.getEditingDomain(); + EObject parentObject = currentSelection; + EStructuralFeature feature = null; + if(currentSelection != null) { + if(currentSelection instanceof Contributor) { + feature = POM_PACKAGE.getContributor_Roles(); + } else if(currentSelection instanceof Developer) { + feature = POM_PACKAGE.getDeveloper_Roles(); + } + } + Command command = SetCommand.create(editingDomain, parentObject, + feature, value, n); + editingDomain.getCommandStack().execute(command); + } + } + }); + + } + + private void createPropertiesSection(FormToolkit toolkit, Composite composite) { + propertiesSection = new PropertiesSection(toolkit, composite, parent.getEditingDomain()); + } + + public void loadContributors() { + changingSelection = true; + contributorsEditor.setInput(model.getContributors()); + changingSelection = false; + } + + void loadDevelopers() { + changingSelection = true; + developersEditor.setInput(model.getDevelopers()); + changingSelection = false; + } + + protected void updateDetails(EObject eo) { + if(changingSelection) { + return; + } + + this.currentSelection = eo; + + if(parent != null) { + parent.removeNotifyListener(userIdText); + parent.removeNotifyListener(userNameText); + parent.removeNotifyListener(userEmailText); + parent.removeNotifyListener(userUrlText); + parent.removeNotifyListener(userTimezoneText); + parent.removeNotifyListener(organizationNameText); + parent.removeNotifyListener(organizationUrlText); + } + + if(parent == null || eo == null) { + FormUtils.setEnabled(detailsComposite, false); + + setText(userIdText, ""); //$NON-NLS-1$ + setText(userNameText, ""); //$NON-NLS-1$ + setText(userEmailText, ""); //$NON-NLS-1$ + setText(userUrlText, ""); //$NON-NLS-1$ + setText(userTimezoneText, ""); //$NON-NLS-1$ + + setText(organizationNameText, ""); //$NON-NLS-1$ + setText(organizationUrlText, ""); //$NON-NLS-1$ + + rolesEditor.setInput(null); + + return; + } + + FormUtils.setEnabled(detailsComposite, true); + FormUtils.setReadonly(detailsComposite, parent.isReadOnly()); + + EList<String> roles = null; + if(eo instanceof Contributor) { + Contributor contributor = (Contributor) eo; + updateContributorDetails(contributor); + roles = contributor.getRoles(); + propertiesSection.setModel(contributor, POM_PACKAGE.getContributor_Properties()); + } else if(eo instanceof Developer) { + Developer developer = (Developer) eo; + updateDeveloperDetails(developer); + roles = developer.getRoles(); + propertiesSection.setModel(developer, POM_PACKAGE.getDeveloper_Properties()); + } + + parent.registerListeners(); + + updateRoles(roles); + } + + protected void updateContributorDetails(Contributor contributor) { + setText(userIdText, ""); //$NON-NLS-1$ + setText(userNameText, contributor.getName()); + setText(userEmailText, contributor.getEmail()); + setText(userUrlText, contributor.getUrl()); + setText(userTimezoneText, contributor.getTimezone()); + setText(organizationNameText, contributor.getOrganization()); + setText(organizationUrlText, contributor.getOrganizationUrl()); + + userIdLabel.setEnabled(false); + userIdText.setEnabled(false); + + ValueProvider<Contributor> contributorProvider = new ValueProvider.DefaultValueProvider<Contributor>(contributor); + parent.setModifyListener(userNameText, contributorProvider, POM_PACKAGE.getContributor_Name(), ""); //$NON-NLS-1$ + parent.setModifyListener(userEmailText, contributorProvider, POM_PACKAGE.getContributor_Email(), ""); //$NON-NLS-1$ + parent.setModifyListener(userUrlText, contributorProvider, POM_PACKAGE.getContributor_Url(), ""); //$NON-NLS-1$ + parent.setModifyListener(userTimezoneText, contributorProvider, POM_PACKAGE.getContributor_Timezone(), ""); //$NON-NLS-1$ + parent.setModifyListener(organizationNameText, contributorProvider, POM_PACKAGE.getContributor_Organization(), ""); //$NON-NLS-1$ + parent + .setModifyListener(organizationUrlText, contributorProvider, POM_PACKAGE.getContributor_OrganizationUrl(), ""); //$NON-NLS-1$ + } + + protected void updateDeveloperDetails(Developer developer) { + setText(userIdText, developer.getId()); + setText(userNameText, developer.getName()); + setText(userEmailText, developer.getEmail()); + setText(userUrlText, developer.getUrl()); + setText(userTimezoneText, developer.getTimezone()); + setText(organizationNameText, developer.getOrganization()); + setText(organizationUrlText, developer.getOrganizationUrl()); + + ValueProvider<Developer> developerProvider = new ValueProvider.DefaultValueProvider<Developer>(developer); + parent.setModifyListener(userIdText, developerProvider, POM_PACKAGE.getDeveloper_Id(), ""); //$NON-NLS-1$ + parent.setModifyListener(userNameText, developerProvider, POM_PACKAGE.getDeveloper_Name(), ""); //$NON-NLS-1$ + parent.setModifyListener(userEmailText, developerProvider, POM_PACKAGE.getDeveloper_Email(), ""); //$NON-NLS-1$ + parent.setModifyListener(userUrlText, developerProvider, POM_PACKAGE.getDeveloper_Url(), ""); //$NON-NLS-1$ + parent.setModifyListener(userTimezoneText, developerProvider, POM_PACKAGE.getDeveloper_Timezone(), ""); //$NON-NLS-1$ + parent.setModifyListener(organizationNameText, developerProvider, POM_PACKAGE.getDeveloper_Organization(), ""); //$NON-NLS-1$ + parent.setModifyListener(organizationUrlText, developerProvider, POM_PACKAGE.getDeveloper_OrganizationUrl(), ""); //$NON-NLS-1$ + } + + public void updateView(Notification notification) { + EObject object = (EObject) notification.getNotifier(); + Object feature = notification.getFeature(); + + if(feature == PomPackage.Literals.MODEL__DEVELOPERS) { + developersEditor.refresh(); + } else if(feature == PomPackage.Literals.MODEL__CONTRIBUTORS) { + contributorsEditor.refresh(); + } else { + Object notificationObject = MavenPomEditorPage.getFromNotification(notification); + if(object instanceof Contributor) { + contributorsEditor.refresh(); + + if(object == currentSelection) + updateDetails(object); + } else if(object instanceof Developer) { + developersEditor.refresh(); + + if(object == currentSelection) + updateDetails(object); + } else if(feature == PomPackage.Literals.DEVELOPER__ROLES || feature == PomPackage.Literals.CONTRIBUTOR__ROLES) { + EList<String> roles = (EList<String>)object.eGet((EStructuralFeature)feature); + if(object == getRoles()) { + updateRoles(roles); + } + } + } + } + + public void loadData(Model model) { + this.model = model; + loadDevelopers(); + loadContributors(); + + developersEditor.setReadOnly(parent.isReadOnly()); + contributorsEditor.setReadOnly(parent.isReadOnly()); + + updateDetails(null); + } + + protected EList<String> getRoles() { + if(currentSelection != null) { + if(currentSelection instanceof Contributor) { + return ((Contributor) currentSelection).getRoles(); + } else if(currentSelection instanceof Developer) { + return ((Developer) currentSelection).getRoles(); + } + } + return null; + } + + protected void updateRoles(EList<String> roles) { + rolesEditor.setInput(roles); + } + + protected EList<PropertyElement> getProperties() { + if(currentSelection != null) { + if(currentSelection instanceof Contributor) { + return ((Contributor) currentSelection).getProperties(); + } else if(currentSelection instanceof Developer) { + return ((Developer) currentSelection).getProperties(); + } + } + return null; + } +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/TeamLabelProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/TeamLabelProvider.java new file mode 100644 index 00000000..e45ba6a8 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/composites/TeamLabelProvider.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.composites; + +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.model.edit.pom.Contributor; +import org.eclipse.m2e.model.edit.pom.Developer; +import org.eclipse.swt.graphics.Image; + + +/** + * Label provider for Developer and Contributor elements + * + * @author Dmitry Platonoff + */ +public class TeamLabelProvider extends LabelProvider { + + @Override + public String getText(Object element) { + if(element instanceof Developer) { + Developer developer = (Developer) element; + return getText(developer.getName(), developer.getEmail(), developer.getOrganization()); + } + else if(element instanceof Contributor) { + Contributor contributor = (Contributor) element; + return getText(contributor.getName(), contributor.getEmail(), contributor.getOrganization()); + } + return super.getText(element); + } + + @Override + public Image getImage(Object element) { + return MavenEditorImages.IMG_PERSON; + } + + private String getText(String name, String email, String organization) { + StringBuilder sb = new StringBuilder(); + + sb.append(isEmpty(name) ? "?" : name); + + if(!isEmpty(email)) { + sb.append(" <").append(email).append('>'); + } + + if(!isEmpty(organization)) { + sb.append(", ").append(organization); + } + + return sb.toString(); + } + + private boolean isEmpty(String s) { + return s == null || s.trim().length() == 0; + } +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java new file mode 100644 index 00000000..83287013 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/ManageDependenciesDialog.java @@ -0,0 +1,527 @@ +/******************************************************************************* + * Copyright (c) 2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ + +package org.eclipse.m2e.editor.dialogs; + +import java.io.IOException; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.ListIterator; + +import org.apache.maven.project.MavenProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.jface.viewers.IColorProvider; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.ui.dialogs.AbstractMavenDialog; +import org.eclipse.m2e.editor.MavenEditorPlugin; +import org.eclipse.m2e.editor.composites.ListEditorContentProvider; +import org.eclipse.m2e.editor.composites.ManageDependencyLabelProvider; +import org.eclipse.m2e.model.edit.pom.Dependency; +import org.eclipse.m2e.model.edit.pom.DependencyManagement; +import org.eclipse.m2e.model.edit.pom.Model; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.m2e.model.edit.pom.PomPackage; +import org.eclipse.m2e.model.edit.pom.util.PomResourceFactoryImpl; +import org.eclipse.m2e.model.edit.pom.util.PomResourceImpl; +import org.eclipse.osgi.util.NLS; +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.graphics.Color; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.Tree; + + +/** + * This dialog is used to present the user with a list of dialogs that they can move to being managed under + * "dependencyManagement". It allows them to pick the destination POM where the dependencies will be managed. + * + * @author rgould + */ +public class ManageDependenciesDialog extends AbstractMavenDialog { + + + protected static final String DIALOG_SETTINGS = ManageDependenciesDialog.class.getName(); + protected TableViewer dependenciesViewer; + protected TreeViewer pomsViewer; + protected Model model; + LinkedList<MavenProject> projectHierarchy; + protected EditingDomain editingDomain; + private IStatus status; + + /** + * Hierarchy is a LinkedList representing the hierarchy relationship between + * POM represented by model and its parents. The head of the list should be + * the child, while the tail should be the root parent, with the others + * in between. + */ + public ManageDependenciesDialog(Shell parent, Model model, LinkedList<MavenProject> hierarchy, EditingDomain editingDomain) { + super(parent, DIALOG_SETTINGS); + + setShellStyle(getShellStyle() | SWT.RESIZE); + setTitle(Messages.ManageDependenciesDialog_dialogTitle); + + this.model = model; + this.projectHierarchy = hierarchy; + this.editingDomain = editingDomain; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + protected Control createDialogArea(Composite parent) { + readSettings(); + + Composite composite = (Composite) super.createDialogArea(parent); + + Label infoLabel = new Label(composite, SWT.WRAP); + infoLabel + .setText(Messages.ManageDependenciesDialog_dialogInfo); + + Label horizontalBar = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); + + SashForm sashForm = new SashForm(composite, SWT.SMOOTH | SWT.HORIZONTAL); + Composite dependenciesComposite = new Composite(sashForm, SWT.NONE); + + Label selectDependenciesLabel = new Label(dependenciesComposite, SWT.NONE); + selectDependenciesLabel.setText(Messages.ManageDependenciesDialog_selectDependenciesLabel); + + final Table dependenciesTable = new Table(dependenciesComposite, SWT.FLAT | SWT.MULTI | SWT.BORDER); + final TableColumn column = new TableColumn(dependenciesTable, SWT.NONE); + dependenciesTable.addControlListener(new ControlAdapter() { + @Override + public void controlResized(ControlEvent e) { + column.setWidth(dependenciesTable.getClientArea().width); + } + }); + + Composite pomComposite = new Composite(sashForm, SWT.NONE); + + Label selectPomLabel = new Label(pomComposite, SWT.NONE); + selectPomLabel.setText(Messages.ManageDependenciesDialog_selectPOMLabel); + + Tree pomTree = new Tree(pomComposite, SWT.BORDER); + + /* + * Configure layouts + */ + + GridLayout layout = new GridLayout(1, false); + composite.setLayout(layout); + + GridData gridData = new GridData(SWT.FILL, SWT.NONE, true, false); + gridData.widthHint = 300; + infoLabel.setLayoutData(gridData); + + gridData = new GridData(SWT.FILL, SWT.NONE, true, false); + horizontalBar.setLayoutData(gridData); + + gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + sashForm.setLayoutData(gridData); + + gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + dependenciesComposite.setLayoutData(gridData); + + layout = new GridLayout(1, false); + dependenciesComposite.setLayout(layout); + + gridData = new GridData(SWT.FILL, SWT.NONE, true, false); + selectDependenciesLabel.setLayoutData(gridData); + + gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + dependenciesTable.setLayoutData(gridData); + + + gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + pomComposite.setLayoutData(gridData); + + layout = new GridLayout(1, false); + pomComposite.setLayout(layout); + + gridData = new GridData(SWT.FILL, SWT.NONE, true, false); + selectPomLabel.setLayoutData(gridData); + + gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + pomTree.setLayoutData(gridData); + + /* + * Set up list/tree viewers + */ + + dependenciesViewer = new TableViewer(dependenciesTable); + dependenciesViewer.setLabelProvider(new ManageDependencyLabelProvider()); + dependenciesViewer.setContentProvider(new ListEditorContentProvider<Dependency>()); + dependenciesViewer.setInput(model.getDependencies()); + dependenciesViewer.addSelectionChangedListener(new DependenciesViewerSelectionListener()); + + pomsViewer = new TreeViewer(pomTree); + + pomsViewer.setLabelProvider(new DepLabelProvider()); + + pomsViewer.setContentProvider(new ContentProvider()); + pomsViewer.setInput(getProjectHierarchy()); + pomsViewer.addSelectionChangedListener(new PomViewerSelectionChangedListener()); + pomsViewer.expandAll(); + + return composite; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult() + */ + protected void computeResult() { + MavenProject targetPOM = getTargetPOM(); + IMavenProjectFacade facade = MavenPlugin.getDefault().getMavenProjectManager().getMavenProject(targetPOM.getGroupId(), targetPOM.getArtifactId(), targetPOM.getVersion()); + + /* + * Load the target model so we can make modifications to it + */ + Model targetModel = null; + if (targetPOM.equals(getProjectHierarchy().getFirst())) { + //Editing the same models in both cases + targetModel = model; + } else { + targetModel = loadTargetModel(facade); + if (targetModel == null) { + return; + } + } + + LinkedList<Dependency> dependencies = getDependenciesList(); + + /* + * 1) Remove version values from the dependencies from the current POM + * 2) Add dependencies to dependencyManagement of targetPOM + */ + + CompoundCommand command = new CompoundCommand(); + + //First we remove the version from the original dependency + for (Dependency dep : dependencies) { + Command unset = SetCommand.create(editingDomain, dep, + PomPackage.eINSTANCE.getDependency_Version(), SetCommand.UNSET_VALUE); + command.append(unset); + } + + DependencyManagement management = targetModel.getDependencyManagement(); + if (management == null) { + //Add dependency management element if it does not exist + management = PomFactory.eINSTANCE.createDependencyManagement(); + Command createDepManagement = SetCommand.create(editingDomain, targetModel, + PomPackage.eINSTANCE.getModel_DependencyManagement(), management); + command.append(createDepManagement); + } else { + //Filter out of the list of dependencies for which we need new entries in the dependency management section. + for (Dependency depFromTarget : management.getDependencies()) { + Iterator<Dependency> iter = dependencies.iterator(); + while (iter.hasNext()) { + Dependency depFromSource = iter.next(); + if (depFromSource.getGroupId().equals(depFromTarget.getGroupId()) + && depFromSource.getArtifactId().equals(depFromTarget.getArtifactId())) { + /* + * Dependency already exists in the target's dependencyManagement, + * so we don't need to add it. + */ + iter.remove(); + } + } + } + } + + //Add new entry in dependency mgt section + for (Dependency dep : dependencies) { + Dependency clone = PomFactory.eINSTANCE.createDependency(); + clone.setGroupId(dep.getGroupId()); + clone.setArtifactId(dep.getArtifactId()); + clone.setVersion(dep.getVersion()); + + Command addDepCommand = AddCommand.create(editingDomain, management, + PomPackage.eINSTANCE.getDependencyManagement_Dependencies(), clone); + + command.append(addDepCommand); + } + editingDomain.getCommandStack().execute(command); + + } + + protected Model loadTargetModel(IMavenProjectFacade facade) { + Model targetModel; + PomResourceFactoryImpl factory = new PomResourceFactoryImpl(); + PomResourceImpl resource = (PomResourceImpl) factory.createResource( + URI.createFileURI(facade.getPomFile().getPath())); + try { + resource.load(Collections.EMPTY_MAP); + } catch(IOException e) { + MavenLogger.log("Can't load model " + facade.getPomFile().getPath(), e); //$NON-NLS-1$ + return null; + } + targetModel = (Model) resource.getContents().get(0); + return targetModel; + } + + protected LinkedList<Dependency> getDependenciesList() { + IStructuredSelection selection = (IStructuredSelection) dependenciesViewer.getSelection(); + + LinkedList<Dependency> dependencies = new LinkedList<Dependency>(); + + for (Object obj : selection.toArray()) { + dependencies.add((Dependency) obj); + } + + return dependencies; + } + + protected LinkedList<MavenProject> getProjectHierarchy() { + return this.projectHierarchy; + } + + protected MavenProject getTargetPOM() { + IStructuredSelection selection = (IStructuredSelection) pomsViewer.getSelection(); + return (MavenProject) selection.getFirstElement(); + } + + /** + * Compare the list of selected dependencies against the selected targetPOM. + * If one of the dependencies is already under dependencyManagement, but has + * a different version than the selected dependency, warn the user about this. + * + * returns true if the user has been warned (but this method updates the status itself) + * + * @param model + * @param dependencies + */ + protected boolean checkDependencies(org.apache.maven.model.Model model, LinkedList<Dependency> dependencies) { + if (this.status != null && this.status.getCode() == IStatus.ERROR) { + //Don't warn the user if there is already an error + return false; + } + if (model == null || model.getDependencyManagement() == null + || model.getDependencyManagement().getDependencies() == null + || model.getDependencyManagement().getDependencies().isEmpty()) { + return false; + } + + for (Dependency selectedDep : dependencies ) { + for (org.apache.maven.model.Dependency targetDep : model.getDependencyManagement().getDependencies()) { + if (selectedDep.getGroupId().equals(targetDep.getGroupId()) + && selectedDep.getArtifactId().equals(targetDep.getArtifactId()) + && !selectedDep.getVersion().equals(targetDep.getVersion())) { + String modelID = model.getGroupId()+":"+model.getArtifactId()+":"+model.getVersion(); //$NON-NLS-1$ //$NON-NLS-2$ + if (targetDep.getLocation("") != null && targetDep.getLocation("").getSource() != null) { //$NON-NLS-1$ //$NON-NLS-2$ + modelID = targetDep.getLocation("").getSource().getModelId(); //$NON-NLS-1$ + } + Object[] arguments = { + selectedDep.getArtifactId()+"-"+selectedDep.getVersion(), //$NON-NLS-1$ + targetDep.getVersion(), + modelID + }; + String message = NLS.bind(Messages.ManageDependenciesDialog_dependencyExistsWarning, arguments); + updateStatus(new Status(IStatus.WARNING, MavenEditorPlugin.PLUGIN_ID, message)); + return true; + } + } + } + return false; + } + + protected void checkStatus(MavenProject targetProject, LinkedList<Dependency> selectedDependencies) { + if (targetProject == null) { + clearStatus(); + return; + } + boolean error = false; + IMavenProjectFacade facade = MavenPlugin.getDefault().getMavenProjectManager().getMavenProject(targetProject.getGroupId(), targetProject.getArtifactId(), targetProject.getVersion()); + if (facade == null) { + error = true; + updateStatus(new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, Messages.ManageDependenciesDialog_projectNotPresentError)); + } else { + org.apache.maven.model.Model model = null; + if (facade.getMavenProject() == null || facade.getMavenProject().getModel() == null) { + try { + model = MavenPlugin.getDefault().getMavenModelManager().readMavenModel(facade.getPom()); + } catch(CoreException e) { + Object[] arguments = { facade.getPom(), e.getLocalizedMessage() }; + Status status = new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, NLS.bind(Messages.ManageDependenciesDialog_pomReadingError,arguments)); + MavenPlugin.getDefault().getLog().log(status); + updateStatus(status); + error = true; + } + } else { + model = facade.getMavenProject().getModel(); + } + if (model != null) { + error = checkDependencies(model, getDependenciesList()); + } + } + + if (!error) { + clearStatus(); + } + } + + protected void clearStatus() { + updateStatus(new Status(IStatus.OK, MavenEditorPlugin.PLUGIN_ID, "")); //$NON-NLS-1$ + } + + protected class DependenciesViewerSelectionListener implements ISelectionChangedListener { + public void selectionChanged(SelectionChangedEvent event) { + checkStatus(getTargetPOM(), getDependenciesList()); + } + } + + protected class PomViewerSelectionChangedListener implements ISelectionChangedListener { + public void selectionChanged(SelectionChangedEvent event) { + checkStatus(getTargetPOM(), getDependenciesList()); + } + } + + @Override + protected void updateStatus(IStatus status) { + this.status = status; + super.updateStatus(status); + } + + public static class DepLabelProvider extends LabelProvider implements IColorProvider { + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) + */ + @Override + public String getText(Object element) { + MavenProject project = null; + if (element instanceof MavenProject) { + project = (MavenProject) element; + } else if (element instanceof Object[]) { + project = (MavenProject) ((Object[]) element)[0]; + } else { + return ""; //$NON-NLS-1$ + } + + StringBuffer buffer = new StringBuffer(); + buffer.append(project.getGroupId() + " : " + project.getArtifactId() + " : " +project.getVersion()); //$NON-NLS-1$ //$NON-NLS-2$ + return buffer.toString(); + + } + + public Color getForeground(Object element) { + if (element instanceof MavenProject) { + MavenProject project = (MavenProject) element; + IMavenProjectFacade search = MavenPlugin.getDefault().getMavenProjectManager().getMavenProject(project.getGroupId(), project.getArtifactId(), project.getVersion()); + if (search == null) { + //This project is not in the workspace so we can't really modify it. + return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); + } + } + return null; + } + + public Color getBackground(Object element) { + return null; + } + } + + public class ContentProvider implements ITreeContentProvider { + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + public void dispose() { + } + + public boolean hasChildren(Object element) { + Object[] children = getChildren(element); + + return children.length != 0; + } + + public Object getParent(Object element) { + if (element instanceof MavenProject){ + MavenProject project = (MavenProject) element; + return project.getParent(); + } + return null; + } + + /* + * Return root element + * (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object) + */ + public Object[] getElements(Object inputElement) { + + if (inputElement instanceof LinkedList) { + LinkedList<MavenProject> projects = (LinkedList<MavenProject>) inputElement; + if (projects.isEmpty()) { + return new Object[0]; + } + return new Object[] { projects.getLast() }; + } + + return new Object[0]; + } + + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof MavenProject) { + /* + * Walk the hierarchy list until we find the parentElement and + * return the previous element, which is the child. + */ + MavenProject parent = (MavenProject) parentElement; + + if (getProjectHierarchy().size() == 1) { + //No parent exists, only one element in the tree + return new Object[0]; + } + + if (getProjectHierarchy().getFirst().equals(parent)) { + //We are the final child + return new Object[0]; + } + + ListIterator<MavenProject> iter = getProjectHierarchy().listIterator(); + while (iter.hasNext()) { + MavenProject next = iter.next(); + if (next.equals(parent)) { + iter.previous(); + MavenProject previous = iter.previous(); + return new Object[] { previous }; + } + } + } + return new Object[0]; + } + } + + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/Messages.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/Messages.java new file mode 100644 index 00000000..dba6ae66 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/Messages.java @@ -0,0 +1,30 @@ + +package org.eclipse.m2e.editor.dialogs; + +import org.eclipse.osgi.util.NLS; + + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.m2e.editor.dialogs.messages"; //$NON-NLS-1$ + + public static String ManageDependenciesDialog_dependencyExistsWarning; + + public static String ManageDependenciesDialog_dialogInfo; + + public static String ManageDependenciesDialog_dialogTitle; + + public static String ManageDependenciesDialog_pomReadingError; + + public static String ManageDependenciesDialog_projectNotPresentError; + + public static String ManageDependenciesDialog_selectDependenciesLabel; + + public static String ManageDependenciesDialog_selectPOMLabel; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/messages.properties b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/messages.properties new file mode 100644 index 00000000..29ab0a6b --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/dialogs/messages.properties @@ -0,0 +1,7 @@ +ManageDependenciesDialog_dependencyExistsWarning=Dependency {0} already declared with version {1} under {2}''s dependencyManagement. +ManageDependenciesDialog_dialogInfo=This will start managing the selected dependencies for all child POMs. You may select the POM that will manage these dependencies. The version information will then be moved to it. +ManageDependenciesDialog_dialogTitle=Manage Dependencies +ManageDependenciesDialog_pomReadingError=Error reading POM file {0}: {1} +ManageDependenciesDialog_projectNotPresentError=The selected project cannot be chosen because it is not present in your workspace. +ManageDependenciesDialog_selectDependenciesLabel=Select dependencies to manage: +ManageDependenciesDialog_selectPOMLabel=Select the POM which will manage the dependencies: diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/Messages.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/Messages.java new file mode 100644 index 00000000..bef6ce02 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/Messages.java @@ -0,0 +1,578 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.internal; + +import org.eclipse.osgi.util.NLS; + + +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.m2e.editor.internal.messages"; //$NON-NLS-1$ + + public static String BuildComposite_btnFiltering; + + public static String BuildComposite_lblDefaultGoal; + + public static String BuildComposite_lblDirectory; + + public static String BuildComposite_lblExcludes; + + public static String BuildComposite_lblFilters; + + public static String BuildComposite_lblFinalName; + + public static String BuildComposite_lblIncludes; + + public static String BuildComposite_lblTargetPath; + + public static String BuildComposite_section_build; + + public static String BuildComposite_sectionResourceDetails; + + public static String BuildComposite_sectionResources; + + public static String BuildComposite_sectionTestResources; + + public static String BuildPage_action_addExtension; + + public static String BuildPage_action_openWeb; + + public static String BuildPage_action_selectExtension; + + public static String BuildPage_action_showGroupId; + + public static String BuildPage_form; + + public static String BuildPage_lblArtifactId; + + public static String BuildPage_lblGroupId; + + public static String BuildPage_lblOutput; + + public static String BuildPage_lblScripts; + + public static String BuildPage_lblSources; + + public static String BuildPage_lblTestOutput; + + public static String BuildPage_lblTestSources; + + public static String BuildPage_lblVersion; + + public static String BuildPage_searchDialog_addExtension; + + public static String BuildPage_searchDialog_selectExtension; + + public static String BuildPage_section_extensionDetails; + + public static String BuildPage_section_extensions; + + public static String BuildPage_section_folders; + + public static String BuildPage_title; + + public static String CustomLifecycleParamsDialog_btnCopyFrom; + + public static String CustomLifecycleParamsDialog_btnCreateEmpty; + + public static String DefaultPluginConfigurationEditor_lblUseXml; + + public static String DependenciesComposite_action_filter; + + public static String DependenciesComposite_action_open_project_page; + + public static String DependenciesComposite_action_selectDependency; + + public static String DependenciesComposite_action_selectExclusion; + + public static String DependenciesComposite_action_showgroupid; + + public static String DependenciesComposite_action_showInheritedDependencies; + + public static String DependenciesComposite_action_sortAlphabetically; + + public static String DependenciesComposite_btnOptional; + + public static String DependenciesComposite_btnSelect; + + public static String DependenciesComposite_checkConsoleForErrors; + + public static String DependenciesComposite_error; + + public static String DependenciesComposite_fixProjectErrors; + + public static String DependenciesComposite_lblArtifactId; + + public static String DependenciesComposite_lblClassifier; + + public static String DependenciesComposite_lblExclusionArtifactId; + + public static String DependenciesComposite_lblExclusionGroupId; + + public static String DependenciesComposite_lblGroupId; + + public static String DependenciesComposite_lblScope; + + public static String DependenciesComposite_lblSystemPath; + + public static String DependenciesComposite_lblType; + + public static String DependenciesComposite_lblVersion; + + public static String DependenciesComposite_manageButton; + + public static String DependenciesComposite_searchDialog_selectExclusion; + + public static String DependenciesComposite_searchDialog_title; + + public static String DependenciesComposite_searchTitle_addExclusion; + + public static String DependenciesComposite_section_dependency_details; + + public static String DependenciesComposite_section_ExclusionDetails; + + public static String DependenciesComposite_sectionDependencies; + + public static String DependenciesComposite_sectionDependencyManagement; + + public static String DependenciesComposite_sectionExclusions; + + public static String DependenciesPage_find; + + public static String DependenciesPage_form; + + public static String DependenciesPage_title; + + public static String DependencyTreePage_0; + + public static String DependencyTreePage_action_collapseAll; + + public static String DependencyTreePage_action_expandAll; + + public static String DependencyTreePage_action_filter; + + public static String DependencyTreePage_action_filterSearch; + + public static String DependencyTreePage_action_refresh; + + public static String DependencyTreePage_action_showGroupId; + + public static String DependencyTreePage_action_sort; + + public static String DependencyTreePage_classpath; + + public static String DependencyTreePage_find; + + public static String DependencyTreePage_form_title; + + public static String DependencyTreePage_job_loading; + + public static String DependencyTreePage_job_reloading; + + public static String DependencyTreePage_message_resolving; + + public static String DependencyTreePage_message_updating; + + public static String DependencyTreePage_scope_all; + + public static String DependencyTreePage_scope_comp_runtime; + + public static String DependencyTreePage_scope_compile; + + public static String DependencyTreePage_scope_runtime; + + public static String DependencyTreePage_section_hierarchy; + + public static String DependencyTreePage_section_resolvedDeps; + + public static String DependencyTreePage_title; + + public static String FormUtils_click_for_details; + + public static String FormUtils_error_info; + + public static String FormUtils_pom_error; + + public static String LifecyclePage_btnAdd; + + public static String LifecyclePage_btnDisable; + + public static String LifecyclePage_btnEdit; + + public static String LifecyclePage_btnEnable; + + public static String LifecyclePage_btnRemove; + + public static String LifecyclePage_column_incremental; + + public static String LifecyclePage_column_name; + + public static String LifecyclePage_form_name; + + public static String LifecyclePage_job_reloading; + + public static String LifecyclePage_message_updating; + + public static String LifecyclePage_scrolledForm; + + public static String LifecyclePage_section_details; + + public static String LifecyclePage_section_mapping; + + public static String ListEditorComposite_btnAdd; + + public static String ListEditorComposite_btnCreate; + + public static String ListEditorComposite_btnRemove; + + public static String ListEditorComposite_btnProperties; + + public static String MavenPomEditor_action_advanced; + + public static String MavenPomEditor_effective; + + public static String MavenPomEditor_effective_pom; + + public static String MavenPomEditor_error_failed_effective; + + public static String MavenPomEditor_error_loading_effective_pom; + + public static String MavenPomEditor_job_disposing; + + public static String MavenPomEditor_job_saving; + + public static String MavenPomEditor_loading; + + public static String MavenPomEditor_task_reading; + + public static String MavenPomEditorPage_actio_refresh; + + public static String MavenPomEditorPage_action_open; + + public static String MavenPomEditorPage_error_unknown; + + public static String MavenPomEditorPage_job_opening; + + public static String OverviewPage_action_new_module_project; + + public static String OverviewPage_action_newModuleElement; + + public static String OverviewPage_action_selectParent; + + public static String OverviewPage_form; + + public static String OverviewPage_job; + + public static String OverviewPage_job_open; + + public static String OverviewPage_lblArtifactId; + + public static String OverviewPage_lblConnection; + + public static String OverviewPage_lblDesc; + + public static String OverviewPage_lblDev; + + public static String OverviewPage_lblGroupId; + + public static String OverviewPage_lblGroupId2; + + public static String OverviewPage_lblInception; + + public static String OverviewPage_lblName; + + public static String OverviewPage_lblPackaging; + + public static String OverviewPage_lblRelPath; + + public static String OverviewPage_lblSystem; + + public static String OverviewPage_lblTag; + + public static String OverviewPage_lblUrl; + + public static String OverviewPage_lblVersion; + + public static String OverviewPage_lblVersion2; + + public static String OverviewPage_msg_not_pom_packaging; + + public static String OverviewPage_opening_editors; + + public static String OverviewPage_searchDialog_selectParent; + + public static String OverviewPage_section_artifact; + + public static String OverviewPage_section_ci; + + public static String OverviewPage_section_issueMan; + + public static String OverviewPage_section_modules; + + public static String OverviewPage_section_org; + + public static String OverviewPage_section_parent; + + public static String OverviewPage_section_project; + + public static String OverviewPage_section_scm; + + public static String OverviewPage_selectModuleProjects; + + public static String OverviewPage_title; + + public static String OverviewPage_updateModulePoms; + + public static String PluginsComposite_action_Filter; + + public static String PluginsComposite_action_openWeb; + + public static String PluginsComposite_action_openXml; + + public static String PluginsComposite_action_other; + + public static String PluginsComposite_action_selectPlugin; + + public static String PluginsComposite_action_showGroupId; + + public static String PluginsComposite_btnExtensions; + + public static String PluginsComposite_btnInherited; + + public static String PluginsComposite_lblArtifactId; + + public static String PluginsComposite_lblGoals; + + public static String PluginsComposite_lblGroupId; + + public static String PluginsComposite_lblId; + + public static String PluginsComposite_lblPhase; + + public static String PluginsComposite_lblVersion; + + public static String PluginsComposite_linkConfiguration; + + public static String PluginsComposite_seachDialog_selectPlugin; + + public static String PluginsComposite_searchDialog_addPlugin; + + public static String PluginsComposite_searchDialog_selectPlugin; + + public static String PluginsComposite_section_configuration; + + public static String PluginsComposite_section_executionDetails; + + public static String PluginsComposite_section_Executions; + + public static String PluginsComposite_section_pluginDetails; + + public static String PluginsComposite_section_PluginDependencies; + + public static String PluginsComposite_section_PluginManagent; + + public static String PluginsComposite_section_Plugins; + + public static String PluginsComposite_tooltip_addPlugin; + + public static String PluginsPage_find; + + public static String PluginsPage_form; + + public static String PluginsPage_title; + + public static String PomEditorMenuCreator_action_showDependencyHierarchy; + + public static String ProfilesPage_action_newModuleProject; + + public static String ProfilesPage_btnActivateByDefault; + + public static String ProfilesPage_form; + + public static String ProfilesPage_lblArchitecture; + + public static String ProfilesPage_lblExists; + + public static String ProfilesPage_lblFamily; + + public static String ProfilesPage_lblJdk; + + public static String ProfilesPage_lblMissing; + + public static String ProfilesPage_lblName; + + public static String ProfilesPage_lblValue; + + public static String ProfilesPage_lblVersion; + + public static String ProfilesPage_section_file; + + public static String ProfilesPage_section_jdk; + + public static String ProfilesPage_section_modules; + + public static String ProfilesPage_section_os; + + public static String ProfilesPage_section_profiles; + + public static String ProfilesPage_section_property; + + public static String ProfilesPage_tab_activation; + + public static String ProfilesPage_tab_build; + + public static String ProfilesPage_tab_dependencies; + + public static String ProfilesPage_tab_plugins; + + public static String ProfilesPage_tab_reporting; + + public static String ProfilesPage_tab_repositories; + + public static String ProfilesPage_title; + + public static String PropertiesSection_section_properties; + + public static String PropertiesSection_title_addProperty; + + public static String PropertiesSection_title_editProperty; + + public static String PropertyPairLabelProvider_0; + + public static String ReportingComposite_action_filter; + + public static String ReportingComposite_action_openWeb; + + public static String ReportingComposite_action_selectReportingPlugin; + + public static String ReportingComposite_action_showGroupId; + + public static String ReportingComposite_btnExcludeDefaults; + + public static String ReportingComposite_btnInherited; + + public static String ReportingComposite_lblArtifactId; + + public static String ReportingComposite_lblGroupId; + + public static String ReportingComposite_lblOutputFolder; + + public static String ReportingComposite_lblVersion; + + public static String ReportingComposite_link_Configuration; + + public static String ReportingComposite_searchDialog_addPlugin; + + public static String ReportingComposite_searchDialog_selectPlugin; + + public static String ReportingComposite_section_Content; + + public static String ReportingComposite_section_reportingPluginDetails; + + public static String ReportingComposite_section_reportSetReports; + + public static String ReportingComposite_section_reportSets; + + public static String ReportingComposite_sectionReportingPlugins; + + public static String ReportingPage_find; + + public static String ReportingPage_form; + + public static String ReportingPage_title; + + public static String RepositoriesComposite_btnEnableRelease; + + public static String RepositoriesComposite_btnEnableSnapshots; + + public static String RepositoriesComposite_btnUniqueVersion; + + public static String RepositoriesComposite_lblArtifactid; + + public static String RepositoriesComposite_lblChecksumPolicy; + + public static String RepositoriesComposite_lblDownload; + + public static String RepositoriesComposite_lblGroupId; + + public static String RepositoriesComposite_lblId; + + public static String RepositoriesComposite_lblLayout; + + public static String RepositoriesComposite_lblMessage; + + public static String RepositoriesComposite_lblName; + + public static String RepositoriesComposite_lblRepoId; + + public static String RepositoriesComposite_lblSiteId; + + public static String RepositoriesComposite_lblUpdatePolicy; + + public static String RepositoriesComposite_lblUrl; + + public static String RepositoriesComposite_lblUrl2; + + public static String RepositoriesComposite_lblVersion; + + public static String RepositoriesComposite_section_pluginRepositories; + + public static String RepositoriesComposite_section_projectSite; + + public static String RepositoriesComposite_section_releaseDistRepo; + + public static String RepositoriesComposite_section_repositories; + + public static String RepositoriesComposite_section_repositoryDetails; + + public static String RepositoriesComposite_section_snapshotDistRepo; + + public static String RepositoriesComposite_sectionRelocation; + + public static String RepositoriesPage_form; + + public static String RepositoriesPage_title; + + public static String SearchControl_lblSearch; + + public static String ShowDependencyHierarchyAction_job_openPomEditor; + + public static String TeamComposite_lblEmail; + + public static String TeamComposite_lblId; + + public static String TeamComposite_lblName; + + public static String TeamComposite_lblTimezone; + + public static String TeamComposite_lblUrl; + + public static String TeamComposite_section_contributors; + + public static String TeamComposite_section_developers; + + public static String TeamComposite_section_organization; + + public static String TeamComposite_section_roles; + + public static String TeamComposite_section_userdetails; + + public static String TeamPage_form; + + public static String TeamPage_title; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/actions/PomEditorMenuCreator.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/actions/PomEditorMenuCreator.java new file mode 100644 index 00000000..f2676969 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/actions/PomEditorMenuCreator.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.internal.actions; + +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.m2e.core.actions.AbstractMavenMenuCreator; +import org.eclipse.m2e.core.actions.SelectionUtil; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.internal.Messages; + + +/** + * @author Eugene Kuleshov + */ +public class PomEditorMenuCreator extends AbstractMavenMenuCreator { + + public void createMenu(IMenuManager mgr) { + int selectionType = SelectionUtil.getSelectionType(selection); + if(selectionType == SelectionUtil.JAR_FILE) { + mgr.appendToGroup(OPEN, getAction(new ShowDependencyHierarchyAction(), // + ShowDependencyHierarchyAction.ID, + Messages.PomEditorMenuCreator_action_showDependencyHierarchy, MavenEditorImages.HIERARCHY)); + } + } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/actions/ShowDependencyHierarchyAction.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/actions/ShowDependencyHierarchyAction.java new file mode 100644 index 00000000..61ed4961 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/actions/ShowDependencyHierarchyAction.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.internal.actions; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.m2e.core.actions.OpenPomAction; +import org.eclipse.m2e.core.actions.SelectionUtil; +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.editor.pom.MavenPomEditor; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.actions.ActionDelegate; + + +/** + * @author Eugene Kuleshov + */ +public class ShowDependencyHierarchyAction extends ActionDelegate { + + public static final String ID = "org.eclipse.m2e.ShowDependencyHierarchy"; //$NON-NLS-1$ + + private IStructuredSelection selection; + + public void selectionChanged(IAction action, ISelection selection) { + if(selection instanceof IStructuredSelection) { + this.selection = (IStructuredSelection) selection; + } else { + this.selection = null; + } + } + + public void run(IAction action) { + if(selection != null) { + Object element = this.selection.getFirstElement(); + IMavenProjectFacade projectFacade = SelectionUtil.getType(element, IMavenProjectFacade.class); + if(projectFacade!=null) { + ArtifactKey artifactKey = SelectionUtil.getType(element, ArtifactKey.class); + if(artifactKey!=null) { + showDependencyHierarchy(projectFacade.getArtifactKey(), artifactKey); + } + } + } + } + + private void showDependencyHierarchy(final ArtifactKey projectKey, final ArtifactKey artifactKey) { + if(artifactKey != null) { + new Job(Messages.ShowDependencyHierarchyAction_job_openPomEditor) { + protected IStatus run(IProgressMonitor monitor) { + final IEditorPart editor = OpenPomAction.openEditor(projectKey.getGroupId(), // + projectKey.getArtifactId(), projectKey.getVersion(), monitor); + if(editor instanceof MavenPomEditor) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + ((MavenPomEditor) editor).showDependencyHierarchy(artifactKey); + } + }); + } + return Status.OK_STATUS; + } + }.schedule(); + } + } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/messages.properties b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/messages.properties new file mode 100644 index 00000000..4b2f988b --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/internal/messages.properties @@ -0,0 +1,276 @@ +BuildComposite_btnFiltering=Filtering +BuildComposite_lblDefaultGoal=Default Goal: +BuildComposite_lblDirectory=Directory: +BuildComposite_lblExcludes=Excludes: +BuildComposite_lblFilters=Filters: +BuildComposite_lblFinalName=Final Name: +BuildComposite_lblIncludes=Includes: +BuildComposite_lblTargetPath=Target Path: +BuildComposite_section_build=Build +BuildComposite_sectionResourceDetails=Resource Details +BuildComposite_sectionResources=Resources +BuildComposite_sectionTestResources=Test Resources +BuildPage_action_addExtension=Add Extension +BuildPage_action_openWeb=Open Web Page +BuildPage_action_selectExtension=Select Extension +BuildPage_action_showGroupId=Show GroupId +BuildPage_form=Build +BuildPage_lblArtifactId=Artifact Id:* +BuildPage_lblGroupId=Group Id:* +BuildPage_lblOutput=Output: +BuildPage_lblScripts=Scripts: +BuildPage_lblSources=Sources: +BuildPage_lblTestOutput=Test Output: +BuildPage_lblTestSources=Test Sources: +BuildPage_lblVersion=Version: +BuildPage_searchDialog_addExtension=Add Extension +BuildPage_searchDialog_selectExtension=Select Extension +BuildPage_section_extensionDetails=Extension Details +BuildPage_section_extensions=Extensions +BuildPage_section_folders=Folders +BuildPage_title=Build +CustomLifecycleParamsDialog_btnCopyFrom=Copy From +CustomLifecycleParamsDialog_btnCreateEmpty=Create Empty +DefaultPluginConfigurationEditor_lblUseXml=Use the XML tab to configure this plugin +DependenciesComposite_action_filter=Filter +DependenciesComposite_action_open_project_page=Open Project Page +DependenciesComposite_action_selectDependency=Select Dependency +DependenciesComposite_action_selectExclusion=Select Exclusion +DependenciesComposite_action_showgroupid=Show GroupId +DependenciesComposite_action_showInheritedDependencies=Show inherited dependencies +DependenciesComposite_action_sortAlphabetically=Sort alphabetically +DependenciesComposite_btnOptional=Optional +DependenciesComposite_btnSelect=Select... +DependenciesComposite_checkConsoleForErrors=Unable to read maven project. Check the console output for possible problems. +DependenciesComposite_error=Error +DependenciesComposite_fixProjectErrors=Unable to read project metadata. Please fix the project errors. +DependenciesComposite_lblArtifactId=Artifact Id: +DependenciesComposite_lblClassifier=Classifier: +DependenciesComposite_lblExclusionArtifactId=Artifact Id: +DependenciesComposite_lblExclusionGroupId=Group Id: +DependenciesComposite_lblGroupId=Group Id: +DependenciesComposite_lblScope=Scope: +DependenciesComposite_lblSystemPath=System Path: +DependenciesComposite_lblType=Type: +DependenciesComposite_lblVersion=Version: +DependenciesComposite_manageButton=Manage... +DependenciesComposite_searchDialog_selectExclusion=Select Exclusion +DependenciesComposite_searchDialog_title=Select Dependency +DependenciesComposite_searchTitle_addExclusion=Add Exclusion +DependenciesComposite_section_dependency_details=Dependency Details +DependenciesComposite_section_ExclusionDetails=Exclusion Details +DependenciesComposite_sectionDependencies=Dependencies +DependenciesComposite_sectionDependencyManagement=Dependency Management +DependenciesComposite_sectionExclusions=Exclusions +DependenciesPage_find=Find +DependenciesPage_form=Dependencies +DependenciesPage_title=Dependencies +DependencyTreePage_0=\ - +DependencyTreePage_action_collapseAll=Collapse All +DependencyTreePage_action_expandAll=Expand All +DependencyTreePage_action_filter=Filter Search Results +DependencyTreePage_action_filterSearch=Filter Search Results +DependencyTreePage_action_refresh=Refresh +DependencyTreePage_action_showGroupId=Show GroupId +DependencyTreePage_action_sort=Sort +DependencyTreePage_classpath=Classpath +DependencyTreePage_find=Find +DependencyTreePage_form_title=Dependency Hierarchy [{0}] +DependencyTreePage_job_loading=Loading pom.xml +DependencyTreePage_job_reloading=Reloading +DependencyTreePage_message_resolving=Resolving dependencies... +DependencyTreePage_message_updating=Updating dependencies... +DependencyTreePage_scope_all=all (test) +DependencyTreePage_scope_comp_runtime=compile+runtime +DependencyTreePage_scope_compile=compile +DependencyTreePage_scope_runtime=runtime +DependencyTreePage_section_hierarchy=Dependency Hierarchy +DependencyTreePage_section_resolvedDeps=Resolved Dependencies +DependencyTreePage_title=Dependency Hierarchy +FormUtils_click_for_details={0} (Click for more details) +FormUtils_error_info=Error info: +FormUtils_pom_error=The POM has the following error: +LifecyclePage_btnAdd=Add +LifecyclePage_btnDisable=Disable +LifecyclePage_btnEdit=Edit... +LifecyclePage_btnEnable=Enable +LifecyclePage_btnRemove=Remove +LifecyclePage_column_incremental=Incremental +LifecyclePage_column_name=Name +LifecyclePage_form_name=Lifecycle Mappings +LifecyclePage_job_reloading=Reloading +LifecyclePage_message_updating=Updating lifecycle mappings... +LifecyclePage_scrolledForm=Lifecycle Mappings (experimental) +LifecyclePage_section_details=Mapping Details +LifecyclePage_section_mapping=Lifecycle Mapping +ListEditorComposite_btnAdd=Add... +ListEditorComposite_btnCreate=Create... +ListEditorComposite_btnRemove=Remove +ListEditorComposite_btnProperties=Properties... +MavenPomEditor_action_advanced=Show Advanced Tabs +MavenPomEditor_effective=\ [effective] +MavenPomEditor_effective_pom=Effective POM +MavenPomEditor_error_failed_effective=Failed to load Effective POM +MavenPomEditor_error_loading_effective_pom=Unable to load Effective POM. See console for errors. +MavenPomEditor_job_disposing=Disposing +MavenPomEditor_job_saving=Saving +MavenPomEditor_loading=Loading Effective POM... +MavenPomEditor_task_reading=Reading project +MavenPomEditorPage_actio_refresh=Refresh +MavenPomEditorPage_action_open=Open Parent POM +MavenPomEditorPage_error_unknown=Unknown error +MavenPomEditorPage_job_opening=Opening POM +OverviewPage_action_new_module_project=New module project +OverviewPage_action_newModuleElement=New module element +OverviewPage_action_selectParent=Select Parent +OverviewPage_form=Overview +OverviewPage_job=Opening {0}:{1}:{2} +OverviewPage_job_open=Open Parent POM +OverviewPage_lblArtifactId=Artifact Id: +OverviewPage_lblConnection=Connection: +OverviewPage_lblDesc=Description: +OverviewPage_lblDev=Developer: +OverviewPage_lblGroupId=Group Id: +OverviewPage_lblGroupId2=Group Id: +OverviewPage_lblInception=Inception: +OverviewPage_lblName=Name: +OverviewPage_lblPackaging=Packaging: +OverviewPage_lblRelPath=Relative Path: +OverviewPage_lblSystem=System: +OverviewPage_lblTag=Tag: +OverviewPage_lblUrl=URL: +OverviewPage_lblVersion=Version: +OverviewPage_lblVersion2=Version: +OverviewPage_msg_not_pom_packaging=Only projects with 'pom' packaging can declare modules +OverviewPage_opening_editors=Opening POM editors +OverviewPage_searchDialog_selectParent=Select Parent +OverviewPage_section_artifact=Artifact +OverviewPage_section_ci=Continuous Integration +OverviewPage_section_issueMan=Issue Management +OverviewPage_section_modules=Modules +OverviewPage_section_org=Organization +OverviewPage_section_parent=Parent +OverviewPage_section_project=Project +OverviewPage_section_scm=SCM +OverviewPage_selectModuleProjects=Select Module Projects +OverviewPage_title=Overview +OverviewPage_updateModulePoms=Update POM parent section in selected projects +PluginsComposite_action_Filter=Filter +PluginsComposite_action_openWeb=Open Web Page +PluginsComposite_action_openXml=Open XML Configuration +PluginsComposite_action_other=Other... +PluginsComposite_action_selectPlugin=Select Plugin +PluginsComposite_action_showGroupId=Show GroupId +PluginsComposite_btnExtensions=Extensions +PluginsComposite_btnInherited=Inherited +PluginsComposite_lblArtifactId=Artifact Id: +PluginsComposite_lblGoals=Goals: +PluginsComposite_lblGroupId=Group Id: +PluginsComposite_lblId=Id: +PluginsComposite_lblPhase=Phase: +PluginsComposite_lblVersion=Version: +PluginsComposite_linkConfiguration=Configuration +PluginsComposite_seachDialog_selectPlugin=Select Plugin +PluginsComposite_searchDialog_addPlugin=Add Plugin +PluginsComposite_searchDialog_selectPlugin=Select Plugin +PluginsComposite_section_configuration=Configuration +PluginsComposite_section_executionDetails=Execution Details +PluginsComposite_section_Executions=Executions +PluginsComposite_section_PluginDependencies=Plugin Dependencies +PluginsComposite_section_pluginDetails=Plugin Details +PluginsComposite_section_PluginManagent=Plugin Management +PluginsComposite_section_Plugins=Plugins +PluginsComposite_tooltip_addPlugin=Add Plugin +PluginsPage_find=Find +PluginsPage_form=Plugins +PluginsPage_title=Plugins +PomEditorMenuCreator_action_showDependencyHierarchy=Show Dependency Hierarchy +ProfilesPage_action_newModuleProject=New module project +ProfilesPage_btnActivateByDefault=Active by default +ProfilesPage_form=Profiles +ProfilesPage_lblArchitecture=Architecture: +ProfilesPage_lblExists=Exist: +ProfilesPage_lblFamily=Family: +ProfilesPage_lblJdk=JDK: +ProfilesPage_lblMissing=Missing: +ProfilesPage_lblName=Name: +ProfilesPage_lblValue=Value: +ProfilesPage_lblVersion=Version: +ProfilesPage_section_file=File +ProfilesPage_section_jdk=JDK +ProfilesPage_section_modules=Modules +ProfilesPage_section_os=OS +ProfilesPage_section_profiles=Profiles +ProfilesPage_section_property=Property +ProfilesPage_tab_activation=Activation +ProfilesPage_tab_build=Build +ProfilesPage_tab_dependencies=Dependencies +ProfilesPage_tab_plugins=Plugins +ProfilesPage_tab_reporting=Reporting +ProfilesPage_tab_repositories=Repositories +ProfilesPage_title=Profiles +PropertiesSection_section_properties=Properties +PropertiesSection_title_addProperty=Add property +PropertiesSection_title_editProperty=Edit property +PropertyPairLabelProvider_0={0} : {1} +ReportingComposite_action_filter=Filter +ReportingComposite_action_openWeb=Open Web Page +ReportingComposite_action_selectReportingPlugin=Select Reporting Plugin +ReportingComposite_action_showGroupId=Show GroupId +ReportingComposite_btnExcludeDefaults=Exclude Defaults +ReportingComposite_btnInherited=Inherited +ReportingComposite_lblArtifactId=Artifact Id: +ReportingComposite_lblGroupId=Group Id: +ReportingComposite_lblOutputFolder=Output Folder: +ReportingComposite_lblVersion=Version: +ReportingComposite_link_Configuration=Configuration +ReportingComposite_searchDialog_addPlugin=Add Plugin +ReportingComposite_searchDialog_selectPlugin=Select Plugin +ReportingComposite_section_Content=Content +ReportingComposite_section_reportingPluginDetails=Reporting Plugin Details +ReportingComposite_section_reportSetReports=Report Set Reports +ReportingComposite_section_reportSets=Report Sets +ReportingComposite_sectionReportingPlugins=Reporting Plugins +ReportingPage_find=Find +ReportingPage_form=Reporting +ReportingPage_title=Reporting +RepositoriesComposite_btnEnableRelease=Enable Releases +RepositoriesComposite_btnEnableSnapshots=Enable Snapshots +RepositoriesComposite_btnUniqueVersion=Unique Version +RepositoriesComposite_lblArtifactid=Artifact Id: +RepositoriesComposite_lblChecksumPolicy=Checksum Policy: +RepositoriesComposite_lblDownload=Download: +RepositoriesComposite_lblGroupId=Group Id: +RepositoriesComposite_lblId=Id:* +RepositoriesComposite_lblLayout=Layout: +RepositoriesComposite_lblMessage=Message: +RepositoriesComposite_lblName=Name: +RepositoriesComposite_lblRepoId=Id: +RepositoriesComposite_lblSiteId=Id: +RepositoriesComposite_lblUpdatePolicy=Update Policy: +RepositoriesComposite_lblUrl=URL:* +RepositoriesComposite_lblUrl2=URL: +RepositoriesComposite_lblVersion=Version: +RepositoriesComposite_section_pluginRepositories=Plugin Repositories +RepositoriesComposite_section_projectSite=Project Site +RepositoriesComposite_section_releaseDistRepo=Release Distribution Repository +RepositoriesComposite_section_repositories=Repositories +RepositoriesComposite_section_repositoryDetails=Repository Details +RepositoriesComposite_section_snapshotDistRepo=Snapshots Distribution Repository +RepositoriesComposite_sectionRelocation=Relocation +RepositoriesPage_form=Repositories +RepositoriesPage_title=Repositories +SearchControl_lblSearch=Search: +ShowDependencyHierarchyAction_job_openPomEditor=Opening POM editor +TeamComposite_lblEmail=Email: +TeamComposite_lblId=Id: +TeamComposite_lblName=Name: +TeamComposite_lblTimezone=Timezone: +TeamComposite_lblUrl=URL: +TeamComposite_section_contributors=Contributors +TeamComposite_section_developers=Developers +TeamComposite_section_organization=Organization +TeamComposite_section_roles=Roles +TeamComposite_section_userdetails=Details +TeamPage_form=Team +TeamPage_title=Team diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/plugins/DefaultPluginConfigurationEditor.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/plugins/DefaultPluginConfigurationEditor.java new file mode 100644 index 00000000..1574ec13 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/plugins/DefaultPluginConfigurationEditor.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.plugins; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.editor.pom.MavenPomEditorPage; +import org.eclipse.m2e.model.edit.pom.Configuration; +import org.eclipse.m2e.model.edit.pom.Plugin; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +public class DefaultPluginConfigurationEditor implements Adapter, IPluginConfigurationExtension { + + protected Plugin plugin = null; + protected Configuration configuration = null; + protected MavenPomEditorPage pomEditor = null; + protected Notifier target; + + public Composite createComposite(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayout(new GridLayout(1, true)); + + Label label = new Label(composite, SWT.NONE); + label.setText(Messages.DefaultPluginConfigurationEditor_lblUseXml); + label.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false)); + label.setEnabled(false); + + return composite; + } + + public void cleanup() { + if(this.configuration != null) { + this.configuration.eAdapters().remove(this); + this.configuration = null; + } + } + + public void setPlugin(Plugin plugin) { + cleanup(); + this.plugin = plugin; + this.configuration = plugin.getConfiguration(); + if(this.configuration != null) { + this.configuration.eAdapters().add(this); + } + } + + public void setPomEditor(MavenPomEditorPage editor) { + this.pomEditor = editor; + } + + public Notifier getTarget() { + return target; + } + + public void setTarget(Notifier newTarget) { + target = newTarget; + } + + public boolean isAdapterForType(Object type) { + return DefaultPluginConfigurationEditor.class.equals(type); + } + + public void notifyChanged(Notification notification) { + } +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/plugins/IPluginConfigurationExtension.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/plugins/IPluginConfigurationExtension.java new file mode 100644 index 00000000..6d0905ef --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/plugins/IPluginConfigurationExtension.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.plugins; + +import org.eclipse.m2e.editor.pom.MavenPomEditorPage; +import org.eclipse.m2e.model.edit.pom.Plugin; +import org.eclipse.swt.widgets.Composite; + +public interface IPluginConfigurationExtension { + public void setPlugin(Plugin plugin); + public void setPomEditor(MavenPomEditorPage editor); + public Composite createComposite(Composite parent); + public void cleanup(); +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/plugins/PluginExtensionDescriptor.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/plugins/PluginExtensionDescriptor.java new file mode 100644 index 00000000..3520034b --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/plugins/PluginExtensionDescriptor.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.plugins; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator; + +public class PluginExtensionDescriptor { + public static final String ARTIFACT_ID = "artifactId"; //$NON-NLS-1$ + public static final String GROUP_ID = "groupId"; //$NON-NLS-1$ + public static final String NAME = "name"; //$NON-NLS-1$ + + private String artifactId; + private String groupId; + private String name; + + private IPluginConfigurationExtension extension = null; + + public PluginExtensionDescriptor(IConfigurationElement element) { + artifactId = element.getAttribute(ARTIFACT_ID); + groupId = element.getAttribute(GROUP_ID); + name = element.getAttribute(NAME); + + Object o; + try { + o = element.createExecutableExtension(AbstractProjectConfigurator.ATTR_CLASS); + extension = (IPluginConfigurationExtension) o; + } catch(CoreException e) { + // TODO Auto-generated catch block + MavenLogger.log(e); + } + } + + public void setArtifactId(String artifactId) { + this.artifactId = artifactId; + } + public String getArtifactId() { + return artifactId; + } + public void setGroupId(String groupId) { + this.groupId = groupId; + } + public String getGroupId() { + return groupId; + } + + public String toString() { + return groupId + ':' + artifactId; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public IPluginConfigurationExtension getExtension() { + return extension; + } +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/BuildPage.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/BuildPage.java new file mode 100644 index 00000000..cbb5e643 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/BuildPage.java @@ -0,0 +1,604 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import static org.eclipse.m2e.editor.pom.FormUtils.nvl; +import static org.eclipse.m2e.editor.pom.FormUtils.setText; + +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.command.RemoveCommand; +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.Separator; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.window.Window; +import org.eclipse.m2e.core.actions.OpenPomAction; +import org.eclipse.m2e.core.actions.OpenUrlAction; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.index.IIndex; +import org.eclipse.m2e.core.index.IndexedArtifactFile; +import org.eclipse.m2e.core.ui.dialogs.MavenRepositorySearchDialog; +import org.eclipse.m2e.core.util.ProposalUtil; +import org.eclipse.m2e.core.util.search.Packaging; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.composites.BuildComposite; +import org.eclipse.m2e.editor.composites.DependencyLabelProvider; +import org.eclipse.m2e.editor.composites.ListEditorComposite; +import org.eclipse.m2e.editor.composites.ListEditorContentProvider; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.model.edit.pom.Build; +import org.eclipse.m2e.model.edit.pom.BuildBase; +import org.eclipse.m2e.model.edit.pom.Extension; +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.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.events.ExpansionAdapter; +import org.eclipse.ui.forms.events.ExpansionEvent; +import org.eclipse.ui.forms.events.HyperlinkAdapter; +import org.eclipse.ui.forms.events.HyperlinkEvent; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Hyperlink; +import org.eclipse.ui.forms.widgets.ScrolledForm; +import org.eclipse.ui.forms.widgets.Section; + +/** + * @author Eugene Kuleshov + */ +public class BuildPage extends MavenPomEditorPage { + + // controls + Text extensionGroupIdText; + Text sourceText; + Text outputText; + Text testSourceText; + Text testOutputText; + Text scriptsSourceText; + + ListEditorComposite<Extension> extensionsEditor; + BuildComposite buildComposite; + Text extensionArtifactIdText; + Text extensionVersionText; + Button extensionSelectButton; + Section foldersSection; + Section extensionsSection; + Section extensionDetailsSection; + + Extension currentExtension; + protected boolean expandingTopSections; + private Action extensionSelectAction; + private Action extensionAddAction; + private Action openWebPageAction; + + + public BuildPage(MavenPomEditor pomEditor) { + super(pomEditor, IMavenConstants.PLUGIN_ID + ".pom.build", Messages.BuildPage_title); //$NON-NLS-1$ + } + + protected void createFormContent(IManagedForm managedForm) { + FormToolkit toolkit = managedForm.getToolkit(); + ScrolledForm form = managedForm.getForm(); + form.setText(Messages.BuildPage_form); + // form.setExpandHorizontal(true); + + Composite body = form.getBody(); + GridLayout gridLayout = new GridLayout(3, true); + gridLayout.horizontalSpacing = 3; + body.setLayout(gridLayout); + toolkit.paintBordersFor(body); + + SashForm buildSash = new SashForm(body, SWT.NONE); + buildSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1)); + GridLayout buildSashLayout = new GridLayout(); + buildSashLayout.horizontalSpacing = 3; + buildSashLayout.marginWidth = 0; + buildSashLayout.marginHeight = 0; + buildSashLayout.numColumns = 3; + buildSash.setLayout(buildSashLayout); + toolkit.adapt(buildSash); + + createFoldersSection(buildSash, toolkit); + createExtensionsSection(buildSash, toolkit); + createExtensionDetailsSection(buildSash, toolkit); + + buildComposite = new BuildComposite(body, SWT.NONE); + GridData buildCompositeData = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1); + buildCompositeData.heightHint = 270; + buildComposite.setLayoutData(buildCompositeData); + toolkit.adapt(buildComposite); + +// form.pack(); + + super.createFormContent(managedForm); + } + + private void createFoldersSection(Composite buildSash, FormToolkit toolkit) { + foldersSection = toolkit.createSection(buildSash, // + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + foldersSection.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + foldersSection.setText(Messages.BuildPage_section_folders); + foldersSection.addExpansionListener(new ExpansionAdapter() { + public void expansionStateChanged(ExpansionEvent e) { + if(!expandingTopSections) { + expandingTopSections = true; + extensionsSection.setExpanded(foldersSection.isExpanded()); + extensionDetailsSection.setExpanded(foldersSection.isExpanded()); + expandingTopSections = false; + } + } + }); + + Composite composite = toolkit.createComposite(foldersSection, SWT.NONE); + GridLayout compositeLayout = new GridLayout(2, false); + compositeLayout.marginWidth = 2; + compositeLayout.marginHeight = 2; + composite.setLayout(compositeLayout); + toolkit.paintBordersFor(composite); + foldersSection.setClient(composite); + + toolkit.createLabel(composite, Messages.BuildPage_lblSources, SWT.NONE); + + sourceText = toolkit.createText(composite, null, SWT.NONE); + sourceText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + toolkit.createLabel(composite, Messages.BuildPage_lblOutput, SWT.NONE); + + outputText = toolkit.createText(composite, null, SWT.NONE); + outputText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + toolkit.createLabel(composite, Messages.BuildPage_lblTestSources, SWT.NONE); + + testSourceText = toolkit.createText(composite, null, SWT.NONE); + testSourceText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + toolkit.createLabel(composite, Messages.BuildPage_lblTestOutput, SWT.NONE); + + testOutputText = toolkit.createText(composite, null, SWT.NONE); + testOutputText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + toolkit.createLabel(composite, Messages.BuildPage_lblScripts, SWT.NONE); + + scriptsSourceText = toolkit.createText(composite, null, SWT.NONE); + scriptsSourceText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + } + + private void createExtensionsSection(Composite buildSash, FormToolkit toolkit) { + extensionsSection = toolkit.createSection(buildSash, // + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + extensionsSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + extensionsSection.setText(Messages.BuildPage_section_extensions); + extensionsSection.addExpansionListener(new ExpansionAdapter() { + public void expansionStateChanged(ExpansionEvent e) { + if(!expandingTopSections) { + expandingTopSections = true; + foldersSection.setExpanded(extensionsSection.isExpanded()); + extensionDetailsSection.setExpanded(extensionsSection.isExpanded()); + expandingTopSections = false; + } + } + }); + + extensionsEditor = new ListEditorComposite<Extension>(extensionsSection, SWT.NONE); + toolkit.paintBordersFor(extensionsEditor); + toolkit.adapt(extensionsEditor); + extensionsSection.setClient(extensionsEditor); + + final DependencyLabelProvider labelProvider = new DependencyLabelProvider(); + extensionsEditor.setLabelProvider(labelProvider); + extensionsEditor.setContentProvider(new ListEditorContentProvider<Extension>()); + + extensionsEditor.addSelectionListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + List<Extension> selection = extensionsEditor.getSelection(); + updateExtensionDetails(selection.size()==1 ? selection.get(0) : null); + } + }); + + extensionsEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + createExtension(null, null, null); + } + }); + + extensionsEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = getEditingDomain(); + + List<Extension> list = extensionsEditor.getSelection(); + for(Extension extension : list) { + Command removeCommand = RemoveCommand.create(editingDomain, model.getBuild(), // + POM_PACKAGE.getBuild_Extensions(), extension); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + updateExtensionDetails(null); + } + }); + + extensionAddAction = new Action(Messages.BuildPage_action_addExtension, MavenEditorImages.ADD_ARTIFACT) { + public void run() { + // XXX calculate list available extensions + Set<ArtifactKey> artifacts = Collections.emptySet(); + MavenRepositorySearchDialog dialog = new MavenRepositorySearchDialog(getEditorSite().getShell(), // + Messages.BuildPage_searchDialog_addExtension, IIndex.SEARCH_ARTIFACT, artifacts); + if(dialog.open() == Window.OK) { + IndexedArtifactFile af = (IndexedArtifactFile) dialog.getFirstResult(); + if(af != null) { + createExtension(af.group, af.artifact, af.version); + } + } + } + }; + extensionAddAction.setEnabled(false); + + ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); + toolBarManager.add(extensionAddAction); + toolBarManager.add(new Separator()); + + toolBarManager.add(new Action(Messages.BuildPage_action_showGroupId, MavenEditorImages.SHOW_GROUP) { + { + setChecked(true); + } + public int getStyle() { + return AS_CHECK_BOX; + } + public void run() { + labelProvider.setShowGroupId(isChecked()); + extensionsEditor.getViewer().refresh(); + } + }); + + Composite toolbarComposite = toolkit.createComposite(extensionsSection); + GridLayout toolbarLayout = new GridLayout(1, true); + toolbarLayout.marginHeight = 0; + toolbarLayout.marginWidth = 0; + toolbarComposite.setLayout(toolbarLayout); + toolbarComposite.setBackground(null); + + toolBarManager.createControl(toolbarComposite); + extensionsSection.setTextClient(toolbarComposite); + } + + private void createExtensionDetailsSection(Composite buildSash, FormToolkit toolkit) { + extensionDetailsSection = toolkit.createSection(buildSash, // + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + extensionDetailsSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + extensionDetailsSection.setText(Messages.BuildPage_section_extensionDetails); + extensionDetailsSection.addExpansionListener(new ExpansionAdapter() { + public void expansionStateChanged(ExpansionEvent e) { + if(!expandingTopSections) { + expandingTopSections = true; + foldersSection.setExpanded(extensionDetailsSection.isExpanded()); + extensionsSection.setExpanded(extensionDetailsSection.isExpanded()); + expandingTopSections = false; + } + } + }); + + Composite extensionDetialsComposite = toolkit.createComposite(extensionDetailsSection, SWT.NONE); + GridLayout extensionDetialsCompositeLayout = new GridLayout(2, false); + extensionDetialsCompositeLayout.marginWidth = 2; + extensionDetialsCompositeLayout.marginHeight = 2; + extensionDetialsComposite.setLayout(extensionDetialsCompositeLayout); + toolkit.paintBordersFor(extensionDetialsComposite); + extensionDetailsSection.setClient(extensionDetialsComposite); + + toolkit.createLabel(extensionDetialsComposite, Messages.BuildPage_lblGroupId); + + extensionGroupIdText = toolkit.createText(extensionDetialsComposite, null, SWT.FLAT); + extensionGroupIdText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + extensionGroupIdText.setData("name", "extensionGroupIdText"); //$NON-NLS-1$ //$NON-NLS-2$ + ProposalUtil.addGroupIdProposal(getProject(), extensionGroupIdText, Packaging.ALL); + + Hyperlink extensionArtifactIdHyperlink = toolkit.createHyperlink(extensionDetialsComposite, Messages.BuildPage_lblArtifactId, SWT.NONE); + extensionArtifactIdHyperlink.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + final String groupId = extensionGroupIdText.getText(); + final String artifactId = extensionArtifactIdText.getText(); + final String version = extensionVersionText.getText(); + new Job("Opening " + groupId + ":" + artifactId + ":" + version) { + protected IStatus run(IProgressMonitor arg0) { + OpenPomAction.openEditor(groupId, artifactId, version, null); + return Status.OK_STATUS; + } + }.schedule(); + } + }); + + extensionArtifactIdText = toolkit.createText(extensionDetialsComposite, null, SWT.FLAT); + extensionArtifactIdText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + extensionArtifactIdText.setData("name", "extensionArtifactIdText"); //$NON-NLS-1$ //$NON-NLS-2$ + ProposalUtil.addArtifactIdProposal(getProject(), extensionGroupIdText, extensionArtifactIdText, Packaging.ALL); + + toolkit.createLabel(extensionDetialsComposite, Messages.BuildPage_lblVersion); + + extensionVersionText = toolkit.createText(extensionDetialsComposite, null, SWT.FLAT); + extensionVersionText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + extensionVersionText.setData("name", "extensionVersionText"); //$NON-NLS-1$ //$NON-NLS-2$ + ProposalUtil.addVersionProposal(getProject(), extensionGroupIdText, extensionArtifactIdText, extensionVersionText, Packaging.ALL); + extensionDetialsComposite.setTabList(new Control[] {extensionGroupIdText, extensionArtifactIdText, extensionVersionText}); + +// extensionSelectButton = toolkit.createButton(extensionDetialsComposite, "Select...", SWT.FLAT); +// extensionSelectButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2, 1)); +// extensionSelectButton.addSelectionListener(new SelectionAdapter() { +// public void widgetSelected(SelectionEvent e) { +// // TODO calculate current list of artifacts for the project +// Set<Dependency> artifacts = Collections.emptySet(); +// MavenRepositorySearchDialog dialog = new MavenRepositorySearchDialog(getEditorSite().getShell(), // +// "Add Dependency", IndexManager.SEARCH_ARTIFACT, artifacts); +// if(dialog.open() == Window.OK) { +// IndexedArtifactFile af = (IndexedArtifactFile) dialog.getFirstResult(); +// if(af != null) { +// extensionGroupIdText.setText(nvl(af.group)); +// extensionArtifactIdText.setText(nvl(af.artifact)); +// extensionVersionText.setText(nvl(af.version)); +// } +// } +// } +// }); + + extensionSelectAction = new Action(Messages.BuildPage_action_selectExtension, MavenEditorImages.SELECT_ARTIFACT) { + public void run() { + // XXX calculate list available extensions + Set<ArtifactKey> artifacts = Collections.emptySet(); + MavenRepositorySearchDialog dialog = new MavenRepositorySearchDialog(getEditorSite().getShell(), // + Messages.BuildPage_searchDialog_selectExtension, IIndex.SEARCH_ARTIFACT, artifacts); + if(dialog.open() == Window.OK) { + IndexedArtifactFile af = (IndexedArtifactFile) dialog.getFirstResult(); + if(af != null) { + extensionGroupIdText.setText(nvl(af.group)); + extensionArtifactIdText.setText(nvl(af.artifact)); + extensionVersionText.setText(nvl(af.version)); + } + } + } + }; + extensionSelectAction.setEnabled(false); + + openWebPageAction = new Action(Messages.BuildPage_action_openWeb, MavenEditorImages.WEB_PAGE) { + public void run() { + final String groupId = extensionGroupIdText.getText(); + final String artifactId = extensionArtifactIdText.getText(); + final String version = extensionVersionText.getText(); + new Job("Opening " + groupId + ":" + artifactId + ":" + version) { + protected IStatus run(IProgressMonitor monitor) { + OpenUrlAction.openBrowser(OpenUrlAction.ID_PROJECT, groupId, artifactId, version, monitor); + return Status.OK_STATUS; + } + }.schedule(); + + } + }; + openWebPageAction.setEnabled(false); + + ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); + toolBarManager.add(extensionSelectAction); + toolBarManager.add(new Separator()); + toolBarManager.add(openWebPageAction); + + Composite toolbarComposite = toolkit.createComposite(extensionDetailsSection); + GridLayout toolbarLayout = new GridLayout(1, true); + toolbarLayout.marginHeight = 0; + toolbarLayout.marginWidth = 0; + toolbarComposite.setLayout(toolbarLayout); + toolbarComposite.setBackground(null); + + toolBarManager.createControl(toolbarComposite); + extensionDetailsSection.setTextClient(toolbarComposite); + } + + public void loadData() { + loadBuild(); + loadBuildBase(); + + extensionsEditor.setReadOnly(isReadOnly()); + + updateExtensionDetails(null); + } + + void updateExtensionDetails(Extension extension) { + currentExtension = extension; + + removeNotifyListener(extensionGroupIdText); + removeNotifyListener(extensionArtifactIdText); + removeNotifyListener(extensionVersionText); + + if(extension==null) { + FormUtils.setEnabled(extensionDetailsSection, false); + extensionSelectAction.setEnabled(false); + openWebPageAction.setEnabled(false); + + setText(extensionGroupIdText, ""); //$NON-NLS-1$ + setText(extensionArtifactIdText, ""); //$NON-NLS-1$ + setText(extensionVersionText, ""); //$NON-NLS-1$ + + return; + } + + FormUtils.setEnabled(extensionDetailsSection, true); + FormUtils.setReadonly(extensionDetailsSection, isReadOnly()); + extensionSelectAction.setEnabled(!isReadOnly()); + openWebPageAction.setEnabled(true); + + setText(extensionGroupIdText, extension.getGroupId()); + setText(extensionArtifactIdText, extension.getArtifactId()); + setText(extensionVersionText, extension.getVersion()); + + ValueProvider<Extension> extensionProvider = new ValueProvider.DefaultValueProvider<Extension>(extension); + setModifyListener(extensionGroupIdText, extensionProvider, POM_PACKAGE.getExtension_GroupId(), ""); //$NON-NLS-1$ + setModifyListener(extensionArtifactIdText, extensionProvider, POM_PACKAGE.getExtension_ArtifactId(), ""); //$NON-NLS-1$ + setModifyListener(extensionVersionText, extensionProvider, POM_PACKAGE.getExtension_Version(), ""); //$NON-NLS-1$ + + registerListeners(); + } + + private void loadBuild() { + removeNotifyListener(sourceText); + removeNotifyListener(outputText); + removeNotifyListener(testSourceText); + removeNotifyListener(testOutputText); + removeNotifyListener(scriptsSourceText); + + Build build = model == null ? null : model.getBuild(); + if(build==null) { + setText(sourceText, ""); //$NON-NLS-1$ + setText(outputText, ""); //$NON-NLS-1$ + setText(testSourceText, ""); //$NON-NLS-1$ + setText(testOutputText, ""); //$NON-NLS-1$ + setText(scriptsSourceText, ""); //$NON-NLS-1$ + + extensionsEditor.setInput(null); + + } else { + setText(sourceText, build.getSourceDirectory()); + setText(outputText, build.getOutputDirectory()); + setText(testSourceText, build.getTestSourceDirectory()); + setText(testOutputText, build.getTestOutputDirectory()); + setText(scriptsSourceText, build.getScriptSourceDirectory()); + + extensionsEditor.setInput(build.getExtensions() == null ? null : build.getExtensions()); + } + + FormUtils.setReadonly(foldersSection, isReadOnly()); + FormUtils.setReadonly(extensionsSection, isReadOnly()); + extensionAddAction.setEnabled(!isReadOnly()); + + updateExtensionDetails(null); + + ValueProvider<Build> modelProvider = new ValueProvider.ParentValueProvider<Build>(sourceText, outputText, testSourceText, testOutputText, scriptsSourceText) { + public Build getValue() { + return model.getBuild(); + } + public Build create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + Build build = model.getBuild(); + if(build==null) { + build = PomFactory.eINSTANCE.createBuild(); + Command command = SetCommand.create(editingDomain, model, POM_PACKAGE.getModel_Build(), build); + compoundCommand.append(command); + } + return build; + } + }; + setModifyListener(sourceText, modelProvider, POM_PACKAGE.getBuild_SourceDirectory(), ""); //$NON-NLS-1$ + setModifyListener(outputText, modelProvider, POM_PACKAGE.getBuild_OutputDirectory(), ""); //$NON-NLS-1$ + setModifyListener(testSourceText, modelProvider, POM_PACKAGE.getBuild_TestSourceDirectory(), ""); //$NON-NLS-1$ + setModifyListener(testOutputText, modelProvider, POM_PACKAGE.getBuild_TestOutputDirectory(), ""); //$NON-NLS-1$ + setModifyListener(scriptsSourceText, modelProvider, POM_PACKAGE.getBuild_ScriptSourceDirectory(), ""); //$NON-NLS-1$ + + loadBuildBase(); + } + + private void loadBuildBase() { + ValueProvider<BuildBase> buildProvider = new ValueProvider<BuildBase>() { + public Build getValue() { + return model.getBuild(); + } + public Build create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + Build build = PomFactory.eINSTANCE.createBuild(); + Command command = SetCommand.create(editingDomain, model, POM_PACKAGE.getModel_Build(), build); + compoundCommand.append(command); + return build; + } + }; + buildComposite.loadData(this, buildProvider); + } + + protected void doUpdate(Notification notification){ + EObject object = (EObject) notification.getNotifier(); + Object feature = notification.getFeature(); + if (object instanceof Build) { + loadBuild(); + } + if (object instanceof BuildBase) { + loadBuildBase(); + } + + if (feature == PomPackage.Literals.BUILD__EXTENSIONS) { + extensionsEditor.refresh(); + } + + if (object instanceof Extension) { + extensionsEditor.refresh(); + if(currentExtension==object) { + updateExtensionDetails(currentExtension); + } + } + + if(buildComposite!=null) { + buildComposite.updateView(this, notification); + } + } + + public void updateView(final Notification notification) { + Display.getDefault().asyncExec(new Runnable(){ + public void run(){ + doUpdate(notification); + } + }); + } + + void createExtension(String groupId, String artifactId, String version) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = getEditingDomain(); + + Build build = model.getBuild(); + if(build == null) { + build = PomFactory.eINSTANCE.createBuild(); + Command command = SetCommand.create(editingDomain, model, POM_PACKAGE.getModel_Build(), build); + compoundCommand.append(command); + } + + Extension extension = PomFactory.eINSTANCE.createExtension(); + extension.setGroupId(groupId); + extension.setArtifactId(artifactId); + extension.setVersion(version); + + Command addCommand = AddCommand.create(editingDomain, build, // + POM_PACKAGE.getBuild_Extensions(), extension); + compoundCommand.append(addCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + + extensionsEditor.setSelection(Collections.singletonList(extension)); + extensionGroupIdText.setFocus(); + } +} + diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/DependenciesPage.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/DependenciesPage.java new file mode 100644 index 00000000..08347b0c --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/DependenciesPage.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.editor.composites.DependenciesComposite; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.model.edit.pom.DependencyManagement; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.ScrolledForm; + +/** + * @author Eugene Kuleshov + */ +public class DependenciesPage extends MavenPomEditorPage { + + private DependenciesComposite dependenciesComposite; + private SearchControl searchControl; + + public DependenciesPage(MavenPomEditor pomEditor) { + super(pomEditor, IMavenConstants.PLUGIN_ID + ".pom.dependencies", Messages.DependenciesPage_title); //$NON-NLS-1$ + } + + public void dispose() { + if(dependenciesComposite!=null) { + dependenciesComposite.dispose(); + } + super.dispose(); + } + + public void setActive(boolean active) { + super.setActive(active); + if(active) { + dependenciesComposite.setSearchControl(searchControl); + searchControl.getSearchText().setEditable(true); + } + } + + protected void createFormContent(IManagedForm managedForm) { + FormToolkit toolkit = managedForm.getToolkit(); + + ScrolledForm form = managedForm.getForm(); + form.setText(Messages.DependenciesPage_form); + + form.getBody().setLayout(new GridLayout(1, true)); + + dependenciesComposite = new DependenciesComposite(form.getBody(), this, SWT.NONE, pomEditor); + dependenciesComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + toolkit.adapt(dependenciesComposite); + + searchControl = new SearchControl(Messages.DependenciesPage_find, managedForm); + + IToolBarManager pageToolBarManager = form.getForm().getToolBarManager(); + pageToolBarManager.add(searchControl); + pageToolBarManager.add(new Separator()); + + form.updateToolBar(); + +// form.pack(); + + super.createFormContent(managedForm); + } + + public void loadData() { + + + ValueProvider<DependencyManagement> dependencyManagementProvider = new ValueProvider<DependencyManagement>() { + public DependencyManagement getValue() { + return model.getDependencyManagement(); + } + + public DependencyManagement create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + DependencyManagement management = model.getDependencyManagement(); + if(management==null) { + management = PomFactory.eINSTANCE.createDependencyManagement(); + Command command = SetCommand.create(editingDomain, model, // + POM_PACKAGE.getModel_DependencyManagement(), management); + compoundCommand.append(command); + } + + return management; + } + }; + + dependenciesComposite.loadData(model, dependencyManagementProvider); + } + + public void updateView(final Notification notification) { + Display.getDefault().asyncExec(new Runnable(){ + public void run(){ + dependenciesComposite.updateView(DependenciesPage.this, notification); + } + }); + + } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/DependencyTreePage.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/DependencyTreePage.java new file mode 100644 index 00000000..a3290031 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/DependencyTreePage.java @@ -0,0 +1,1063 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.project.MavenProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.ActionContributionItem; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuCreator; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.viewers.IColorProvider; +import org.eclipse.jface.viewers.IOpenListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.OpenEvent; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.actions.OpenPomAction; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.project.IMavenProjectChangedListener; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectChangedEvent; +import org.eclipse.m2e.core.project.MavenProjectManager; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.editor.FormPage; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.ScrolledForm; +import org.eclipse.ui.forms.widgets.Section; +import org.eclipse.ui.progress.UIJob; +import org.sonatype.aether.graph.DependencyNode; +import org.sonatype.aether.graph.DependencyVisitor; + + +/** + * @author Eugene Kuleshov + * @author Benjamin Bentmann + */ +public class DependencyTreePage extends FormPage implements IMavenProjectChangedListener, IPomFileChangedListener { + + protected static final Object[] EMPTY = new Object[0]; + + final MavenPomEditor pomEditor; + + TreeViewer treeViewer; + + TableViewer listViewer; + + SearchControl searchControl; + + SearchMatcher searchMatcher; + + DependencyFilter searchFilter; + + ListSelectionFilter listSelectionFilter; + + ViewerFilter currentFilter; + + ArrayList<DependencyNode> dependencyNodes = new ArrayList<DependencyNode>(); + + Color searchHighlightColor; + + MavenProject mavenProject; + + boolean isSettingSelection = false; + + Action hierarchyFilterAction; + + private Job dataLoadingJob; + + String currentClasspath = Artifact.SCOPE_TEST; + + public DependencyTreePage(MavenPomEditor pomEditor) { + super(pomEditor, IMavenConstants.PLUGIN_ID + ".pom.dependencyTree", Messages.DependencyTreePage_title); //$NON-NLS-1$ + this.pomEditor = pomEditor; + } + + protected void createFormContent(IManagedForm managedForm) { + MavenPlugin.getDefault().getMavenProjectManager().addMavenProjectChangedListener(this); + + FormToolkit formToolkit = managedForm.getToolkit(); + + searchHighlightColor = new Color(Display.getDefault(), 242, 218, 170); + + ScrolledForm form = managedForm.getForm(); + form.setText(formatFormTitle()); + form.setExpandHorizontal(true); + form.setExpandVertical(true); + + Composite body = form.getBody(); + body.setLayout(new FillLayout()); + + SashForm sashForm = new SashForm(body, SWT.NONE); + formToolkit.adapt(sashForm); + formToolkit.adapt(sashForm, true, true); + + createHierarchySection(sashForm, formToolkit); + + createListSection(sashForm, formToolkit); + + sashForm.setWeights(new int[] {1, 1}); + + createSearchBar(managedForm); + + // compatibility proxy to support Eclipse 3.2 + FormUtils.decorateHeader(managedForm.getToolkit(), form.getForm()); + + initPopupMenu(treeViewer, ".tree"); //$NON-NLS-1$ + initPopupMenu(listViewer, ".list"); //$NON-NLS-1$ + + loadData(false); + } + + private void initPopupMenu(Viewer viewer, String id) { + MenuManager menuMgr = new MenuManager("#PopupMenu-" + id); //$NON-NLS-1$ + menuMgr.setRemoveAllWhenShown(true); + + Menu menu = menuMgr.createContextMenu(viewer.getControl()); + + viewer.getControl().setMenu(menu); + + getEditorSite().registerContextMenu(MavenPomEditor.EDITOR_ID + id, menuMgr, viewer, false); + } + + String formatFormTitle() { + return NLS.bind(Messages.DependencyTreePage_form_title, currentClasspath); + } + + void loadData(final boolean force) { + // form.setMessage() forces the panel layout, which messes up the viewers + // (e.g. long entries in the tree cause it to expand horizontally so much + // doesn't fit into the editor anymore). Clearing the input in the viewers + // helps to ensure they won't change the size when the message is set. + treeViewer.setInput(null); + listViewer.setInput(null); + FormUtils.setMessage(getManagedForm().getForm(), Messages.DependencyTreePage_message_resolving, IMessageProvider.WARNING); + + dataLoadingJob = new Job(Messages.DependencyTreePage_job_loading) { + protected IStatus run(IProgressMonitor monitor) { + try { + mavenProject = pomEditor.readMavenProject(force, monitor); + if(mavenProject == null){ + MavenLogger.log("Unable to read maven project. Dependencies not updated.", null); //$NON-NLS-1$ + return Status.CANCEL_STATUS; + } + + final DependencyNode dependencyNode = pomEditor.readDependencyTree(force, currentClasspath, monitor); + if(dependencyNode == null) { + return Status.CANCEL_STATUS; + } + dependencyNode.accept(new DependencyVisitor() { + public boolean visitEnter(DependencyNode node) { + if(node.getDependency() != null) { + dependencyNodes.add(node); + } + return true; + } + + public boolean visitLeave(DependencyNode dependencynode) { + return true; + } + }); + + getPartControl().getDisplay().syncExec(new Runnable() { + public void run() { + FormUtils.setMessage(getManagedForm().getForm(), null, IMessageProvider.NONE); + treeViewer.setInput(dependencyNode); + treeViewer.expandAll(); + listViewer.setInput(mavenProject); + } + }); + } catch(final CoreException ex) { + MavenLogger.log(ex); + getPartControl().getDisplay().asyncExec(new Runnable() { + public void run() { + FormUtils.setMessage(getManagedForm().getForm(), ex.getMessage(), IMessageProvider.ERROR); + } + }); + } + + return Status.OK_STATUS; + } + }; + dataLoadingJob.schedule(); + } + + private void createHierarchySection(Composite sashForm, FormToolkit formToolkit) { + Composite hierarchyComposite = formToolkit.createComposite(sashForm, SWT.NONE); + hierarchyComposite.setLayout(new GridLayout()); + + Section hierarchySection = formToolkit.createSection(hierarchyComposite, ExpandableComposite.TITLE_BAR); + hierarchySection.marginHeight = 1; + GridData gd_hierarchySection = new GridData(SWT.FILL, SWT.FILL, true, true); + gd_hierarchySection.widthHint = 100; + gd_hierarchySection.minimumWidth = 100; + hierarchySection.setLayoutData(gd_hierarchySection); + hierarchySection.setText(Messages.DependencyTreePage_section_hierarchy); + formToolkit.paintBordersFor(hierarchySection); + + Tree tree = formToolkit.createTree(hierarchySection, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI); + hierarchySection.setClient(tree); + + treeViewer = new TreeViewer(tree); + treeViewer.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.TRUE); + + DependencyTreeLabelProvider treeLabelProvider = new DependencyTreeLabelProvider(); + treeViewer.setContentProvider(new DependencyTreeContentProvider()); + treeViewer.setLabelProvider(treeLabelProvider); + + treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + if(!isSettingSelection) { + isSettingSelection = true; + IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); + selectListElements(new DependencyNodeMatcher(selection)); + isSettingSelection = false; + } + } + }); + + treeViewer.addOpenListener(new IOpenListener() { + public void open(OpenEvent event) { + IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); + for(Iterator<?> it = selection.iterator(); it.hasNext();) { + Object o = it.next(); + if(o instanceof DependencyNode) { + org.sonatype.aether.artifact.Artifact a = ((DependencyNode) o).getDependency().getArtifact(); + OpenPomAction.openEditor(a.getGroupId(), a.getArtifactId(), a.getVersion(), null); + } + } + } + }); + + createHierarchyToolbar(hierarchySection, treeLabelProvider, formToolkit); + } + + private void createHierarchyToolbar(Section hierarchySection, final DependencyTreeLabelProvider treeLabelProvider, + FormToolkit formToolkit) { + ToolBarManager hiearchyToolBarManager = new ToolBarManager(SWT.FLAT); + + hiearchyToolBarManager.add(new Action(Messages.DependencyTreePage_action_collapseAll, MavenEditorImages.COLLAPSE_ALL) { + public void run() { + treeViewer.collapseAll(); + } + }); + + hiearchyToolBarManager.add(new Action(Messages.DependencyTreePage_action_expandAll, MavenEditorImages.EXPAND_ALL) { + public void run() { + treeViewer.expandAll(); + } + }); + + hiearchyToolBarManager.add(new Separator()); + + hiearchyToolBarManager.add(new Action(Messages.DependencyTreePage_action_sort, MavenEditorImages.SORT) { + public int getStyle() { + return AS_CHECK_BOX; + } + + public void run() { + if(treeViewer.getComparator() == null) { + treeViewer.setComparator(new ViewerComparator()); + } else { + treeViewer.setComparator(null); + } + } + }); + + hiearchyToolBarManager.add(new Action(Messages.DependencyTreePage_action_showGroupId, MavenEditorImages.SHOW_GROUP) { + public int getStyle() { + return AS_CHECK_BOX; + } + + public void run() { + treeLabelProvider.setShowGroupId(isChecked()); + treeViewer.refresh(); + } + }); + + hierarchyFilterAction = new Action(Messages.DependencyTreePage_action_filterSearch, MavenEditorImages.FILTER) { + public int getStyle() { + return AS_CHECK_BOX; + } + + public void run() { + if(isChecked()) { + setTreeFilter(currentFilter, true); +// treeViewer.setFilters(new ViewerFilter[] {searchFilter, listSelectionFilter}); + } else { + treeViewer.removeFilter(searchFilter); + } + treeViewer.refresh(); + treeViewer.expandAll(); + } + }; + hierarchyFilterAction.setChecked(true); + hiearchyToolBarManager.add(hierarchyFilterAction); + + Composite toolbarComposite = formToolkit.createComposite(hierarchySection); + toolbarComposite.setBackground(null); + RowLayout rowLayout = new RowLayout(); + rowLayout.wrap = false; + rowLayout.marginRight = 0; + rowLayout.marginLeft = 0; + rowLayout.marginTop = 0; + rowLayout.marginBottom = 0; + toolbarComposite.setLayout(rowLayout); + + hiearchyToolBarManager.createControl(toolbarComposite); + hierarchySection.setTextClient(toolbarComposite); + } + + private void createListSection(SashForm sashForm, FormToolkit formToolkit) { + Composite listComposite = formToolkit.createComposite(sashForm, SWT.NONE); + listComposite.setLayout(new GridLayout()); + + Section listSection = formToolkit.createSection(listComposite, ExpandableComposite.TITLE_BAR); + listSection.marginHeight = 1; + GridData gd_listSection = new GridData(SWT.FILL, SWT.FILL, true, true); + gd_listSection.widthHint = 100; + gd_listSection.minimumWidth = 100; + listSection.setLayoutData(gd_listSection); + listSection.setText(Messages.DependencyTreePage_section_resolvedDeps); + formToolkit.paintBordersFor(listSection); + + final DependencyListLabelProvider listLabelProvider = new DependencyListLabelProvider(); + + Table table = formToolkit.createTable(listSection, SWT.FLAT | SWT.MULTI); + listSection.setClient(table); + + // listViewer = new TableViewer(listSection, SWT.FLAT | SWT.MULTI); + listViewer = new TableViewer(table); + listViewer.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.TRUE); + listViewer.setContentProvider(new DependencyListContentProvider()); + listViewer.setLabelProvider(listLabelProvider); + listViewer.setComparator(new ViewerComparator()); // by default is sorted + + listSelectionFilter = new ListSelectionFilter(); + listViewer.addSelectionChangedListener(listSelectionFilter); + listViewer.getTable().addFocusListener(listSelectionFilter); + + listViewer.addOpenListener(new IOpenListener() { + public void open(OpenEvent event) { + IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection(); + for(Iterator<?> it = selection.iterator(); it.hasNext();) { + Object o = it.next(); + if(o instanceof Artifact) { + Artifact a = (Artifact) o; + OpenPomAction.openEditor(a.getGroupId(), a.getArtifactId(), a.getVersion(), null); + } + } + } + }); + + createListToolbar(listSection, listLabelProvider, formToolkit); + + } + + private void createListToolbar(Section listSection, final DependencyListLabelProvider listLabelProvider, + FormToolkit formToolkit) { + ToolBarManager listToolBarManager = new ToolBarManager(SWT.FLAT); + + listToolBarManager.add(new Action(Messages.DependencyTreePage_action_sort, MavenEditorImages.SORT) { + { + setChecked(true); + } + + public int getStyle() { + return AS_CHECK_BOX; + } + + public void run() { + if(listViewer.getComparator() == null) { + listViewer.setComparator(new ViewerComparator()); + } else { + listViewer.setComparator(null); + } + } + }); + + listToolBarManager.add(new Action(Messages.DependencyTreePage_action_showGroupId, MavenEditorImages.SHOW_GROUP) { + public int getStyle() { + return AS_CHECK_BOX; + } + + public void run() { + listLabelProvider.setShowGroupId(isChecked()); + listViewer.refresh(); + } + }); + + listToolBarManager.add(new Action(Messages.DependencyTreePage_action_filter, MavenEditorImages.FILTER) { + public int getStyle() { + return AS_CHECK_BOX; + } + + public void run() { + if(listViewer.getFilters() == null || listViewer.getFilters().length == 0) { + listViewer.addFilter(searchFilter); + } else { + listViewer.removeFilter(searchFilter); + } + } + }); + + Composite toolbarComposite = formToolkit.createComposite(listSection); + toolbarComposite.setBackground(null); + RowLayout rowLayout = new RowLayout(); + rowLayout.wrap = false; + rowLayout.marginRight = 0; + rowLayout.marginLeft = 0; + rowLayout.marginTop = 0; + rowLayout.marginBottom = 0; + toolbarComposite.setLayout(rowLayout); + + listToolBarManager.createControl(toolbarComposite); + listSection.setTextClient(toolbarComposite); + } + + private void createSearchBar(IManagedForm managedForm) { + searchControl = new SearchControl(Messages.DependencyTreePage_find, managedForm); + searchMatcher = new SearchMatcher(searchControl); + searchFilter = new DependencyFilter(new SearchMatcher(searchControl)); + treeViewer.addFilter(searchFilter); // by default is filtered + + ScrolledForm form = managedForm.getForm(); + + IToolBarManager toolBarManager = form.getForm().getToolBarManager(); + toolBarManager.add(searchControl); + + class ClasspathDropdown extends Action implements IMenuCreator { + private Menu menu; + + public ClasspathDropdown() { + setText(Messages.DependencyTreePage_classpath); + setImageDescriptor(MavenEditorImages.SCOPE); + setMenuCreator(this); + } + + public Menu getMenu(Menu parent) { + return null; + } + + public Menu getMenu(Control parent) { + if (menu != null) { + menu.dispose(); + } + + menu = new Menu(parent); + addToMenu(menu, Messages.DependencyTreePage_scope_all, Artifact.SCOPE_TEST, currentClasspath); + addToMenu(menu, Messages.DependencyTreePage_scope_comp_runtime, Artifact.SCOPE_COMPILE_PLUS_RUNTIME, currentClasspath); + addToMenu(menu, Messages.DependencyTreePage_scope_compile, Artifact.SCOPE_COMPILE, currentClasspath); + addToMenu(menu, Messages.DependencyTreePage_scope_runtime, Artifact.SCOPE_RUNTIME, currentClasspath); + return menu; + } + + protected void addToMenu(Menu parent, String text, String scope, String currentScope) { + ClasspathAction action = new ClasspathAction(text, scope); + action.setChecked(scope.equals(currentScope)); + new ActionContributionItem(action).fill(parent, -1); + } + + public void dispose() { + if (menu != null) { + menu.dispose(); + menu = null; + } + } + } + toolBarManager.add(new ClasspathDropdown()); + + toolBarManager.add(new Separator()); + toolBarManager.add(new Action(Messages.DependencyTreePage_action_refresh, MavenEditorImages.REFRESH) { + public void run() { + loadData(true); + } + }); + + form.updateToolBar(); + + searchControl.getSearchText().addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent e) { + isSettingSelection = true; + selectListElements(searchMatcher); + selectTreeElements(searchMatcher); + setTreeFilter(searchFilter, false); + isSettingSelection = false; + } + }); + + searchControl.getSearchText().addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + isSettingSelection = true; + selectListElements(searchMatcher); + selectTreeElements(searchMatcher); + setTreeFilter(searchFilter, false); + isSettingSelection = false; + } + }); + } + + protected void setTreeFilter(ViewerFilter filter, boolean force) { + currentFilter = filter; + if(filter != null && (force || (treeViewer.getFilters().length > 0 && treeViewer.getFilters()[0] != filter))) { + treeViewer.addFilter(filter); + } + } + + protected void selectListElements(Matcher matcher) { + DependencyListLabelProvider listLabelProvider = (DependencyListLabelProvider) listViewer.getLabelProvider(); + listLabelProvider.setMatcher(matcher); + listViewer.refresh(); + + if(!matcher.isEmpty() && mavenProject != null) { + Set<Artifact> projectArtifacts = mavenProject.getArtifacts(); + for(Artifact a : projectArtifacts) { + if(matcher.isMatchingArtifact(a.getGroupId(), a.getArtifactId())) { + listViewer.reveal(a); + break; + } + } + } + } + + void selectTreeElements(Matcher matcher) { + DependencyTreeLabelProvider treeLabelProvider = (DependencyTreeLabelProvider) treeViewer.getLabelProvider(); + treeLabelProvider.setMatcher(matcher); + treeViewer.refresh(); + treeViewer.expandAll(); + + if(!matcher.isEmpty()) { + for(DependencyNode node : dependencyNodes) { + org.sonatype.aether.artifact.Artifact a = node.getDependency().getArtifact(); + if(matcher.isMatchingArtifact(a.getGroupId(), a.getGroupId())) { + treeViewer.reveal(node); + break; + } + } + } + } + + static class DependencyFilter extends ViewerFilter { + protected Matcher matcher; + + public DependencyFilter(Matcher matcher) { + this.matcher = matcher; + } + + public boolean select(Viewer viewer, Object parentElement, Object element) { + if(matcher != null && !matcher.isEmpty()) { + // matcher = new TextMatcher(searchControl.getSearchText().getText()); + if(element instanceof Artifact) { + Artifact a = (Artifact) element; + return matcher.isMatchingArtifact(a.getGroupId(), a.getArtifactId()); + + } else if(element instanceof DependencyNode) { + DependencyNode node = (DependencyNode) element; + org.sonatype.aether.artifact.Artifact a = node.getDependency().getArtifact(); + if(matcher.isMatchingArtifact(a.getGroupId(), a.getArtifactId())) { + return true; + } + + class ChildMatcher implements DependencyVisitor { + protected boolean foundMatch = false; + + public boolean visitEnter(DependencyNode node) { + org.sonatype.aether.artifact.Artifact a = node.getDependency().getArtifact(); + if(matcher.isMatchingArtifact(a.getGroupId(), a.getArtifactId())) { + foundMatch = true; + return false; + } + return true; + } + + public boolean visitLeave(DependencyNode node) { + return true; + } + } + ; + + ChildMatcher childMatcher = new ChildMatcher(); + node.accept(childMatcher); + return childMatcher.foundMatch; + } + } + return true; + } + + } + + class ListSelectionFilter extends DependencyFilter implements ISelectionChangedListener, FocusListener { + + public ListSelectionFilter() { + super(null); // no filter by default + } + + // ISelectionChangedListener + + public void selectionChanged(SelectionChangedEvent event) { + if(!isSettingSelection) { + isSettingSelection = true; + IStructuredSelection selection = (IStructuredSelection) listViewer.getSelection(); + matcher = new ArtifactMatcher(selection); + selectTreeElements(matcher); + setTreeFilter(this, false); + isSettingSelection = false; + } + } + + // FocusListener + + public void focusGained(FocusEvent e) { + if(hierarchyFilterAction.isChecked()) { + setTreeFilter(this, false); +// treeViewer.addFilter(this); + } + } + + public void focusLost(FocusEvent e) { +// treeViewer.removeFilter(this); + matcher = null; + } + } + + final class DependencyTreeContentProvider implements ITreeContentProvider { + + public Object[] getElements(Object input) { + return getChildren(input); + } + + public Object[] getChildren(Object element) { + if(element instanceof DependencyNode) { + DependencyNode node = (DependencyNode) element; + List<DependencyNode> children = node.getChildren(); + return children.toArray(new DependencyNode[children.size()]); + } + return new Object[0]; + } + + public Object getParent(Object element) { + return null; + } + + public boolean hasChildren(Object element) { + if(element instanceof DependencyNode) { + DependencyNode node = (DependencyNode) element; + return !node.getChildren().isEmpty(); + } + return false; + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + } + + final class DependencyTreeLabelProvider extends LabelProvider implements IColorProvider { + + private boolean showGroupId = false; + + private Matcher matcher = null; + + public void setMatcher(Matcher matcher) { + this.matcher = matcher; + } + + public void setShowGroupId(boolean showGroupId) { + this.showGroupId = showGroupId; + } + + // IColorProvider + + public Color getForeground(Object element) { + if(element instanceof DependencyNode) { + DependencyNode node = (DependencyNode) element; + String scope = node.getDependency().getScope(); + if(scope != null && !"compile".equals(scope)) { //$NON-NLS-1$ + return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); + } + } + return null; + } + + public Color getBackground(Object element) { + if(matcher != null && !matcher.isEmpty() && element instanceof DependencyNode) { + org.sonatype.aether.artifact.Artifact a = ((DependencyNode) element).getDependency().getArtifact(); + if(matcher.isMatchingArtifact(a.getGroupId(), a.getArtifactId())) { + return searchHighlightColor; + } + } + return null; + } + + // LabelProvider + + @Override + public String getText(Object element) { + if(element instanceof DependencyNode) { + DependencyNode node = (DependencyNode) element; + + org.sonatype.aether.artifact.Artifact a = node.getDependency().getArtifact(); + + org.sonatype.aether.artifact.Artifact c = null; + if(!node.getAliases().isEmpty()) { + c = node.getAliases().iterator().next(); + } + + StringBuilder label = new StringBuilder(128); + + if(showGroupId) { + label.append(a.getGroupId()).append(" : "); + } + + label.append(a.getArtifactId()).append(" : "); + + label.append(a.getBaseVersion()); + + if(node.getPremanagedVersion() != null && !node.getPremanagedVersion().equals(a.getBaseVersion())) { + label.append(" (managed from ").append(node.getPremanagedVersion()).append(")"); + } + + if(c != null) { + String version = c.getBaseVersion(); + if(!a.getBaseVersion().equals(version)) { + label.append(" (omitted for conflict with ").append(version).append(")"); + } + } + + if(a.getClassifier().length() > 0) { + label.append(Messages.DependencyTreePage_0).append(a.getClassifier()); + } + + label.append(" [").append(node.getDependency().getScope()).append("]"); + + if(node.getPremanagedScope() != null) { + label.append(" (from ").append(node.getPremanagedScope()).append(")"); + } + + return label.toString(); + } + return element.toString(); + } + + @Override + public Image getImage(Object element) { + if(element instanceof DependencyNode) { + DependencyNode node = (DependencyNode) element; + org.sonatype.aether.artifact.Artifact a = node.getDependency().getArtifact(); + MavenProjectManager projectManager = MavenPlugin.getDefault().getMavenProjectManager(); + IMavenProjectFacade projectFacade = projectManager.getMavenProject(a.getGroupId(), // + a.getArtifactId(), // + a.getBaseVersion() == null ? a.getVersion() : a.getBaseVersion()); + return projectFacade == null ? MavenEditorImages.IMG_JAR : MavenEditorImages.IMG_PROJECT; + } + return null; + } + } + + public class DependencyListLabelProvider extends LabelProvider implements IColorProvider { + + private boolean showGroupId = false; + + private Matcher matcher = null; + + public void setMatcher(Matcher matcher) { + this.matcher = matcher; + } + + public void setShowGroupId(boolean showGroupId) { + this.showGroupId = showGroupId; + } + + // IColorProvider + + public Color getForeground(Object element) { + if(element instanceof Artifact) { + Artifact a = (Artifact) element; + String scope = a.getScope(); + if(scope != null && !"compile".equals(scope)) { //$NON-NLS-1$ + return Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); + } + } + return null; + } + + public Color getBackground(Object element) { + if(matcher != null && !matcher.isEmpty() && element instanceof Artifact) { + Artifact a = (Artifact) element; + if(matcher.isMatchingArtifact(a.getGroupId(), a.getArtifactId())) { + return searchHighlightColor; + } + } + return null; + } + + // LabelProvider + + @Override + public String getText(Object element) { + if(element instanceof Artifact) { + Artifact a = (Artifact) element; + StringBuilder label = new StringBuilder(64); + + if(showGroupId) { + label.append(a.getGroupId()).append(" : "); + } + + label.append(a.getArtifactId()).append(" : ").append(a.getVersion()); + + if(a.hasClassifier()) { + label.append(" - ").append(a.getClassifier()); + } + + if(a.getScope() != null) { + label.append(" [").append(a.getScope()).append("]"); + } + + return label.toString(); + } + return super.getText(element); + } + + @Override + public Image getImage(Object element) { + if(element instanceof Artifact) { + Artifact a = (Artifact) element; + MavenProjectManager projectManager = MavenPlugin.getDefault().getMavenProjectManager(); + IMavenProjectFacade projectFacade = projectManager.getMavenProject(a.getGroupId(), // + a.getArtifactId(), // + a.getBaseVersion() == null ? a.getVersion() : a.getBaseVersion()); + return projectFacade == null ? MavenEditorImages.IMG_JAR : MavenEditorImages.IMG_PROJECT; + } + return null; + } + + } + + public class DependencyListContentProvider implements IStructuredContentProvider { + + public Object[] getElements(Object input) { + if(input instanceof MavenProject) { + MavenProject project = (MavenProject) input; + List<Artifact> artifacts = new ArrayList<Artifact>(); + ArtifactFilter filter = new org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter(currentClasspath); + for(Artifact artifact : project.getArtifacts()) { + if(filter.include(artifact)) { + artifacts.add(artifact); + } + } + return artifacts.toArray(new Artifact[artifacts.size()]); + } + return null; + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + public void dispose() { + } + + } + + public static class ArtifactMatcher extends Matcher { + + protected final HashSet<String> artifactKeys = new HashSet<String>(); + + public ArtifactMatcher(IStructuredSelection selection) { + for(Iterator<?> it = selection.iterator(); it.hasNext();) { + addArtifactKey(it.next()); + } + } + + public boolean isEmpty() { + return artifactKeys.isEmpty(); + } + + public boolean isMatchingArtifact(String groupId, String artifactId) { + return artifactKeys.contains(getKey(groupId, artifactId)); + } + + protected void addArtifactKey(Object o) { + if(o instanceof Artifact) { + Artifact a = (Artifact) o; + artifactKeys.add(getKey(a.getGroupId(), a.getArtifactId())); + } + } + + protected String getKey(String groupId, String artifactId) { + return groupId + ":" + artifactId; + } + + } + + public static class DependencyNodeMatcher extends ArtifactMatcher { + + public DependencyNodeMatcher(IStructuredSelection selection) { + super(selection); + } + + @Override + protected void addArtifactKey(Object o) { + if(o instanceof DependencyNode) { + org.sonatype.aether.artifact.Artifact a = ((DependencyNode) o).getDependency().getArtifact(); + artifactKeys.add(getKey(a.getGroupId(), a.getArtifactId())); + } + } + + } + + @Override + public void dispose() { + MavenPlugin.getDefault().getMavenProjectManager().removeMavenProjectChangedListener(this); + + if(searchHighlightColor != null) { + searchHighlightColor.dispose(); + } + super.dispose(); + } + + public void selectDepedency(ArtifactKey artifactKey) { + if(dataLoadingJob!=null && dataLoadingJob.getState()==Job.RUNNING) { + try { + dataLoadingJob.join(); + } catch(InterruptedException ex) { + // ignore + } + } + + if(mavenProject!=null) { + Artifact artifact = getArtifact(artifactKey); + if(artifact!=null) { + listViewer.getTable().setFocus(); + listViewer.setSelection(new StructuredSelection(artifact), true); + } + } + } + + private Artifact getArtifact(ArtifactKey artifactKey) { + Set<Artifact> artifacts = mavenProject.getArtifacts(); + for(Artifact artifact : artifacts) { + if(artifactKey.equals(new ArtifactKey(artifact))) { + return artifact; + } + } + return null; + } + + + public class ClasspathAction extends Action { + + private final String classpath; + + public ClasspathAction(String text, String classpath) { + super(text, IAction.AS_RADIO_BUTTON); + this.classpath = classpath; + } + + public void run() { + if(isChecked()) { + currentClasspath = classpath; + IManagedForm managedForm = DependencyTreePage.this.getManagedForm(); + managedForm.getForm().setText(formatFormTitle()); + loadData(false); + } + } + } + + public void loadData() { + loadData(true); + } + + public void mavenProjectChanged(MavenProjectChangedEvent[] events, IProgressMonitor monitor) { + if (getManagedForm() == null || getManagedForm().getForm() == null) + return; + + for (int i=0; i<events.length; i++) { + if (events[i].getSource().equals(((MavenPomEditor) getEditor()).getPomFile())) { + // file has been changed. need to update graph + new UIJob(Messages.DependencyTreePage_job_reloading) { + public IStatus runInUIThread(IProgressMonitor monitor) { + loadData(); + FormUtils.setMessage(getManagedForm().getForm(), null, IMessageProvider.WARNING); + return Status.OK_STATUS; + } + }.schedule(); + } + } + } + + public void fileChanged() { + if (getManagedForm() == null || getManagedForm().getForm() == null) + return; + + new UIJob(Messages.DependencyTreePage_job_reloading) { + public IStatus runInUIThread(IProgressMonitor monitor) { + FormUtils.setMessage(getManagedForm().getForm(), Messages.DependencyTreePage_message_updating, IMessageProvider.WARNING); + return Status.OK_STATUS; + } + }.schedule(); + } +} 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 new file mode 100644 index 00000000..9eee3953 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/FormUtils.java @@ -0,0 +1,252 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import java.net.MalformedURLException; +import java.net.URL; + +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.ui.dialogs.MavenMessageDialog; +import org.eclipse.m2e.core.util.Util; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseTrackAdapter; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.browser.IWebBrowser; +import org.eclipse.ui.browser.IWorkbenchBrowserSupport; +import org.eclipse.ui.forms.widgets.Form; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Hyperlink; +import org.eclipse.ui.forms.widgets.ScrolledForm; + + +/** + * @author Eugene Kuleshov + */ +public abstract class FormUtils { + public static final int MAX_MSG_LENGTH = 80; + + /** + * @deprecated use your own string.. this should not have been made ublic in the first place. + */ + public static final String MORE_DETAILS = ""; //$NON-NLS-1$ + + public static void decorateHeader(FormToolkit toolkit, Form form) { + Util.proxy(toolkit, FormTooliktStub.class).decorateFormHeading(form); + } + + /** + * Stub interface for API added to FormToolikt in Eclipse 3.3 + */ + private interface FormTooliktStub { + public void decorateFormHeading(Form form); + } + + /** + * @param form + * @param message + * @param severity + * @return + */ + public static boolean setMessage(ScrolledForm form, String message, int severity) { + if(message != null && message.length() > MAX_MSG_LENGTH) { + String truncMsg = message; + String[] lines = message.split("\n"); //$NON-NLS-1$ + if(lines.length > 0) { + truncMsg = lines[0]; + } else { + truncMsg = message.substring(0, MAX_MSG_LENGTH); + } + setMessageAndTTip(form, NLS.bind(Messages.FormUtils_click_for_details, truncMsg), message, severity); + return true; + } else { + setMessageAndTTip(form, message, message, severity); + return false; + } + } + + public static void setMessageAndTTip(final ScrolledForm form, final String message, final String ttip, + final int severity) { + form.getForm().setMessage(message, severity); + addFormTitleListeners(form, message, ttip, severity); + } + + public static String nvl(String s) { + return s == null ? "" : s; //$NON-NLS-1$ + } + + public static String nvl(String s, String defaultValue) { + return s == null ? defaultValue : s; + } + + public static boolean isEmpty(String s) { + return s == null || s.length() == 0; + } + + public static boolean isEmpty(Text t) { + return t == null || isEmpty(t.getText()); + } + + public static void setText(Text control, String text) { + if(control != null && !control.isDisposed() && !control.getText().equals(text)) { + control.setText(nvl(text)); + control.setSelection(nvl(text).length()); + } + } + + public static void setText(CCombo control, String text) { + if(control != null && !control.isDisposed() && !control.getText().equals(text)) { + control.setText(nvl(text)); + } + } + + public static void setButton(Button control, boolean selection) { + if(control != null && !control.isDisposed() && control.getSelection() != selection) { + control.setSelection(selection); + } + } + + public static void openHyperlink(String url) { + if(!isEmpty(url) && (url.startsWith("http://") || url.startsWith("https://"))) { //$NON-NLS-1$ //$NON-NLS-2$ + url = url.trim(); + try { + IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport(); + IWebBrowser browser = browserSupport.createBrowser(IWorkbenchBrowserSupport.NAVIGATION_BAR + | IWorkbenchBrowserSupport.LOCATION_BAR, url, url, url); + browser.openURL(new URL(url)); + } catch(PartInitException ex) { + MavenLogger.log(ex); + } catch(MalformedURLException ex) { + MavenLogger.log("Malformed url " + url, ex); //$NON-NLS-1$ + } + } + } + + public static void setEnabled(Composite composite, boolean enabled) { + if(composite != null && !composite.isDisposed()) { + composite.setEnabled(enabled); + for(Control control : composite.getChildren()) { + if(control instanceof Combo) { + control.setEnabled(enabled); + + } else if(control instanceof CCombo) { + control.setEnabled(enabled); + + } else if(control instanceof Hyperlink) { + control.setEnabled(enabled); + + } else if(control instanceof Composite) { + setEnabled((Composite) control, enabled); + + } else { + control.setEnabled(enabled); + + } + } + } + } + + public static void setReadonly(Composite composite, boolean readonly) { + if(composite != null) { + for(Control control : composite.getChildren()) { + if(control instanceof Text) { + ((Text) control).setEditable(!readonly); + + } else if(control instanceof Combo) { + ((Combo) control).setEnabled(!readonly); + + } else if(control instanceof CCombo) { + ((CCombo) control).setEnabled(!readonly); + + } else if(control instanceof Button) { + ((Button) control).setEnabled(!readonly); + + } else if(control instanceof Composite) { + setReadonly((Composite) control, readonly); + + } + } + } + } + + private static void cleanupMouseListeners(Control kid, int event) { + Listener[] listeners = kid.getListeners(event); + if(listeners != null) { + for(Listener list : listeners) { + kid.removeListener(event, list); + } + } + } + + private static void addFormTitleListeners(final ScrolledForm form, final String message, final String ttip, + final int severity) { + if(ttip != null && ttip.length() > 0 && message != null && severity == IMessageProvider.ERROR) { + final Composite head = form.getForm().getHead(); + Control[] kids = head.getChildren(); + for(Control kid : kids) { + //want to get the title region only + //Note: doing this instead of adding a head 'client' control because that gets put + //on the second line of the title, and looks broken. instead, converting the title + //into a url + if(kid != form && kid instanceof Canvas) { + cleanupMouseListeners(kid, SWT.MouseUp); + cleanupMouseListeners(kid, SWT.MouseEnter); + cleanupMouseListeners(kid, SWT.MouseExit); + kid.addMouseListener(new MouseAdapter() { + public void mouseUp(MouseEvent e) { + MavenMessageDialog.openInfo(form.getShell(), Messages.FormUtils_error_info, Messages.FormUtils_pom_error, ttip); + } + }); + kid.addMouseTrackListener(new MouseTrackAdapter() { + public void mouseEnter(MouseEvent e) { + head.setCursor(Display.getDefault().getSystemCursor(SWT.CURSOR_HAND)); + } + + public void mouseExit(MouseEvent e) { + head.setCursor(null); + } + }); + } + } + } else { + //no ttip or message, make sure old listeners are cleaned up if errs are removed + final Composite head = form.getForm().getHead(); + Control[] kids = head.getChildren(); + for(Control kid : kids) { + //want to get the title region only + //Note: doing this instead of adding a head 'client' control because that gets put + //on the second line of the title, and looks broken. instead, converting the title + //into a url + if(kid != form && kid instanceof Canvas) { + cleanupMouseListeners(kid, SWT.MouseUp); + cleanupMouseListeners(kid, SWT.MouseEnter); + cleanupMouseListeners(kid, SWT.MouseExit); + } + } + } + } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/IPomFileChangedListener.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/IPomFileChangedListener.java new file mode 100644 index 00000000..d1b5fe6e --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/IPomFileChangedListener.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +public interface IPomFileChangedListener { + + public void fileChanged(); + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/Matcher.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/Matcher.java new file mode 100644 index 00000000..d321de46 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/Matcher.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +/** + * @author Eugene Kuleshov + */ +public abstract class Matcher { + + public abstract boolean isMatchingArtifact(String groupId, String artifactId); + + public abstract boolean isEmpty(); + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java new file mode 100644 index 00000000..c8404c3d --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java @@ -0,0 +1,1214 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.EventObject; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.apache.maven.model.io.xpp3.MavenXpp3Writer; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.IOUtil; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.resources.IResourceDeltaVisitor; +import org.eclipse.core.resources.IStorage; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.emf.common.command.BasicCommandStack; +import org.eclipse.emf.common.command.CommandStackListener; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.common.notify.impl.AdapterFactoryImpl; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.emf.edit.domain.IEditingDomainProvider; +import org.eclipse.emf.edit.provider.ComposedAdapterFactory; +import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory; +import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentListener; +import org.eclipse.jface.text.ITextListener; +import org.eclipse.jface.text.TextEvent; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.actions.OpenPomAction.MavenPathStorageEditorInput; +import org.eclipse.m2e.core.actions.OpenPomAction.MavenStorageEditorInput; +import org.eclipse.m2e.core.actions.SelectionUtil; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.embedder.MavenModelManager; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectManager; +import org.eclipse.m2e.core.util.Util; +import org.eclipse.m2e.core.util.Util.FileStoreEditorInputStub; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.MavenEditorPlugin; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.model.edit.pom.Model; +import org.eclipse.m2e.model.edit.pom.util.PomResourceFactoryImpl; +import org.eclipse.m2e.model.edit.pom.util.PomResourceImpl; +import org.eclipse.search.ui.text.ISearchEditorAccess; +import org.eclipse.search.ui.text.Match; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IEditorActionBarContributor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.IPartListener; +import org.eclipse.ui.IPartService; +import org.eclipse.ui.IShowEditorInput; +import org.eclipse.ui.IStorageEditorInput; +import org.eclipse.ui.IWindowListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.forms.editor.FormEditor; +import org.eclipse.ui.forms.editor.IFormPage; +import org.eclipse.ui.ide.IGotoMarker; +import org.eclipse.ui.part.MultiPageEditorActionBarContributor; +import org.eclipse.ui.progress.UIJob; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.IDocumentProviderExtension3; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; +import org.eclipse.wst.sse.core.StructuredModelManager; +import org.eclipse.wst.sse.core.internal.provisional.IModelManager; +import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; +import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; +import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager; +import org.eclipse.wst.sse.ui.StructuredTextEditor; +import org.eclipse.wst.xml.core.internal.emf2xml.EMF2DOMSSEAdapter; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement; +import org.sonatype.aether.graph.DependencyNode; + + +/** + * Maven POM editor + * + * @author Eugene Kuleshov + * @author Anton Kraev + */ +@SuppressWarnings("restriction") +public class MavenPomEditor extends FormEditor implements IResourceChangeListener, IShowEditorInput, IGotoMarker, + ISearchEditorAccess, IEditingDomainProvider { + + private static final String POM_XML = "pom.xml"; + + public static final String EDITOR_ID = "org.eclipse.m2e.editor.MavenPomEditor"; //$NON-NLS-1$ + + private static final String EXTENSION_FACTORIES = MavenEditorPlugin.PLUGIN_ID + ".pageFactories"; //$NON-NLS-1$ + + private static final String ELEMENT_PAGE = "factory"; //$NON-NLS-1$ + + private static final String EFFECTIVE_POM = Messages.MavenPomEditor_effective_pom; + + IAction showAdvancedTabsAction; + + OverviewPage overviewPage; + + DependenciesPage dependenciesPage; + + RepositoriesPage repositoriesPage; + + BuildPage buildPage; + + PluginsPage pluginsPage; + + ReportingPage reportingPage; + + ProfilesPage profilesPage; + + TeamPage teamPage; + + DependencyTreePage dependencyTreePage; + + StructuredSourceTextEditor sourcePage; + + StructuredTextEditor effectivePomSourcePage; + + List<MavenPomEditorPage> pages = new ArrayList<MavenPomEditorPage>(); + + private Model projectDocument; + + private Map<String, org.sonatype.aether.graph.DependencyNode> rootNodes = new HashMap<String, org.sonatype.aether.graph.DependencyNode>(); + + IStructuredModel structuredModel; + + private MavenProject mavenProject; + + AdapterFactory adapterFactory; + + AdapterFactoryEditingDomain editingDomain; + + private int sourcePageIndex; + + NotificationCommandStack commandStack; + + IModelManager modelManager; + + IFile pomFile; + + MavenPomActivationListener activationListener; + + boolean dirty; + + CommandStackListener commandStackListener; + + BasicCommandStack sseCommandStack; + + List<IPomFileChangedListener> fileChangeListeners = new ArrayList<IPomFileChangedListener>(); + + private LoadDependenciesJob loadDependenciesJob; + + public MavenPomEditor() { + modelManager = StructuredModelManager.getModelManager(); + } + + // IResourceChangeListener + + /** + * Closes all project files on project close. + */ + public void resourceChanged(final IResourceChangeEvent event) { + if(pomFile == null) { + return; + } + + //handle project delete + if(event.getType() == IResourceChangeEvent.PRE_CLOSE || event.getType() == IResourceChangeEvent.PRE_DELETE) { + if(pomFile.getProject().equals(event.getResource())) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + close(false); + } + }); + } + return; + } + //handle pom delete + class RemovedResourceDeltaVisitor implements IResourceDeltaVisitor { + boolean removed = false; + + public boolean visit(IResourceDelta delta) throws CoreException { + if(delta.getResource() == pomFile // + && (delta.getKind() & (IResourceDelta.REMOVED)) != 0) { + removed = true; + return false; + } + return true; + } + }; + + try { + RemovedResourceDeltaVisitor visitor = new RemovedResourceDeltaVisitor(); + event.getDelta().accept(visitor); + if(visitor.removed) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + close(true); + } + }); + } + } catch(CoreException ex) { + MavenLogger.log(ex); + } + + // Reload model if pom file was changed externally. + // TODO implement generic merge scenario (when file is externally changed and is dirty) + + // suppress a prompt to reload the pom if modifications were caused by workspace actions + sourcePage.updateModificationStamp(); + + class ChangedResourceDeltaVisitor implements IResourceDeltaVisitor { + + public boolean visit(IResourceDelta delta) throws CoreException { + if(delta.getResource().equals(pomFile) + && (delta.getKind() & IResourceDelta.CHANGED) != 0 && delta.getResource().exists()) { + int flags = delta.getFlags(); + if ((flags & (IResourceDelta.CONTENT | flags & IResourceDelta.REPLACED)) != 0) { + handleContentChanged(); + return false; + } + if ((flags & IResourceDelta.MARKERS) != 0) { + handleMarkersChanged(); + return false; + } + } + return true; + } + + private void handleContentChanged() { + Display.getDefault().asyncExec(new Runnable() { + public void run() { +/* MNGECLIPSE-1789: commented this out since forced model reload caused the XML editor to go crazy; + the model is already updated at this point so reloading from file is unnecessary; + externally originated file updates are checked in handleActivation() */ +// try { +// structuredModel.reload(pomFile.getContents()); + reload(); +// } catch(CoreException e) { +// MavenLogger.log(e); +// } catch(Exception e) { +// MavenLogger.log("Error loading pom editor model.", e); +// } + } + }); + } + private void handleMarkersChanged() { + try { + IMarker[] markers = pomFile.findMarkers(IMavenConstants.MARKER_ID, true, IResource.DEPTH_ZERO); + final String msg = markers != null && markers.length > 0 // + ? markers[0].getAttribute(IMarker.MESSAGE, "Unknown error") : null; + final int severity = markers != null && markers.length > 0 ? (markers[0].getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR) == IMarker.SEVERITY_WARNING ? IMessageProvider.WARNING : IMessageProvider.ERROR) : IMessageProvider.NONE; + + Display.getDefault().asyncExec(new Runnable() { + public void run() { + for(MavenPomEditorPage page : pages) { + page.setErrorMessage(msg, msg == null ? IMessageProvider.NONE : severity); + } + } + }); + } catch (CoreException ex ) { + MavenLogger.log("Error updating pom file markers.", ex); //$NON-NLS-1$ + } + } + }; + + try { + ChangedResourceDeltaVisitor visitor = new ChangedResourceDeltaVisitor(); + event.getDelta().accept(visitor); + } catch(CoreException ex) { + MavenLogger.log(ex); + } + + } + + public void reload() { + if (projectDocument != null) { + projectDocument.eResource().unload(); + } + projectDocument = null; + try { + readProjectDocument(); + //fix for resetting the pom document after an external change +// sourcePage.getDocumentProvider().resetDocument(sourcePage.getEditorInput()); + } catch(CoreException e) { + MavenLogger.log(e); + } + for(MavenPomEditorPage page : pages) { + page.reload(); + } + if(isEffectiveActive()){ + loadEffectivePOM(); + } + flushCommandStack(); + } + + private boolean isEffectiveActive(){ + int active = getActivePage(); + String name = getPageText(active); + return EFFECTIVE_POM.equals(name); + } + + void flushCommandStack() { + dirty = false; + if (sseCommandStack != null) + sseCommandStack.saveIsDone(); + if (getContainer() != null && !getContainer().isDisposed()) + getContainer().getDisplay().asyncExec(new Runnable() { + public void run() { + editorDirtyStateChanged(); + } + }); + } + + /** + * Show or hide the advanced pages within the editor (based on the default setting) + */ + protected void showAdvancedPages(){ + showAdvancedPages(MavenPlugin.getDefault().getPreferenceStore().getBoolean(PomEditorPreferencePage.P_SHOW_ADVANCED_TABS)); + } + + /** + * Show or hide the advanced pages within the editor (forced) + */ + protected void showAdvancedPages(boolean showAdvancedTabs){ + if(!showAdvancedTabs) { + return; + } + + if(repositoriesPage == null){ + showAdvancedTabsAction.setChecked(true); + + repositoriesPage = new RepositoriesPage(this); + addPomPage(repositoriesPage); + + buildPage = new BuildPage(this); + addPomPage(buildPage); + + profilesPage = new ProfilesPage(this); + addPomPage(profilesPage); + + teamPage = new TeamPage(this); + addPomPage(teamPage); + + } + } + + protected void addPages() { + + showAdvancedTabsAction = new Action(Messages.MavenPomEditor_action_advanced, IAction.AS_RADIO_BUTTON) { + public void run() { + showAdvancedPages(showAdvancedTabsAction.isChecked()); +// pomEditor.reload(); + } + }; + showAdvancedTabsAction.setImageDescriptor(MavenEditorImages.ADVANCED_TABS); + + overviewPage = new OverviewPage(this); + addPomPage(overviewPage); + + dependenciesPage = new DependenciesPage(this); + addPomPage(dependenciesPage); + + pluginsPage = new PluginsPage(this); + addPomPage(pluginsPage); + + reportingPage = new ReportingPage(this); + addPomPage(reportingPage); + + dependencyTreePage = new DependencyTreePage(this); + addPomPage(dependencyTreePage); + + addSourcePage(); + + showAdvancedPages(); + + addEditorPageExtensions(); + selectActivePage(); + } + + protected void selectActivePage(){ + boolean showXML = MavenPlugin.getDefault().getPreferenceStore().getBoolean(PomEditorPreferencePage.P_DEFAULT_POM_EDITOR_PAGE); + if(showXML){ + setActivePage(null); + } + } + + protected void pageChange(int newPageIndex) { + String name = getPageText(newPageIndex); + if(EFFECTIVE_POM.equals(name)){ + loadEffectivePOM(); + } + if (POM_XML.equals(name)) { + //attempt to preload the maven project to have the caches hot for template proposals. + if (getEditorInput() instanceof IFileEditorInput) { + IFileEditorInput ei = (IFileEditorInput)getEditorInput(); + final IFile file = ei.getFile(); + IProject prj = file != null ? file.getProject() : null; + if (prj != null) { + MavenProjectManager projectManager = MavenPlugin.getDefault().getMavenProjectManager(); + final IMavenProjectFacade mvnprj = projectManager.getProject(prj); + if (mvnprj != null && mvnprj.getMavenProject() == null) { + Job jb = new Job("load maven project") { + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + mvnprj.getMavenProject(monitor); + } catch(CoreException e) { + //just ignore + MavenLogger.log("Unable to read maven project. Some content assists might not work as advertized.", e); //$NON-NLS-1$ + } + return Status.OK_STATUS; + } + }; + jb.setSystem(true); + jb.schedule(); + } + } + } + } + //The editor occassionally doesn't get + //closed if the project gets deleted. In this case, the editor + //stays open and very bad things happen if you select it + try{ + super.pageChange(newPageIndex); + }catch(NullPointerException e){ + MavenEditorPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, "", e)); //$NON-NLS-1$ + this.close(false); + } + // a workaround for editor pages not returned + IEditorActionBarContributor contributor = getEditorSite().getActionBarContributor(); + if(contributor != null && contributor instanceof MultiPageEditorActionBarContributor) { + IEditorPart activeEditor = getActivePageInstance(); + ((MultiPageEditorActionBarContributor) contributor).setActivePage(activeEditor); + } + } + + private void addEditorPageExtensions() { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint indexesExtensionPoint = registry.getExtensionPoint(EXTENSION_FACTORIES); + if(indexesExtensionPoint != null) { + IExtension[] indexesExtensions = indexesExtensionPoint.getExtensions(); + for(IExtension extension : indexesExtensions) { + for(IConfigurationElement element : extension.getConfigurationElements()) { + if(element.getName().equals(ELEMENT_PAGE)) { + try { + MavenPomEditorPageFactory factory; + factory = (MavenPomEditorPageFactory) element.createExecutableExtension("class"); //$NON-NLS-1$ + factory.addPages(this); + } catch(CoreException ex) { + MavenLogger.log(ex); + } + } + } + } + } + } + + public void loadDependencies(Callback callback, String classpath) { + if (this.loadDependenciesJob != null && this.loadDependenciesJob.dependencyNode != null) { + //Already loaded, we're done! + callback.onFinish(loadDependenciesJob.dependencyNode); + return; + } else if (this.loadDependenciesJob != null && this.loadDependenciesJob.getState() != Job.NONE) { + //Currently running + loadDependenciesJob.addCallback(callback); + return; + } + + this.loadDependenciesJob = new LoadDependenciesJob(this, classpath, callback); + loadDependenciesJob.schedule(); + } + + public static interface Callback { + /** + * Called when the dependency tree is done loading. The node parameter + * points to the root of the tree. + * @param node + */ + public void onFinish(DependencyNode node); + + /** + * Called if an exception occurs while loading the dependency tree. + * @param ex + */ + public void onException(CoreException ex); + } + + /** + * Loads the dependency tree in a Job so as to not block the UI. + * Once the loading is done, it calls the provided callback with the root + * node of the dependency tree. If there is an error, it notifies the + * callback's onException method. + */ + class LoadDependenciesJob extends Job { + + private MavenPomEditor pomEditor; + private String classpath; + private List<Callback> callbacks = new LinkedList<MavenPomEditor.Callback>(); + DependencyNode dependencyNode; + + public LoadDependenciesJob(MavenPomEditor editor, String classpath, Callback callback) { + super("Resolving dependencies"); + this.pomEditor = editor; + this.classpath = classpath; + this.callbacks.add( callback ); + } + + void addCallback(Callback callback) { + if (!this.callbacks.contains(callback)) { + this.callbacks.add( callback ); + } + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + protected IStatus run(IProgressMonitor monitor) { + boolean force = false; + try { + final DependencyNode dependencyNode = pomEditor.readDependencyTree(force, classpath, monitor); + + if(dependencyNode == null) { + return Status.CANCEL_STATUS; + } + this.dependencyNode = dependencyNode; + for (Callback callback : callbacks) { + callback.onFinish(dependencyNode); + } + } catch(final CoreException ex) { + for (Callback callback : callbacks) { + callback.onException(ex); + } + } + + return Status.OK_STATUS; + } + } + + /** + * Load the effective POM in a job and then update the effective pom page when its done + * @author dyocum + * + */ + class LoadEffectivePomJob extends Job{ + + public LoadEffectivePomJob(String name) { + super(name); + } + + private void showEffectivePomError(final String name){ + Display.getDefault().asyncExec(new Runnable(){ + public void run(){ + String error = Messages.MavenPomEditor_error_loading_effective_pom; + IEditorInput editorInput = new MavenPathStorageEditorInput(name, name, null, error.getBytes()); + effectivePomSourcePage.setInput(editorInput); + } + }); + } + @Override + protected IStatus run(IProgressMonitor monitor) { + try{ + StringWriter sw = new StringWriter(); + final String name = getPartName() + Messages.MavenPomEditor_effective; + MavenProject mavenProject = SelectionUtil.getMavenProject(getEditorInput(), monitor); + if(mavenProject == null){ + showEffectivePomError(name); + return Status.CANCEL_STATUS; + } + new MavenXpp3Writer().write(sw, mavenProject.getModel()); + final String content = sw.toString(); + + Display.getDefault().asyncExec(new Runnable(){ + public void run() { + try{ + IEditorInput editorInput = new MavenStorageEditorInput(name, name, null, content.getBytes("UTF-8")); //$NON-NLS-1$ + effectivePomSourcePage.setInput(editorInput); + effectivePomSourcePage.update(); + }catch(IOException ie){ + MavenLogger.log(new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, -1, Messages.MavenPomEditor_error_failed_effective, ie)); + } + } + }); + return Status.OK_STATUS; + } catch(CoreException ce){ + return new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, -1, Messages.MavenPomEditor_error_failed_effective, ce); + } catch(IOException ie){ + return new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, -1, Messages.MavenPomEditor_error_failed_effective, ie); + } + } + } + + /** + * Load the effective POM. Should only happen when tab is brought to front or tab + * is in front when a reload happens. + */ + private void loadEffectivePOM(){ + //put a msg in the editor saying that the effective pom is loading, in case this is a long running job + String content = Messages.MavenPomEditor_loading; + String name = getPartName() + Messages.MavenPomEditor_effective; + IEditorInput editorInput = new MavenStorageEditorInput(name, name, null, content.getBytes()); + effectivePomSourcePage.setInput(editorInput); + + //then start the load + LoadEffectivePomJob job = new LoadEffectivePomJob(Messages.MavenPomEditor_loading); + job.schedule(); + } + + protected class StructuredSourceTextEditor extends StructuredTextEditor { + private long fModificationStamp = -1; + + protected void updateModificationStamp() { + IDocumentProvider p= getDocumentProvider(); + if (p == null) + return; + + if(p instanceof IDocumentProviderExtension3) { + fModificationStamp= p.getModificationStamp(getEditorInput()); + } + } + protected void sanityCheckState(IEditorInput input) { + + IDocumentProvider p= getDocumentProvider(); + if (p == null) + return; + + if (p instanceof IDocumentProviderExtension3) { + + IDocumentProviderExtension3 p3= (IDocumentProviderExtension3) p; + + long stamp= p.getModificationStamp(input); + if (stamp != fModificationStamp) { + fModificationStamp= stamp; + if (!p3.isSynchronized(input)) + handleEditorInputChanged(); + } + + } else { + + if (fModificationStamp == -1) + fModificationStamp= p.getSynchronizationStamp(input); + + long stamp= p.getModificationStamp(input); + if (stamp != fModificationStamp) { + fModificationStamp= stamp; + if (stamp != p.getSynchronizationStamp(input)) + handleEditorInputChanged(); + } + } + + updateState(getEditorInput()); + updateStatusField(ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE); + } + public void doSave(IProgressMonitor monitor) { + // always save text editor + ResourcesPlugin.getWorkspace().removeResourceChangeListener(MavenPomEditor.this); + try { + super.doSave(monitor); + flushCommandStack(); + } finally { + ResourcesPlugin.getWorkspace().addResourceChangeListener(MavenPomEditor.this); + } + } + + private boolean oldDirty; + public boolean isDirty() { + if (oldDirty != dirty) { + oldDirty = dirty; + updatePropertyDependentActions(); + } + return dirty; + } + } + + private void addSourcePage() { + sourcePage = new StructuredSourceTextEditor(); + sourcePage.setEditorPart(this); + //the page for showing the effective POM + effectivePomSourcePage = new StructuredTextEditor(); + effectivePomSourcePage.setEditorPart(this); + try { + int dex = addPage(effectivePomSourcePage, getEditorInput()); + setPageText(dex, EFFECTIVE_POM); + + sourcePageIndex = addPage(sourcePage, getEditorInput()); + setPageText(sourcePageIndex, POM_XML); + sourcePage.update(); + + + IDocument doc = sourcePage.getDocumentProvider().getDocument(getEditorInput()); + + doc.addDocumentListener(new IDocumentListener(){ + + public void documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent event) { + } + + public void documentChanged(org.eclipse.jface.text.DocumentEvent event) { + //recheck the read-only status if the document changes (will happen when xml page is edited) + if(MavenPomEditor.this.checkedWritableStatus && MavenPomEditor.this.readOnly){ + MavenPomEditor.this.checkedWritableStatus = false; + } + } + }); + structuredModel = modelManager.getExistingModelForEdit(doc); + if(structuredModel == null) { + structuredModel = modelManager.getModelForEdit((IStructuredDocument) doc); + } + + commandStackListener = new CommandStackListener() { + public void commandStackChanged(EventObject event) { + boolean oldDirty = dirty; + dirty = sseCommandStack.isSaveNeeded(); + if (dirty != oldDirty) + MavenPomEditor.this.editorDirtyStateChanged(); + } + }; + + IStructuredTextUndoManager undoManager = structuredModel.getUndoManager(); + if(undoManager != null) { + sseCommandStack = (BasicCommandStack) undoManager.getCommandStack(); + if(sseCommandStack != null) { + sseCommandStack.addCommandStackListener(commandStackListener); + } + } + + flushCommandStack(); + try { + readProjectDocument(); + } catch(CoreException e) { + MavenLogger.log(e); + } + + // TODO activate xml source page if model is empty or have errors + + if(doc instanceof IStructuredDocument) { + List<AdapterFactoryImpl> factories = new ArrayList<AdapterFactoryImpl>(); + factories.add(new ResourceItemProviderAdapterFactory()); + factories.add(new ReflectiveItemProviderAdapterFactory()); + + adapterFactory = new ComposedAdapterFactory(factories); + commandStack = new NotificationCommandStack(this); + editingDomain = new AdapterFactoryEditingDomain(adapterFactory, // + commandStack, new HashMap<Resource, Boolean>()); + } + } catch(PartInitException ex) { + MavenLogger.log(ex); + } + } + + public boolean isReadOnly() { + return !(getEditorInput() instanceof IFileEditorInput); + } + + private int addPomPage(IFormPage page) { + try { + if(page instanceof MavenPomEditorPage) { + pages.add((MavenPomEditorPage) page); + } + if (page instanceof IPomFileChangedListener) { + fileChangeListeners.add((IPomFileChangedListener) page); + } + return addPage(page); + } catch(PartInitException ex) { + MavenLogger.log(ex); + return -1; + } + } + + public EditingDomain getEditingDomain() { + return editingDomain; + } + + // XXX move to MavenModelManager (CommandStack and EditorDomain too) + public synchronized Model readProjectDocument() throws CoreException { + if(projectDocument == null) { + IEditorInput input = getEditorInput(); + if(input instanceof IFileEditorInput) { + pomFile = ((IFileEditorInput) input).getFile(); + pomFile.refreshLocal(1, null); + + ResourcesPlugin.getWorkspace().addResourceChangeListener(this); + MavenModelManager modelManager = MavenPlugin.getDefault().getMavenModelManager(); + PomResourceImpl resource = modelManager.loadResource(pomFile); + projectDocument = resource.getModel(); + + } else if(input instanceof IStorageEditorInput) { + IStorageEditorInput storageInput = (IStorageEditorInput) input; + IStorage storage = storageInput.getStorage(); + IPath path = storage.getFullPath(); + if(path == null || !new File(path.toOSString()).exists()) { + File tempPomFile = null; + InputStream is = null; + OutputStream os = null; + try { + tempPomFile = File.createTempFile("maven-pom", ".pom"); //$NON-NLS-1$ //$NON-NLS-2$ + os = new FileOutputStream(tempPomFile); + is = storage.getContents(); + IOUtil.copy(is, os); + projectDocument = loadModel(tempPomFile.getAbsolutePath()); + } catch(IOException ex) { + MavenLogger.log("Can't close stream", ex); //$NON-NLS-1$ + } finally { + IOUtil.close(is); + IOUtil.close(os); + if(tempPomFile != null) { + tempPomFile.delete(); + } + } + } else { + projectDocument = loadModel(path.toOSString()); + } + + } else if(input.getClass().getName().endsWith("FileStoreEditorInput")) { //$NON-NLS-1$ + projectDocument = loadModel(Util.proxy(input, FileStoreEditorInputStub.class).getURI().getPath()); + } + } + + return projectDocument; + } + + private Model loadModel(String path) { + URI uri = URI.createFileURI(path); + PomResourceFactoryImpl factory = new PomResourceFactoryImpl(); + PomResourceImpl resource = (PomResourceImpl) factory.createResource(uri); + + try { + resource.load(Collections.EMPTY_MAP); + return (Model)resource.getContents().get(0); + + } catch(Exception ex) { + MavenLogger.log("Can't load model " + path, ex); //$NON-NLS-1$ + return null; + + } + } + + public synchronized org.sonatype.aether.graph.DependencyNode readDependencyTree(boolean force, String classpath, + IProgressMonitor monitor) throws CoreException { + if(force || !rootNodes.containsKey(classpath)) { + monitor.setTaskName(Messages.MavenPomEditor_task_reading); + MavenProject mavenProject = readMavenProject(force, monitor); + if(mavenProject == null){ + MavenLogger.log("Unable to read maven project. Dependencies not updated.", null); //$NON-NLS-1$ + return null; + } + + rootNodes.put(classpath, + MavenPlugin.getDefault().getMavenModelManager().readDependencyTree(mavenProject, classpath, monitor)); + } + + return rootNodes.get(classpath); + } + + public MavenProject readMavenProject(boolean force, IProgressMonitor monitor) throws CoreException { + if(force || mavenProject == null) { + IEditorInput input = getEditorInput(); + + if(input instanceof IFileEditorInput) { + IFileEditorInput fileInput = (IFileEditorInput) input; + pomFile = fileInput.getFile(); + pomFile.refreshLocal(1, null); + ResourcesPlugin.getWorkspace().addResourceChangeListener(this); + } + + mavenProject = SelectionUtil.getMavenProject(input, monitor); + } + return mavenProject; + } + + public void dispose() { + new UIJob(Messages.MavenPomEditor_job_disposing) { + @SuppressWarnings("synthetic-access") + public IStatus runInUIThread(IProgressMonitor monitor) { + structuredModel.releaseFromEdit(); + if (sseCommandStack != null) + sseCommandStack.removeCommandStackListener(commandStackListener); + + if(activationListener != null) { + activationListener.dispose(); + activationListener = null; + } + + ResourcesPlugin.getWorkspace().removeResourceChangeListener(MavenPomEditor.this); + + if(projectDocument != null) { + projectDocument.eResource().unload(); + } + MavenPomEditor.super.dispose(); + return Status.OK_STATUS; + } + }.schedule(); + } + + /** + * Saves structured editor XXX form model need to be synchronized + */ + public void doSave(IProgressMonitor monitor) { + new UIJob(Messages.MavenPomEditor_job_saving) { + public IStatus runInUIThread(IProgressMonitor monitor) { + sourcePage.doSave(monitor); + return Status.OK_STATUS; + } + }.schedule(); + } + + public void doSaveAs() { + // IEditorPart editor = getEditor(0); + // editor.doSaveAs(); + // setPageText(0, editor.getTitle()); + // setInput(editor.getEditorInput()); + } + + /* + * (non-Javadoc) Method declared on IEditorPart. + */ + public boolean isSaveAsAllowed() { + return false; + } + + public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException { +// if(!(editorInput instanceof IStorageEditorInput)) { +// throw new PartInitException("Unsupported editor input " + editorInput); +// } + + setPartName(editorInput.getToolTipText()); + // setContentDescription(name); + + super.init(site, editorInput); + + activationListener = new MavenPomActivationListener(site.getWorkbenchWindow().getPartService()); + } + + public void showInSourceEditor(EObject o) { + IDOMElement element = getElement(o); + if(element != null) { + int start = element.getStartOffset(); + int lenght = element.getLength(); + setActivePage(sourcePageIndex); + sourcePage.selectAndReveal(start, lenght); + } + } + + public IDOMElement getElement(EObject o) { + for(Adapter adapter : o.eAdapters()) { + if(adapter instanceof EMF2DOMSSEAdapter) { + EMF2DOMSSEAdapter a = (EMF2DOMSSEAdapter) adapter; + if(a.getNode() instanceof IDOMElement) { + return (IDOMElement) a.getNode(); + } + break; + } + } + return null; + } + + // IShowEditorInput + + public void showEditorInput(IEditorInput editorInput) { + // could activate different tabs based on the editor input + } + + // IGotoMarker + + public void gotoMarker(IMarker marker) { + // TODO use selection to activate corresponding form page elements + setActivePage(sourcePageIndex); + IGotoMarker adapter = (IGotoMarker) sourcePage.getAdapter(IGotoMarker.class); + adapter.gotoMarker(marker); + } + + // ISearchEditorAccess + + public IDocument getDocument(Match match) { + return sourcePage.getDocumentProvider().getDocument(getEditorInput()); + } + + public IAnnotationModel getAnnotationModel(Match match) { + return sourcePage.getDocumentProvider().getAnnotationModel(getEditorInput()); + } + + public boolean isDirty() { + return sourcePage.isDirty(); + } + + public List<MavenPomEditorPage> getPages() { + return pages; + } + + public void showDependencyHierarchy(ArtifactKey artifactKey) { + setActivePage(dependencyTreePage.getId()); + dependencyTreePage.selectDepedency(artifactKey); + } + + private boolean checkedWritableStatus; + private boolean readOnly; + /** read/write check for read only pom files -- called when the file is opened + * and will validateEdit -- so files will be checked out of src control, etc + * Note: this is actually done separately from isReadOnly() because there are 2 notions of 'read only' + * for a POM. The first is for a file downloaded from a repo, like maven central. That one + * is never editable. The second is for a local file that is read only because its been marked + * that way by an SCM, etc. This method will do a one-time check/validateEdit for the life of the POM + * editor. + **/ + protected boolean checkReadOnly(){ + if(checkedWritableStatus){ + return readOnly; + } + checkedWritableStatus = true; + if(getPomFile() != null && getPomFile().isReadOnly()){ + IStatus validateEdit = ResourcesPlugin.getWorkspace().validateEdit(new IFile[]{getPomFile()}, getEditorSite().getShell()); + if(!validateEdit.isOK()){ + readOnly = true; + } else { + readOnly = isReadOnly(); + } + } else { + readOnly = isReadOnly(); + } + return readOnly; + } + + /** + * Adapted from <code>org.eclipse.ui.texteditor.AbstractTextEditor.ActivationListener</code> + */ + class MavenPomActivationListener implements IPartListener, IWindowListener { + + private IWorkbenchPart activePart; + + private boolean isHandlingActivation = false; + + + public MavenPomActivationListener(IPartService partService) { + partService.addPartListener(this); + PlatformUI.getWorkbench().addWindowListener(this); + } + + public void dispose() { + getSite().getWorkbenchWindow().getPartService().removePartListener(this); + PlatformUI.getWorkbench().removeWindowListener(this); + } + + + // IPartListener + + public void partActivated(IWorkbenchPart part) { + activePart = part; + handleActivation(); + checkReadOnly(); + } + + public void partBroughtToTop(IWorkbenchPart part) { + } + + public void partClosed(IWorkbenchPart part) { + } + + public void partDeactivated(IWorkbenchPart part) { + activePart = null; + } + + public void partOpened(IWorkbenchPart part) { + } + + // IWindowListener + + public void windowActivated(IWorkbenchWindow window) { + if(window == getEditorSite().getWorkbenchWindow()) { + /* + * Workaround for problem described in + * http://dev.eclipse.org/bugs/show_bug.cgi?id=11731 + * Will be removed when SWT has solved the problem. + */ + window.getShell().getDisplay().asyncExec(new Runnable() { + public void run() { + handleActivation(); + } + }); + } + } + + public void windowDeactivated(IWorkbenchWindow window) { + } + + public void windowClosed(IWorkbenchWindow window) { + } + + public void windowOpened(IWorkbenchWindow window) { + } + + /** + * Handles the activation triggering a element state check in the editor. + */ + void handleActivation() { + if(isHandlingActivation) { + return; + } + + if(activePart == MavenPomEditor.this) { + isHandlingActivation = true; + final boolean[] changed = new boolean[] {false}; + try { + + ITextListener listener = new ITextListener() { + public void textChanged(TextEvent event) { + changed[0] = true; + } + }; + if (sourcePage != null && sourcePage.getTextViewer() != null) { + sourcePage.getTextViewer().addTextListener(listener); + try { + sourcePage.safelySanityCheckState(getEditorInput()); + } finally { + sourcePage.getTextViewer().removeTextListener(listener); + } + sourcePage.update(); + } + + if(changed[0]) { + try { + pomFile.refreshLocal(IResource.DEPTH_INFINITE, null); + } catch(CoreException e) { + MavenLogger.log(e); + } + } + + } finally { + isHandlingActivation = false; + + } + } + } + } + + public StructuredTextEditor getSourcePage() { + return sourcePage; + } + + @Override + public IFormPage setActivePage(String pageId) { + if(pageId == null) { + setActivePage(sourcePageIndex); + } + return super.setActivePage(pageId); + } + + @Override + @SuppressWarnings("unchecked") + public Object getAdapter(Class adapter) { + Object result = super.getAdapter(adapter); + if(result != null && Display.getCurrent() == null) { + return result; + } + return sourcePage.getAdapter(adapter); + } + + public IFile getPomFile() { + return pomFile; + } + + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorContributor.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorContributor.java new file mode 100644 index 00000000..d10be490 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorContributor.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import org.eclipse.jface.action.IAction; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.ide.IDEActionFactory; +import org.eclipse.ui.part.MultiPageEditorActionBarContributor; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; + +/** + * Manages the installation/deinstallation of global actions for multi-page + * editors. Responsible for the redirection of global actions to the active + * editor. Multi-page contributor replaces the contributors for the individual + * editors in the multi-page editor. + */ +public class MavenPomEditorContributor extends MultiPageEditorActionBarContributor { + private MavenPomEditor editorPart; + + public void setActiveEditor(IEditorPart targetEditor) { + if (targetEditor instanceof MavenPomEditor) { + editorPart = (MavenPomEditor) targetEditor; + setActivePage(editorPart.getActiveEditor()); + } + } + + public void setActivePage(IEditorPart part) { + //set the text editor + IActionBars actionBars = getActionBars(); + if(editorPart !=null) { + if (actionBars != null) { + actionBars.clearGlobalActionHandlers(); + + // undo/redo always enabled + actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), // + getAction(ITextEditorActionConstants.UNDO)); + actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), // + getAction(ITextEditorActionConstants.REDO)); + + // all other action, for text editor only (FormPage doesn't provide for these actions...) + if (part instanceof ITextEditor) { + actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), // + getAction(ITextEditorActionConstants.DELETE)); + actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), // + getAction(ITextEditorActionConstants.CUT)); + actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), // + getAction(ITextEditorActionConstants.COPY)); + actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), // + getAction(ITextEditorActionConstants.PASTE)); + actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), // + getAction(ITextEditorActionConstants.SELECT_ALL)); + actionBars.setGlobalActionHandler(ActionFactory.FIND.getId(), // + getAction(ITextEditorActionConstants.FIND)); + actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), // + getAction(IDEActionFactory.BOOKMARK.getId())); + } + + actionBars.updateActionBars(); + } + } + + } + + /** + * Returns the action registered with the given text editor. + * + * @return IAction or null if editor is null. + */ + protected IAction getAction(String actionId) { + if(editorPart != null) { + try { + return editorPart.getSourcePage().getAction(actionId); + } catch (NullPointerException e) { + //editor has been disposed, ignore + } + } + return null; + } + +} 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 new file mode 100644 index 00000000..25a6dfa1 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorPage.java @@ -0,0 +1,620 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import static org.eclipse.m2e.editor.pom.FormUtils.isEmpty; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.Notifier; +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.edit.command.RemoveCommand; +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.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.actions.OpenPomAction; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.core.core.MavenLogger; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.MavenProjectManager; +import org.eclipse.m2e.core.ui.dialogs.InputHistory; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.internal.Messages; +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.swt.custom.CCombo; +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.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.editor.FormPage; +import org.eclipse.ui.forms.widgets.ScrolledForm; + + +/** + * This class provides basic page editor functionality (event listeners, readonly, etc) + * + * @author Anton Kraev + * @author Eugene Kuleshov + */ +public abstract class MavenPomEditorPage extends FormPage implements Adapter { + + // parent editor + protected final MavenPomEditor pomEditor; + + // model + protected Model model; + + // Notifier target + protected Notifier target; + + // are we already updating model + protected boolean updatingModel; + + // have we loaded data? + private boolean dataLoaded; + + private InputHistory inputHistory; + + protected static PomPackage POM_PACKAGE = PomPackage.eINSTANCE; + + protected Map<Object, List<ModifyListener>> modifyListeners = new HashMap<Object, List<ModifyListener>>(); + + public MavenPomEditorPage(MavenPomEditor pomEditor, String id, String title) { + super(pomEditor, id, title); + this.pomEditor = pomEditor; + this.inputHistory = new InputHistory(id); + } + + public MavenPomEditor getPomEditor() { + return pomEditor; + } + + @Override + protected void createFormContent(IManagedForm managedForm) { + ScrolledForm form = managedForm.getForm(); + IToolBarManager toolBarManager = form.getToolBarManager(); + +// toolBarManager.add(pomEditor.showAdvancedTabsAction); + + toolBarManager.add(new Action(Messages.MavenPomEditorPage_action_open, MavenEditorImages.PARENT_POM) { + public void run() { + // XXX listen to parent modification and accordingly enable/disable action + final Parent parent = model.getParent(); + if(parent!=null && !isEmpty(parent.getGroupId()) && !isEmpty(parent.getArtifactId()) && !isEmpty(parent.getVersion())) { + new Job(Messages.MavenPomEditorPage_job_opening) { + protected IStatus run(IProgressMonitor monitor) { + OpenPomAction.openEditor(parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), monitor); + return Status.OK_STATUS; + } + }.schedule(); + } + } + }); + + + toolBarManager.add(new Action(Messages.MavenPomEditorPage_actio_refresh, MavenEditorImages.REFRESH) { + public void run() { + pomEditor.reload(); + } + }); + + form.updateToolBar(); + + // compatibility proxy to support Eclipse 3.2 + FormUtils.decorateHeader(managedForm.getToolkit(), form.getForm()); + + inputHistory.load(); + } + + public void setActive(boolean active) { + super.setActive(active); + doLoadData(active); + + boolean readOnly = pomEditor.checkReadOnly(); + FormUtils.setReadonly((Composite) getPartControl(), readOnly); + } + + public boolean isReadOnly() { + return pomEditor.isReadOnly(); + } + + private void doLoadData(boolean active) { + if(active && !dataLoaded) { + dataLoaded = true; +// new Job("Loading pom.xml") { +// protected IStatus run(IProgressMonitor monitor) { + try { + model = pomEditor.readProjectDocument(); + if(model != null) { + if (getPartControl() != null) { + getPartControl().getDisplay().asyncExec(new Runnable() { + public void run() { + updatingModel = true; + try { + loadData(); + registerListeners(); + } catch(Throwable e) { + MavenLogger.log("Error loading data", e); //$NON-NLS-1$ + } finally { + updatingModel = false; + } + } + }); + } + } + + IFile pomFile = pomEditor.getPomFile(); + if(pomFile!=null) { + IMarker[] markers = pomFile.findMarkers(IMavenConstants.MARKER_ID, true, IResource.DEPTH_ZERO); + if(markers != null && markers.length > 0) { + int severity = markers[0].getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) == IMarker.SEVERITY_WARNING ? IMessageProvider.WARNING : IMessageProvider.ERROR; + setErrorMessage(markers[0].getAttribute(IMarker.MESSAGE, Messages.MavenPomEditorPage_error_unknown), severity); + } else { + setErrorMessage(null, IMessageProvider.NONE); + } + } + + } catch(final CoreException ex) { + MavenLogger.log(ex); + final String msg = ex.getMessage(); + setErrorMessage(msg, IMessageProvider.ERROR); + } + + } + } + + public void setErrorMessage(final String msg, final int severity) { + if(getPartControl()!=null && !getPartControl().isDisposed()) { + getPartControl().getDisplay().asyncExec(new Runnable() { + public void run() { + if (!getManagedForm().getForm().isDisposed()) { + + FormUtils.setMessage(getManagedForm().getForm(), msg, severity); + } + } + }); + } + } + + public Notifier getTarget() { + return target; + } + + public boolean isAdapterForType(Object type) { + return false; + } + + public void reload() { + deRegisterListeners(); + boolean oldDataLoaded = dataLoaded; + dataLoaded = false; + doLoadData(oldDataLoaded); + } + + public synchronized void notifyChanged(Notification notification) { + if(updatingModel) { + return; + } + + updatingModel = true; + try { + switch(notification.getEventType()) { + //TODO: fine-grained notification? + case Notification.ADD: + case Notification.MOVE: + case Notification.REMOVE: + case Notification.SET: + case Notification.UNSET: + case Notification.ADD_MANY: //this is for properties (clear/addAll is used for any properties update) + case Notification.REMOVE_MANY: + if (getManagedForm() != null) + updateView(notification); + break; + + default: + break; + + // case Notification.ADD_MANY: + // case Notification.REMOVE_MANY: + } + + } catch(Exception ex) { + MavenLogger.log("Can't update view", ex); //$NON-NLS-1$ + } finally { + updatingModel = false; + } + + registerListeners(); + } + + public void dispose() { + inputHistory.save(); + + deRegisterListeners(); + + for(Map.Entry<Object, List<ModifyListener>> e : modifyListeners.entrySet()) { + Object control = e.getKey(); + for(ModifyListener listener : e.getValue()) { + if(control instanceof Text) { + Text textControl = (Text) control; + if(!textControl.isDisposed()) { + textControl.removeModifyListener(listener); + } + } else if(control instanceof Combo) { + Combo comboControl = (Combo) control; + if(!comboControl.isDisposed()) { + comboControl.removeModifyListener(listener); + } + } else if(control instanceof CCombo) { + CCombo comboControl = (CCombo) control; + if(!comboControl.isDisposed()) { + comboControl.removeModifyListener(listener); + } + } else if(control instanceof Combo) { + Button buttonControl = (Button) control; + if(!buttonControl.isDisposed()) { + buttonControl.removeSelectionListener((SelectionListener) listener); + } + } + } + } + + super.dispose(); + } + + public void setTarget(Notifier newTarget) { + this.target = newTarget; + } + + public Model getModel() { + return model; + } + + public EditingDomain getEditingDomain() { + return pomEditor.getEditingDomain(); + } + + public abstract void loadData(); + + public abstract void updateView(Notification notification); + + public void registerListeners() { + if(model!=null) { + doRegister(model); + + for(Iterator<?> it = model.eAllContents(); it.hasNext();) { + Object next = it.next(); + if (next instanceof EObject) + doRegister((EObject) next); + } + } + } + + private void doRegister(EObject object) { + if (!object.eAdapters().contains(this)) { + object.eAdapters().add(this); + } + } + + public void deRegisterListeners() { + if(model!=null) { + model.eAdapters().remove(this); + for(Iterator<?> it = model.eAllContents(); it.hasNext(); ) { + Object next = it.next(); + if(next instanceof EObject) { + EObject object = (EObject) next; + object.eAdapters().remove(this); + } + } + } + } + + public <T> void setModifyListener(final Text textControl, ValueProvider<T> owner, EStructuralFeature feature, + String defaultValue) { + if(textControl!=null && !textControl.isDisposed()) { + List<ModifyListener> listeners = getModifyListeners(textControl); + for(ModifyListener listener : listeners) { + textControl.removeModifyListener(listener); + } + listeners.clear(); + ModifyListener listener = setModifyListener(new TextAdapter() { + public String getText() { + return textControl.getText(); + } + public void addModifyListener(ModifyListener listener) { + textControl.addModifyListener(listener); + } + }, owner, feature, defaultValue); + listeners.add(listener); + } + } + + public <T> void setModifyListener(final Combo control, ValueProvider<T> owner, EStructuralFeature feature) { + if(control!=null && !control.isDisposed()) { + List<ModifyListener> listeners = getModifyListeners(control); + for(ModifyListener listener : listeners) { + control.removeModifyListener(listener); + } + listeners.clear(); + ModifyListener listener = setModifyListener(new TextAdapter() { + public String getText() { + return control.getText(); + } + public void addModifyListener(ModifyListener listener) { + control.addModifyListener(listener); + } + }, owner, feature, null); + listeners.add(listener); + } + } + + public <T> void setModifyListener(final CCombo control, ValueProvider<T> owner, EStructuralFeature feature, + String defaultValue) { + if(control!=null && !control.isDisposed()) { + List<ModifyListener> listeners = getModifyListeners(control); + for(ModifyListener listener : listeners) { + control.removeModifyListener(listener); + } + listeners.clear(); + ModifyListener listener = setModifyListener(new TextAdapter() { + public String getText() { + return control.getText(); + } + public void addModifyListener(ModifyListener listener) { + control.addModifyListener(listener); + } + }, owner, feature, defaultValue); + listeners.add(listener); + } + } + + private <T> ModifyListener setModifyListener(final TextAdapter adapter, final ValueProvider<T> provider, + final EStructuralFeature feature, final String defaultValue) { + ModifyListener listener = new ModifyListener() { + public void modifyText(ModifyEvent e) { + T owner = provider.getValue(); + CompoundCommand compoundCommand = new CompoundCommand(); + if(owner==null && !provider.isEmpty()) { + owner = provider.create(getEditingDomain(), compoundCommand); + } + + Command command; + if(adapter.getText().equals(defaultValue) || isEmpty(adapter.getText())) { + command = SetCommand.create(getEditingDomain(), owner, feature, SetCommand.UNSET_VALUE); + } else { + command = SetCommand.create(getEditingDomain(), owner, feature, adapter.getText()); + } + compoundCommand.append(command); + //MNGECLIPSE-1854 + //the semantics of isEmpty() is probably not entirely correct for this context + // as it only takes the fields shown in ui into account, but there could be others, not + // managed by this valueprovider + if (provider.isEmpty() && owner != null) { + //in a way this stuff shall be recursive and remove everything that is empty all the way up.. + command = RemoveCommand.create(getEditingDomain(), owner); + compoundCommand.append(command); + } + getEditingDomain().getCommandStack().execute(compoundCommand); + registerListeners(); + } + }; + adapter.addModifyListener(listener); + return listener; + } + + public <T> void setModifyListener(final Button control, final ValueProvider<T> provider, + final EStructuralFeature feature, final String defaultValue) { + if(control!=null && !control.isDisposed()) { + List<ModifyListener> listeners = getModifyListeners(control); + for(ModifyListener listener : listeners) { + control.removeSelectionListener((SelectionListener) listener); + } + + listeners.clear(); + + class ButtonModifyListener extends SelectionAdapter implements ModifyListener { + public void widgetSelected(SelectionEvent e) { + T owner = provider.getValue(); + if(owner == null && !provider.isEmpty()) { + CompoundCommand compoundCommand = new CompoundCommand(); + provider.create(getEditingDomain(), compoundCommand); + getEditingDomain().getCommandStack().execute(compoundCommand); + owner = provider.getValue(); + } + + String value = control.getSelection() ? "true" : "false"; + Command command = SetCommand.create(getEditingDomain(), owner, feature, // + defaultValue.equals(value) ? null : value); + getEditingDomain().getCommandStack().execute(command); + registerListeners(); + } + + public void modifyText(ModifyEvent e) { + widgetSelected(null); + } + }; + + ButtonModifyListener listener = new ButtonModifyListener(); + control.addSelectionListener(listener); + + listeners.add(listener); + } + } + + public void removeNotifyListener(Text control) { + List<ModifyListener> listeners = getModifyListeners(control); + for(ModifyListener listener : listeners) { + if(!control.isDisposed()) { + control.removeModifyListener(listener); + } + } + listeners.clear(); + } + + public void removeNotifyListener(CCombo control) { + List<ModifyListener> listeners = getModifyListeners(control); + for(ModifyListener listener : listeners) { + if(!control.isDisposed()) { + control.removeModifyListener(listener); + } + } + listeners.clear(); + } + + public void removeNotifyListener(Combo control) { + List<ModifyListener> listeners = getModifyListeners(control); + for(ModifyListener listener : listeners) { + if(!control.isDisposed()) { + control.removeModifyListener(listener); + } + } + listeners.clear(); + } + + public void removeNotifyListener(Button button) { + List<ModifyListener> listeners = getModifyListeners(button); + for(ModifyListener listener : listeners) { + if(!button.isDisposed()) { + button.removeSelectionListener((SelectionAdapter) listener); + } + } + listeners.clear(); + } + + private List<ModifyListener> getModifyListeners(Object control) { + List<ModifyListener> listeners = modifyListeners.get(control); + if (listeners == null) { + listeners = new ArrayList<ModifyListener>(); + modifyListeners.put(control, listeners); + } + return listeners; + } + + public IMavenProjectFacade findModuleProject(String moduleName) { + IFile pomFile = pomEditor.getPomFile(); + if(pomFile != null) { + return findModuleProject(pomFile, moduleName); + } + return null; + } + + private IMavenProjectFacade findModuleProject(IFile pomFile, String module) { + IPath modulePath = pomFile.getParent().getLocation(); + if (modulePath == null) return null; + modulePath = modulePath.append(module); + //it's possible to have the pom file name in the module path.. + if (!modulePath.lastSegment().endsWith("pom.xml")) { //$NON-NLS-1$ + modulePath = modulePath.append("pom.xml"); //$NON-NLS-1$ + } + MavenProjectManager projectManager = MavenPlugin.getDefault().getMavenProjectManager(); + IMavenProjectFacade[] facades = projectManager.getProjects(); + for(int i = 0; i < facades.length; i++ ) { + if(facades[i].getPom().getLocation().equals(modulePath)) { + return facades[i]; + } + } + return null; + } + + public IFile findModuleFile(String moduleName) { + IFile pomFile = pomEditor.getPomFile(); + if(pomFile!=null) { + IPath modulePath = pomFile.getParent().getLocation(); + if (modulePath == null) return null; + modulePath = modulePath.append(moduleName); + //it's possible to have the pom file name in the module path.. + if (!modulePath.lastSegment().endsWith("pom.xml")) { //$NON-NLS-1$ + modulePath = modulePath.append("pom.xml"); //$NON-NLS-1$ + } + IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(modulePath); + return file; + } + return null; + } + + public void initPopupMenu(Viewer viewer, String id) { + MenuManager menuMgr = new MenuManager("#PopupMenu-" + id); //$NON-NLS-1$ + menuMgr.setRemoveAllWhenShown(true); + + Menu menu = menuMgr.createContextMenu(viewer.getControl()); + + viewer.getControl().setMenu(menu); + + getEditorSite().registerContextMenu(MavenPomEditor.EDITOR_ID + id, menuMgr, viewer, false); + } + + /* + * returns added/removed/updated EObject from notification (convenience method for detail forms) + */ + public static Object getFromNotification(Notification notification) { + if(notification.getFeature() != null && !(notification.getFeature() instanceof EAttribute)) { + // for structuralFeatures, return new value (for insert/delete) + return notification.getNewValue(); + } else { + // for attributes, return the notifier as it contains all new attributes (attribute modified) + return notification.getNotifier(); + } + } + + /** + * Adapter for Text, Combo and CCombo widgets + */ + public interface TextAdapter { + String getText(); + void addModifyListener(ModifyListener listener); + } + + public IProject getProject() { + IFile pomFile = pomEditor.getPomFile(); + return pomFile != null? pomFile.getProject(): null; + } + + protected void addToHistory(Control control) { + inputHistory.add(control); + } +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorPageFactory.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorPageFactory.java new file mode 100644 index 00000000..1560d66c --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditorPageFactory.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +/** + * A factory for creating POMeditor pages + * + * @author Eugene Kuleshov + */ +public abstract class MavenPomEditorPageFactory { + + public abstract void addPages(MavenPomEditor pomEditor); + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/ModulesLabelProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/ModulesLabelProvider.java new file mode 100644 index 00000000..3a1d3e48 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/ModulesLabelProvider.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import org.eclipse.core.resources.IFile; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.composites.StringLabelProvider; +import org.eclipse.swt.graphics.Image; + +public class ModulesLabelProvider extends StringLabelProvider { + + private final MavenPomEditorPage editorPage; + + public ModulesLabelProvider(MavenPomEditorPage editorPage) { + super(MavenEditorImages.IMG_JAR); + this.editorPage = editorPage; + } + + @Override + public Image getImage(Object element) { + if(element instanceof String) { + String moduleName = (String) element; + IMavenProjectFacade projectFacade = editorPage.findModuleProject(moduleName); + if(projectFacade!=null) { + return MavenEditorImages.IMG_PROJECT; + } + + IFile moduleFile = editorPage.findModuleFile(moduleName); + if(moduleFile!=null && moduleFile.isAccessible()) { + return MavenEditorImages.IMG_PROJECT; + } + } + return super.getImage(element); + } +}
\ No newline at end of file diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/NotificationCommandStack.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/NotificationCommandStack.java new file mode 100644 index 00000000..c389d7b4 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/NotificationCommandStack.java @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.emf.common.command.BasicCommandStack; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.command.RemoveCommand; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.jface.text.IUndoManager; + +/** + * @author Anton Kraev + */ +public class NotificationCommandStack extends BasicCommandStack { + + private MavenPomEditor editor; + private List<MavenPomEditorPage> pages; + private boolean isDirty = false; + + public NotificationCommandStack(MavenPomEditor editor) { + this.editor = editor; + this.pages = editor.getPages(); + } + + @Override + public void execute(Command command) { + processCommand(command, false); + + IUndoManager undoManager = editor.getSourcePage().getTextViewer().getUndoManager(); + undoManager.beginCompoundChange(); + try { + super.execute(command); + } finally { + undoManager.endCompoundChange(); + } + + processCommand(command, true); + fireDirty(); + } + + private void processCommand(Command command, boolean add) { + if (command instanceof CompoundCommand) { + CompoundCommand compoundCommand = (CompoundCommand) command; + Iterator<Command> commands = compoundCommand.getCommandList().iterator(); + while (commands.hasNext()) { + processCommand(commands.next(), add); + } + } + + if (command instanceof AddCommand) { + AddCommand addCommand = (AddCommand) command; + Iterator<?> it = addCommand.getCollection().iterator(); + while (it.hasNext()) { + processListeners(it.next(), add); + } + } + + if (command instanceof SetCommand) { + SetCommand setCommand = (SetCommand) command; + processListeners(setCommand.getValue(), add); + } + + if (command instanceof RemoveCommand) { + RemoveCommand removeCommand = (RemoveCommand) command; + Collection<?> collection = removeCommand.getCollection(); + if(collection!=null) { + Iterator<?> it = collection.iterator(); + while (it.hasNext()) { + Object next = it.next(); + if (next instanceof EObject) { + EObject object = (EObject) next; + for (int i=0; i<pages.size(); i++) { + object.eAdapters().remove(pages.get(i)); + } + } + } + } + } + } + + private void processListeners(Object next, boolean add) { + if (next instanceof EObject) { + EObject object = (EObject) next; + for (int i=0; i<pages.size(); i++) { + if (add) { + if (!object.eAdapters().contains(pages.get(i))) + object.eAdapters().add(pages.get(i)); + } else { + object.eAdapters().remove(pages.get(i)); + } + } + } + } + + @Override + public void redo() { + super.redo(); + fireDirty(); + } + + private void fireDirty() { + if (isDirty != isSaveNeeded()) { + editor.editorDirtyStateChanged(); + } + isDirty = isSaveNeeded(); + } + + @Override + public void undo() { + super.undo(); + fireDirty(); + } + +} 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 new file mode 100644 index 00000000..dc90abc6 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/OverviewPage.java @@ -0,0 +1,1442 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import static org.eclipse.m2e.editor.pom.FormUtils.isEmpty; +import static org.eclipse.m2e.editor.pom.FormUtils.nvl; +import static org.eclipse.m2e.editor.pom.FormUtils.setText; + +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.command.RemoveCommand; +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.viewers.ICellModifier; +import org.eclipse.jface.viewers.IColorProvider; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.IOpenListener; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.OpenEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.window.Window; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.m2e.core.MavenImages; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.actions.OpenPomAction; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.embedder.ProjectUpdater; +import org.eclipse.m2e.core.index.IIndex; +import org.eclipse.m2e.core.index.IndexedArtifactFile; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.ui.dialogs.MavenRepositorySearchDialog; +import org.eclipse.m2e.core.util.M2EUtils; +import org.eclipse.m2e.core.util.ProposalUtil; +import org.eclipse.m2e.core.util.search.Packaging; +import org.eclipse.m2e.core.wizards.MavenModuleWizard; +import org.eclipse.m2e.core.wizards.MavenProjectSelectionDialog; +import org.eclipse.m2e.core.wizards.WidthGroup; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.composites.ListEditorComposite; +import org.eclipse.m2e.editor.composites.ListEditorContentProvider; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.model.edit.pom.CiManagement; +import org.eclipse.m2e.model.edit.pom.IssueManagement; +import org.eclipse.m2e.model.edit.pom.Model; +import org.eclipse.m2e.model.edit.pom.Organization; +import org.eclipse.m2e.model.edit.pom.Parent; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.m2e.model.edit.pom.PomPackage; +import org.eclipse.m2e.model.edit.pom.PropertyElement; +import org.eclipse.m2e.model.edit.pom.Scm; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DropTargetAdapter; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.Transfer; +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.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.events.ExpansionAdapter; +import org.eclipse.ui.forms.events.ExpansionEvent; +import org.eclipse.ui.forms.events.HyperlinkAdapter; +import org.eclipse.ui.forms.events.HyperlinkEvent; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Hyperlink; +import org.eclipse.ui.forms.widgets.ScrolledForm; +import org.eclipse.ui.forms.widgets.Section; +import org.eclipse.ui.model.WorkbenchLabelProvider; +import org.eclipse.ui.part.FileEditorInput; +import org.eclipse.ui.part.ResourceTransfer; + + +/** + * @author Eugene Kuleshov + */ +public class OverviewPage extends MavenPomEditorPage { + + //controls + Text artifactIdText; + + Text artifactVersionText; + + Text artifactGroupIdText; + + CCombo artifactPackagingCombo; + + Text parentVersionText; + + Text parentArtifactIdText; + + Text parentGroupIdText; + + Text parentRelativePathText; + + Text projectUrlText; + + Text projectNameText; + + Text projectDescriptionText; + + Text inceptionYearText; + + Text organizationUrlText; + + Text organizationNameText; + + Text scmUrlText; + + Text scmDevConnectionText; + + Text scmConnectionText; + + Text scmTagText; + + CCombo issueManagementSystemCombo; + + CCombo issueManagementUrlCombo; + + CCombo ciManagementUrlCombo; + + CCombo ciManagementSystemCombo; + + ListEditorComposite<String> modulesEditor; + + PropertiesSection propertiesSection; + + Section modulesSection; + + Section parentSection; + + Section projectSection; + + Section organizationSection; + + Section scmSection; + + Section issueManagementSection; + + Section ciManagementSection; + +// private Action newModuleProjectAction; + + private Action newModuleElementAction; + + private Action parentSelectAction; + + private Action parentOpenAction; + + private StackLayout modulesStack; + + private Composite noModules; + + private Composite modulesSectionComposite; + + protected GridData projectSectionData; + + public OverviewPage(MavenPomEditor pomEditor) { + super(pomEditor, IMavenConstants.PLUGIN_ID + ".pom.overview", Messages.OverviewPage_title); //$NON-NLS-1$ + } + + protected void createFormContent(IManagedForm managedForm) { + FormToolkit toolkit = managedForm.getToolkit(); + ScrolledForm form = managedForm.getForm(); + form.setText(Messages.OverviewPage_form); + + Composite body = form.getBody(); + GridLayout gridLayout = new GridLayout(2, true); + gridLayout.horizontalSpacing = 7; + body.setLayout(gridLayout); + toolkit.paintBordersFor(body); + + Composite leftComposite = toolkit.createComposite(body, SWT.NONE); + leftComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + GridLayout leftCompositeLayout = new GridLayout(); + leftCompositeLayout.marginWidth = 0; + leftCompositeLayout.marginHeight = 0; + leftComposite.setLayout(leftCompositeLayout); + + WidthGroup leftWidthGroup = new WidthGroup(); + leftComposite.addControlListener(leftWidthGroup); + + createArtifactSection(toolkit, leftComposite, leftWidthGroup); + createParentsection(toolkit, leftComposite, leftWidthGroup); + createPropertiesSection(toolkit, leftComposite, leftWidthGroup); + createModulesSection(toolkit, leftComposite, leftWidthGroup); + + Composite rightComposite = toolkit.createComposite(body, SWT.NONE); + rightComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + GridLayout rightCompositeLayout = new GridLayout(); + rightCompositeLayout.marginWidth = 0; + rightCompositeLayout.marginHeight = 0; + rightComposite.setLayout(rightCompositeLayout); + + WidthGroup rightWidthGroup = new WidthGroup(); + rightComposite.addControlListener(rightWidthGroup); + + createProjectSection(toolkit, rightComposite, rightWidthGroup); + createOrganizationSection(toolkit, rightComposite, rightWidthGroup); + createScmSection(toolkit, rightComposite, rightWidthGroup); + createIssueManagementSection(toolkit, rightComposite, rightWidthGroup); + createCiManagementSection(toolkit, rightComposite, rightWidthGroup); + + toolkit.paintBordersFor(leftComposite); + toolkit.paintBordersFor(rightComposite); + + super.createFormContent(managedForm); + } + + private void createArtifactSection(FormToolkit toolkit, Composite composite, WidthGroup widthGroup) { + Section artifactSection = toolkit.createSection(composite, ExpandableComposite.TITLE_BAR); + artifactSection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + artifactSection.setText(Messages.OverviewPage_section_artifact); + + Composite artifactComposite = toolkit.createComposite(artifactSection, SWT.NONE); + toolkit.adapt(artifactComposite); + GridLayout gridLayout = new GridLayout(2, false); + gridLayout.marginBottom = 5; + gridLayout.marginHeight = 2; + gridLayout.marginWidth = 1; + artifactComposite.setLayout(gridLayout); + artifactSection.setClient(artifactComposite); + + Label groupIdLabel = toolkit.createLabel(artifactComposite, Messages.OverviewPage_lblGroupId, SWT.NONE); + + artifactGroupIdText = toolkit.createText(artifactComposite, null, SWT.NONE); + artifactGroupIdText.setData("name", "groupId"); //$NON-NLS-1$ //$NON-NLS-2$ + GridData gd_artifactGroupIdText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_artifactGroupIdText.horizontalIndent = 4; + artifactGroupIdText.setLayoutData(gd_artifactGroupIdText); + ProposalUtil.addGroupIdProposal(getProject(), artifactGroupIdText, Packaging.ALL); + + Label artifactIdLabel = toolkit.createLabel(artifactComposite, Messages.OverviewPage_lblArtifactId, SWT.NONE); + + artifactIdText = toolkit.createText(artifactComposite, null, SWT.NONE); + artifactIdText.setData("name", "artifactId"); //$NON-NLS-1$ //$NON-NLS-2$ + GridData gd_artifactIdText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_artifactIdText.horizontalIndent = 4; + artifactIdText.setLayoutData(gd_artifactIdText); + M2EUtils.addRequiredDecoration(artifactIdText); + + Label versionLabel = toolkit.createLabel(artifactComposite, Messages.OverviewPage_lblVersion, SWT.NONE); + + artifactVersionText = toolkit.createText(artifactComposite, null, SWT.NONE); + GridData gd_versionText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_versionText.horizontalIndent = 4; + gd_versionText.widthHint = 200; + artifactVersionText.setLayoutData(gd_versionText); + artifactVersionText.setData("name", "version"); //$NON-NLS-1$ //$NON-NLS-2$ + + Label packagingLabel = toolkit.createLabel(artifactComposite, Messages.OverviewPage_lblPackaging, SWT.NONE); + + artifactPackagingCombo = new CCombo(artifactComposite, SWT.FLAT); + + artifactPackagingCombo.add("jar"); //$NON-NLS-1$ + artifactPackagingCombo.add("war"); //$NON-NLS-1$ + artifactPackagingCombo.add("ejb"); //MNGECLIPSE-688 : add EAR & EJB Support //$NON-NLS-1$ + artifactPackagingCombo.add("ear"); //$NON-NLS-1$ + artifactPackagingCombo.add("pom"); //$NON-NLS-1$ + artifactPackagingCombo.add("maven-plugin"); //$NON-NLS-1$ +// uncomment this only if you are able to not to break the project +// artifactPackagingCombo.add("osgi-bundle"); +// artifactPackagingCombo.add("eclipse-feature"); + + toolkit.adapt(artifactPackagingCombo, true, true); + GridData gd_packagingText = new GridData(SWT.LEFT, SWT.CENTER, true, false); + gd_packagingText.horizontalIndent = 4; + gd_packagingText.widthHint = 120; + artifactPackagingCombo.setLayoutData(gd_packagingText); + artifactPackagingCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + artifactPackagingCombo.setData("name", "packaging"); //$NON-NLS-1$ //$NON-NLS-2$ + toolkit.paintBordersFor(artifactPackagingCombo); + + widthGroup.addControl(groupIdLabel); + widthGroup.addControl(artifactIdLabel); + widthGroup.addControl(versionLabel); + widthGroup.addControl(packagingLabel); + + toolkit.paintBordersFor(artifactComposite); + } + + private void createParentsection(FormToolkit toolkit, Composite composite, WidthGroup widthGroup) { + parentSection = toolkit.createSection(composite, // + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + parentSection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + parentSection.setText(Messages.OverviewPage_section_parent); + parentSection.setData("name", "parentSection"); //$NON-NLS-1$ //$NON-NLS-2$ + + parentSelectAction = new Action(Messages.OverviewPage_action_selectParent, MavenEditorImages.SELECT_ARTIFACT) { + public void run() { + // calculate current list of artifacts for the project - that's the current parent.. + Set<ArtifactKey> current = new HashSet<ArtifactKey>(); + String parentGroup = parentGroupIdText.getText(); + String parentArtifact = parentArtifactIdText.getText(); + String parentVersion = parentVersionText.getText(); + if (parentGroup != null && parentArtifact != null && parentVersion != null) { + current.add(new ArtifactKey(parentGroup, parentArtifact, parentVersion, null)); + } + MavenRepositorySearchDialog dialog = new MavenRepositorySearchDialog(getEditorSite().getShell(), // + Messages.OverviewPage_searchDialog_selectParent, IIndex.SEARCH_PARENTS, + current, Collections.<ArtifactKey>emptySet(), false); + if(parentGroup != null && parentGroup.trim().length() != 0) { + //chances are we will get good match by adding the groupid here.. + dialog.setQuery(parentGroupIdText.getText()); + } else if(artifactGroupIdText.getText() != null && artifactGroupIdText.getText().trim().length() != 0) { + //chances are we will get good match by adding the groupid here.. + dialog.setQuery(artifactGroupIdText.getText()); + } + if(dialog.open() == Window.OK) { + IndexedArtifactFile af = (IndexedArtifactFile) dialog.getFirstResult(); + if(af != null) { + String grid = nvl(af.group); + String ver = nvl(af.version); + parentGroupIdText.setText(grid); + parentArtifactIdText.setText(nvl(af.artifact)); + parentVersionText.setText(ver); + + //promote good practices -> + if(grid.equals(artifactGroupIdText.getText())) { + //if the groupId is the same, just remove it in child. + artifactGroupIdText.setText(""); //$NON-NLS-1$ + } + if(ver.equals(artifactVersionText.getText())) { + //if the version is the same, just remove it in child. + artifactVersionText.setText(""); //$NON-NLS-1$ + } + parentSection.setExpanded(true); + } + } + } + }; + parentSelectAction.setEnabled(false); + + parentOpenAction = new Action(Messages.OverviewPage_job_open, MavenEditorImages.PARENT_POM) { + public void run() { + final String groupId = parentGroupIdText.getText(); + final String artifactId = parentArtifactIdText.getText(); + final String version = parentVersionText.getText(); + new Job(NLS.bind(Messages.OverviewPage_job, new Object[] {groupId, artifactId, version})) { + protected IStatus run(IProgressMonitor monitor) { + OpenPomAction.openEditor(groupId, artifactId, version, monitor); + return Status.OK_STATUS; + } + }.schedule(); + } + }; + parentOpenAction.setEnabled(false); + + ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); + toolBarManager.add(parentOpenAction); + toolBarManager.add(parentSelectAction); + + Composite toolbarComposite = toolkit.createComposite(parentSection); + GridLayout toolbarLayout = new GridLayout(1, true); + toolbarLayout.marginHeight = 0; + toolbarLayout.marginWidth = 0; + toolbarComposite.setLayout(toolbarLayout); + toolbarComposite.setBackground(null); + + toolBarManager.createControl(toolbarComposite); + parentSection.setTextClient(toolbarComposite); + + Composite parentComposite = toolkit.createComposite(parentSection, SWT.NONE); + GridLayout gridLayout = new GridLayout(2, false); + gridLayout.marginBottom = 5; + gridLayout.marginWidth = 1; + gridLayout.marginHeight = 2; + parentComposite.setLayout(gridLayout); + parentSection.setClient(parentComposite); + + Label parentGroupIdLabel = toolkit.createLabel(parentComposite, Messages.OverviewPage_lblGroupId2, SWT.NONE); + + parentGroupIdText = toolkit.createText(parentComposite, null, SWT.NONE); + GridData gd_parentGroupIdText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_parentGroupIdText.horizontalIndent = 4; + parentGroupIdText.setLayoutData(gd_parentGroupIdText); + parentGroupIdText.setData("name", "parentGroupId"); //$NON-NLS-1$ //$NON-NLS-2$ + ProposalUtil.addGroupIdProposal(getProject(), parentGroupIdText, Packaging.POM); + M2EUtils.addRequiredDecoration(parentGroupIdText); + + final Label parentArtifactIdLabel = toolkit.createLabel(parentComposite, Messages.OverviewPage_lblArtifactId, + SWT.NONE); + + parentArtifactIdText = toolkit.createText(parentComposite, null, SWT.NONE); + GridData gd_parentArtifactIdText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_parentArtifactIdText.horizontalIndent = 4; + parentArtifactIdText.setLayoutData(gd_parentArtifactIdText); + parentArtifactIdText.setData("name", "parentArtifactId"); //$NON-NLS-1$ //$NON-NLS-2$ + ProposalUtil.addArtifactIdProposal(getProject(), parentGroupIdText, parentArtifactIdText, Packaging.POM); + M2EUtils.addRequiredDecoration(parentArtifactIdText); + + Label parentVersionLabel = toolkit.createLabel(parentComposite, Messages.OverviewPage_lblVersion2, SWT.NONE); + parentVersionLabel.setLayoutData(new GridData()); + + parentVersionText = toolkit.createText(parentComposite, null, SWT.NONE); + GridData parentVersionTextData = new GridData(SWT.LEFT, SWT.CENTER, true, false); + parentVersionTextData.horizontalIndent = 4; + parentVersionTextData.widthHint = 200; + parentVersionText.setLayoutData(parentVersionTextData); + parentVersionText.setData("name", "parentVersion"); //$NON-NLS-1$ //$NON-NLS-2$ + ProposalUtil.addVersionProposal(getProject(), parentGroupIdText, parentArtifactIdText, parentVersionText, + Packaging.POM); + M2EUtils.addRequiredDecoration(parentVersionText); + + ModifyListener ml = new ModifyListener() { + public void modifyText(ModifyEvent e) { + String text1 = parentArtifactIdText.getText().trim(); + String text2 = parentGroupIdText.getText().trim(); + String text3 = parentVersionText.getText().trim(); + if(text1.length() > 0 && text2.length() > 0 && text3.length() > 0) { + parentOpenAction.setEnabled(true); + } else { + parentOpenAction.setEnabled(false); + } + } + }; + parentArtifactIdText.addModifyListener(ml); + parentVersionText.addModifyListener(ml); + parentGroupIdText.addModifyListener(ml); + +// Button parentSelectButton = toolkit.createButton(parentComposite, "Select...", SWT.NONE); +// parentSelectButton.addSelectionListener(new SelectionAdapter() { +// public void widgetSelected(SelectionEvent e) { +// // TODO calculate current list of artifacts for the project +// Set<Artifact> artifacts = Collections.emptySet(); +// MavenRepositorySearchDialog dialog = new MavenRepositorySearchDialog(getEditorSite().getShell(), +// "Add Dependency", IndexManager.SEARCH_ARTIFACT, artifacts); +// if(dialog.open() == Window.OK) { +// IndexedArtifactFile af = (IndexedArtifactFile) dialog.getFirstResult(); +// if(af != null) { +// parentGroupIdText.setText(nvl(af.group)); +// parentArtifactIdText.setText(nvl(af.artifact)); +// parentVersionText.setText(nvl(af.version)); +// } +// } +// } +// }); + + Label parentRealtivePathLabel = toolkit.createLabel(parentComposite, Messages.OverviewPage_lblRelPath, SWT.NONE); + + parentRelativePathText = toolkit.createText(parentComposite, null, SWT.NONE); + GridData gd_parentRelativePathText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_parentRelativePathText.horizontalIndent = 4; + parentRelativePathText.setLayoutData(gd_parentRelativePathText); + parentRelativePathText.setData("name", "parentRelativePath"); //$NON-NLS-1$ //$NON-NLS-2$ + + widthGroup.addControl(parentGroupIdLabel); + widthGroup.addControl(parentArtifactIdLabel); + widthGroup.addControl(parentVersionLabel); + widthGroup.addControl(parentRealtivePathLabel); + + toolkit.paintBordersFor(parentComposite); + parentComposite.setTabList(new Control[] {parentGroupIdText, parentArtifactIdText, parentVersionText, + parentRelativePathText}); + } + + private void createPropertiesSection(FormToolkit toolkit, Composite composite, WidthGroup widthGroup) { + propertiesSection = new PropertiesSection(toolkit, composite, getEditingDomain()); + } + + private void createModulesSection(FormToolkit toolkit, Composite composite, WidthGroup widthGroup) { + // XXX should disable Modules actions based on artifact packaging and only add modules when packaging is "pom" + + modulesSection = toolkit.createSection(composite, // + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + modulesSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + modulesSection.setText(Messages.OverviewPage_section_modules); + modulesSection.setData("name", "modulesSection"); //$NON-NLS-1$ //$NON-NLS-2$ + + modulesSectionComposite = toolkit.createComposite(modulesSection); + modulesStack = new StackLayout(); + modulesSectionComposite.setLayout(modulesStack); + modulesSection.setClient(modulesSectionComposite); + + noModules = toolkit.createComposite(modulesSectionComposite); + noModules.setLayout(new GridLayout(1, false)); + + Label label = toolkit.createLabel(noModules, Messages.OverviewPage_msg_not_pom_packaging); + GridData gd_label = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1); + gd_label.verticalIndent = 12; + gd_label.horizontalIndent = 12; + label.setLayoutData(gd_label); + + modulesEditor = new ListEditorComposite<String>(modulesSectionComposite, SWT.NONE, true); + modulesEditor.getViewer().getTable().setData("name", "modulesEditor"); //$NON-NLS-1$ //$NON-NLS-2$ + toolkit.paintBordersFor(modulesEditor); + toolkit.adapt(modulesEditor); + + modulesEditor.setContentProvider(new ListEditorContentProvider<String>()); + modulesEditor.setLabelProvider(new ModulesLabelProvider(this)); + + modulesEditor.setOpenListener(new IOpenListener() { + public void open(OpenEvent openevent) { + final List<String> selection = modulesEditor.getSelection(); + new Job(Messages.OverviewPage_opening_editors) { + protected IStatus run(IProgressMonitor monitor) { + for(String module : selection) { + IMavenProjectFacade projectFacade = findModuleProject(module); + if(projectFacade != null) { + ArtifactKey key = projectFacade.getArtifactKey(); + OpenPomAction.openEditor(key.getGroupId(), key.getArtifactId(), key.getVersion(), monitor); + } else { + IFile modulePom = findModuleFile(module); + if(modulePom != null && modulePom.isAccessible()) { + OpenPomAction.openEditor(new FileEditorInput(modulePom), "pom.xml"); //$NON-NLS-1$ + } + } + } + return Status.OK_STATUS; + } + }.schedule(); + } + }); + + modulesEditor.setAddButtonListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + final Set<Object> moduleContainers = new HashSet<Object>(); + for(String module : model.getModules()) { + IMavenProjectFacade facade = findModuleProject(module); + if(facade != null) { + moduleContainers.add(facade.getProject().getLocation()); + } + IFile file = findModuleFile(module); + if(file != null) { + moduleContainers.add(file.getParent().getLocation()); + } + } + moduleContainers.add(getProject().getLocation()); + final boolean[] updateParentSection = new boolean[] {true}; + + MavenProjectSelectionDialog dialog = new MavenProjectSelectionDialog(getSite().getShell(), true) { + @Override + protected Control createDialogArea(Composite parent) { + Control control = super.createDialogArea(parent); + + final TreeViewer viewer = getViewer(); + viewer.setLabelProvider(new ProjectLabelProvider()); + viewer.getTree().addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + if(e.detail == SWT.CHECK) { + TreeItem item = (TreeItem) e.item; + Object data = item.getData(); + if(item.getChecked() && data instanceof IResource + && moduleContainers.contains(((IResource) data).getLocation())) { + item.setChecked(false); + } + } + } + }); + viewer.getTree().setFocus(); + + final Button checkbox = new Button((Composite) control, SWT.CHECK); + checkbox.setSelection(false); + checkbox.setText(Messages.OverviewPage_updateModulePoms); + checkbox.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateParentSection[0] = checkbox.getSelection(); + } + }); + + return control; + } + + class ProjectLabelProvider extends LabelProvider implements IColorProvider { + private ILabelProvider labelProvider = WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider(); + + @Override + public String getText(Object element) { + return labelProvider.getText(element); + } + + @Override + public Image getImage(Object element) { + return labelProvider.getImage(element); + } + + public Color getForeground(Object element) { + if(element instanceof IResource && moduleContainers.contains(((IResource) element).getLocation())) { + return Display.getDefault().getSystemColor(SWT.COLOR_GRAY); + } + return null; + } + + public Color getBackground(Object element) { + return null; + } + + } + }; + dialog.setTitle(Messages.OverviewPage_selectModuleProjects); + + if(dialog.open() == Window.OK) { + addSelectedModules(dialog.getResult(), updateParentSection[0]); + } + } + }); + + modulesEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + IEditorInput editorInput = OverviewPage.this.pomEditor.getEditorInput(); + if(editorInput instanceof FileEditorInput) { + MavenModuleWizard wizard = new MavenModuleWizard(true); + wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(((FileEditorInput) editorInput).getFile())); + WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard); + int res = dialog.open(); + if(res == Window.OK) { + createNewModule(wizard.getModuleName()); + } + } + } + }); + + modulesEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = getEditingDomain(); + + int n = 0; + for(String module : modulesEditor.getSelection()) { + Command removeCommand = RemoveCommand.create(editingDomain, model, POM_PACKAGE.getModel_Modules(), module); + compoundCommand.append(removeCommand); + n++ ; + } + //MNGECLIPSE-1850 this is a partial fix, have the remove commands executed separately and + // then remove the whole <modules> section. Unfortunately that one doesn't work. + editingDomain.getCommandStack().execute(compoundCommand); + if(model.getModules().size() == 0) { + Command removeModules = SetCommand.create(editingDomain, model, POM_PACKAGE.getModel_Modules(), null); + editingDomain.getCommandStack().execute(removeModules); + } + // modulesEditor.refresh(); + } + }); + + modulesEditor.setCellModifier(new ICellModifier() { + public boolean canModify(Object element, String property) { + return true; + } + + public Object getValue(Object element, String property) { + return element; + } + + public void modify(Object element, String property, Object value) { + int n = modulesEditor.getViewer().getTable().getSelectionIndex(); + EList<String> modules = model.getModules(); + if(!value.equals(modules.get(n))) { + EditingDomain editingDomain = getEditingDomain(); + Command command = SetCommand.create(editingDomain, model, // + POM_PACKAGE.getModel_Modules(), value, n); + editingDomain.getCommandStack().execute(command); + // modulesEditor.refresh(); + } + } + }); + + modulesEditor.getViewer().addDropSupport(DND.DROP_COPY | DND.DROP_LINK | DND.DROP_MOVE, + new Transfer[] {ResourceTransfer.getInstance()}, new DropTargetAdapter() { + @Override + public void dragEnter(DropTargetEvent event) { + event.detail = DND.DROP_LINK; + } + + @Override + public void dragOperationChanged(DropTargetEvent event) { + event.detail = DND.DROP_LINK; + } + + @Override + public void drop(DropTargetEvent event) { + if(event.data instanceof Object[]) { + addSelectedModules((Object[]) event.data, true); + } + } + }); + + newModuleElementAction = new Action(Messages.OverviewPage_action_newModuleElement, MavenImages.NEW_POM) { + public void run() { + createNewModule("?"); //$NON-NLS-1$ + } + }; + +// newModuleProjectAction = new Action(Messages.OverviewPage_action_new_module_project, MavenEditorImages.ADD_MODULE) { +// public void run() { +// IEditorInput editorInput = OverviewPage.this.pomEditor.getEditorInput(); +// if(editorInput instanceof FileEditorInput) { +// MavenModuleWizard wizard = new MavenModuleWizard(true); +// wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(((FileEditorInput) editorInput).getFile())); +// WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard); +// int res = dialog.open(); +// if(res == Window.OK) { +// createNewModule(wizard.getModuleName()); +// } +// } +// } +// }; + + ToolBarManager modulesToolBarManager = new ToolBarManager(SWT.FLAT); + modulesToolBarManager.add(newModuleElementAction); +// modulesToolBarManager.add(newModuleProjectAction); + + Composite toolbarComposite = toolkit.createComposite(modulesSection); + GridLayout toolbarLayout = new GridLayout(1, true); + toolbarLayout.marginHeight = 0; + toolbarLayout.marginWidth = 0; + toolbarComposite.setLayout(toolbarLayout); + toolbarComposite.setBackground(null); + + modulesToolBarManager.createControl(toolbarComposite); + modulesSection.setTextClient(toolbarComposite); + + modulesEditor.setReadOnly(pomEditor.isReadOnly()); + newModuleElementAction.setEnabled(!pomEditor.isReadOnly()); +// newModuleProjectAction.setEnabled(!pomEditor.isReadOnly()); + } + + // right side + + private void createProjectSection(FormToolkit toolkit, Composite composite, WidthGroup widthGroup) { + projectSection = toolkit.createSection(composite, // + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + projectSectionData = new GridData(SWT.FILL, SWT.FILL, true, true); + projectSection.setLayoutData(projectSectionData); + projectSection.setText(Messages.OverviewPage_section_project); + projectSection.setData("name", "projectSection"); //$NON-NLS-1$ //$NON-NLS-2$ + projectSection.addExpansionListener(new ExpansionAdapter() { + public void expansionStateChanged(ExpansionEvent e) { + projectSectionData.grabExcessVerticalSpace = e.getState(); + projectSection.getParent().layout(); + } + }); + + Composite projectComposite = toolkit.createComposite(projectSection, SWT.NONE); + projectComposite.setLayout(new GridLayout(2, false)); + projectSection.setClient(projectComposite); + + Label nameLabel = toolkit.createLabel(projectComposite, Messages.OverviewPage_lblName, SWT.NONE); + + projectNameText = toolkit.createText(projectComposite, null, SWT.NONE); + GridData gd_projectNameText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_projectNameText.widthHint = 150; + projectNameText.setLayoutData(gd_projectNameText); + projectNameText.setData("name", "projectName"); //$NON-NLS-1$ //$NON-NLS-2$ + + Hyperlink urlLabel = toolkit.createHyperlink(projectComposite, Messages.OverviewPage_lblUrl, SWT.NONE); + urlLabel.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + FormUtils.openHyperlink(projectUrlText.getText()); + } + }); + + projectUrlText = toolkit.createText(projectComposite, null, SWT.NONE); + GridData gd_projectUrlText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_projectUrlText.widthHint = 150; + projectUrlText.setLayoutData(gd_projectUrlText); + projectUrlText.setData("name", "projectUrl"); //$NON-NLS-1$ //$NON-NLS-2$ + + Label descriptionLabel = toolkit.createLabel(projectComposite, Messages.OverviewPage_lblDesc, SWT.NONE); + descriptionLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false)); + + projectDescriptionText = toolkit.createText(projectComposite, null, SWT.WRAP | SWT.V_SCROLL | SWT.MULTI); + GridData gd_descriptionText = new GridData(SWT.FILL, SWT.FILL, true, true); + gd_descriptionText.widthHint = 150; + gd_descriptionText.heightHint = 100; + gd_descriptionText.minimumHeight = 100; + projectDescriptionText.setLayoutData(gd_descriptionText); + projectDescriptionText.setData("name", "projectDescription"); //$NON-NLS-1$ //$NON-NLS-2$ + + Label inceptionYearLabel = toolkit.createLabel(projectComposite, Messages.OverviewPage_lblInception, SWT.NONE); + + inceptionYearText = toolkit.createText(projectComposite, null, SWT.NONE); + GridData gd_inceptionYearText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_inceptionYearText.widthHint = 150; + inceptionYearText.setLayoutData(gd_inceptionYearText); + inceptionYearText.setData("name", "projectInceptionYear"); //$NON-NLS-1$ //$NON-NLS-2$ + + widthGroup.addControl(nameLabel); + widthGroup.addControl(urlLabel); + widthGroup.addControl(descriptionLabel); + widthGroup.addControl(inceptionYearLabel); + + toolkit.paintBordersFor(projectComposite); + projectComposite.setTabList(new Control[] {projectNameText, projectUrlText, projectDescriptionText, + inceptionYearText}); + } + + private void createOrganizationSection(FormToolkit toolkit, Composite composite, WidthGroup widthGroup) { + organizationSection = toolkit.createSection(composite, // + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + organizationSection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); + organizationSection.setText(Messages.OverviewPage_section_org); + organizationSection.setData("name", "organizationSection"); //$NON-NLS-1$ //$NON-NLS-2$ + + Composite organizationComposite = toolkit.createComposite(organizationSection, SWT.NONE); + organizationComposite.setLayout(new GridLayout(2, false)); + organizationSection.setClient(organizationComposite); + + Label organizationNameLabel = toolkit.createLabel(organizationComposite, Messages.OverviewPage_lblName, SWT.NONE); + + organizationNameText = toolkit.createText(organizationComposite, null, SWT.NONE); + GridData gd_organizationNameText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_organizationNameText.widthHint = 150; + organizationNameText.setLayoutData(gd_organizationNameText); + organizationNameText.setData("name", "organizationName"); //$NON-NLS-1$ //$NON-NLS-2$ + + Hyperlink organizationUrlLabel = toolkit.createHyperlink(organizationComposite, Messages.OverviewPage_lblUrl, + SWT.NONE); + organizationUrlLabel.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + FormUtils.openHyperlink(organizationUrlText.getText()); + } + }); + + organizationUrlText = toolkit.createText(organizationComposite, null, SWT.NONE); + GridData gd_organizationUrlText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_organizationUrlText.widthHint = 150; + organizationUrlText.setLayoutData(gd_organizationUrlText); + organizationUrlText.setData("name", "organizationUrl"); //$NON-NLS-1$ //$NON-NLS-2$ + + widthGroup.addControl(organizationNameLabel); + widthGroup.addControl(organizationUrlLabel); + + toolkit.paintBordersFor(organizationComposite); + organizationComposite.setTabList(new Control[] {organizationNameText, organizationUrlText}); + } + + private void createScmSection(FormToolkit toolkit, Composite composite, WidthGroup widthGroup) { + scmSection = toolkit.createSection(composite, // + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + GridData gd_scmSection = new GridData(SWT.FILL, SWT.TOP, false, false); + scmSection.setLayoutData(gd_scmSection); + scmSection.setText(Messages.OverviewPage_section_scm); + scmSection.setData("name", "scmSection"); //$NON-NLS-1$ //$NON-NLS-2$ + + Composite scmComposite = toolkit.createComposite(scmSection, SWT.NONE); + scmComposite.setLayout(new GridLayout(2, false)); + scmSection.setClient(scmComposite); + + Hyperlink scmUrlLabel = toolkit.createHyperlink(scmComposite, Messages.OverviewPage_lblUrl, SWT.NONE); + scmUrlLabel.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + FormUtils.openHyperlink(scmUrlText.getText()); + } + }); + + scmUrlText = toolkit.createText(scmComposite, null, SWT.NONE); + GridData gd_scmUrlText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_scmUrlText.widthHint = 150; + scmUrlText.setLayoutData(gd_scmUrlText); + scmUrlText.setData("name", "scmUrl"); //$NON-NLS-1$ //$NON-NLS-2$ + + Label scmConnectionLabel = toolkit.createLabel(scmComposite, Messages.OverviewPage_lblConnection, SWT.NONE); + + scmConnectionText = toolkit.createText(scmComposite, null, SWT.NONE); + GridData gd_scmConnectionText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_scmConnectionText.widthHint = 150; + scmConnectionText.setLayoutData(gd_scmConnectionText); + scmConnectionText.setData("name", "scmConnection"); //$NON-NLS-1$ //$NON-NLS-2$ + + Label scmDevConnectionLabel = toolkit.createLabel(scmComposite, Messages.OverviewPage_lblDev, SWT.NONE); + + scmDevConnectionText = toolkit.createText(scmComposite, null, SWT.NONE); + GridData gd_scmDevConnectionText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_scmDevConnectionText.widthHint = 150; + scmDevConnectionText.setLayoutData(gd_scmDevConnectionText); + scmDevConnectionText.setData("name", "scmDevConnection"); //$NON-NLS-1$ //$NON-NLS-2$ + + Label scmTagLabel = toolkit.createLabel(scmComposite, Messages.OverviewPage_lblTag, SWT.NONE); + + scmTagText = toolkit.createText(scmComposite, null, SWT.NONE); + GridData gd_scmTagText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_scmTagText.widthHint = 150; + scmTagText.setLayoutData(gd_scmTagText); + scmTagText.setData("name", "scmTag"); //$NON-NLS-1$ //$NON-NLS-2$ + + widthGroup.addControl(scmUrlLabel); + widthGroup.addControl(scmConnectionLabel); + widthGroup.addControl(scmDevConnectionLabel); + widthGroup.addControl(scmTagLabel); + + toolkit.paintBordersFor(scmComposite); + } + + private void createIssueManagementSection(FormToolkit toolkit, Composite composite, WidthGroup widthGroup) { + issueManagementSection = toolkit.createSection(composite, // + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + issueManagementSection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); + issueManagementSection.setText(Messages.OverviewPage_section_issueMan); + issueManagementSection.setData("name", "issueManagementSection"); //$NON-NLS-1$ //$NON-NLS-2$ + + Composite issueManagementComposite = toolkit.createComposite(issueManagementSection, SWT.NONE); + issueManagementComposite.setLayout(new GridLayout(2, false)); + issueManagementSection.setClient(issueManagementComposite); + + Label issueManagementSystemLabel = toolkit.createLabel(issueManagementComposite, Messages.OverviewPage_lblSystem, + SWT.NONE); + + issueManagementSystemCombo = new CCombo(issueManagementComposite, SWT.FLAT); + GridData gd_issueManagementSystemText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_issueManagementSystemText.widthHint = 150; + issueManagementSystemCombo.setLayoutData(gd_issueManagementSystemText); + issueManagementSystemCombo.setData("name", "issueManagementSystem"); //$NON-NLS-1$ //$NON-NLS-2$ + issueManagementSystemCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + addToHistory(issueManagementSystemCombo); + toolkit.paintBordersFor(issueManagementSystemCombo); + toolkit.adapt(issueManagementSystemCombo, true, true); + + Hyperlink issueManagementUrlLabel = toolkit.createHyperlink(issueManagementComposite, Messages.OverviewPage_lblUrl, + SWT.NONE); + issueManagementUrlLabel.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + FormUtils.openHyperlink(issueManagementUrlCombo.getText()); + } + }); + + issueManagementUrlCombo = new CCombo(issueManagementComposite, SWT.FLAT); + GridData gd_issueManagementUrlText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_issueManagementUrlText.widthHint = 150; + issueManagementUrlCombo.setLayoutData(gd_issueManagementUrlText); + issueManagementUrlCombo.setData("name", "issueManagementUrl"); //$NON-NLS-1$ //$NON-NLS-2$ + issueManagementUrlCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + addToHistory(issueManagementUrlCombo); + toolkit.paintBordersFor(issueManagementUrlCombo); + toolkit.adapt(issueManagementUrlCombo, true, true); + + widthGroup.addControl(issueManagementSystemLabel); + widthGroup.addControl(issueManagementUrlLabel); + + toolkit.paintBordersFor(issueManagementComposite); + issueManagementComposite.setTabList(new Control[] {issueManagementSystemCombo, issueManagementUrlCombo}); + } + + private void createCiManagementSection(FormToolkit toolkit, Composite composite, WidthGroup widthGroup) { + ciManagementSection = toolkit.createSection(composite, // + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + ciManagementSection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); + ciManagementSection.setText(Messages.OverviewPage_section_ci); + ciManagementSection.setData("name", "continuousIntegrationSection"); //$NON-NLS-1$ //$NON-NLS-2$ + + Composite ciManagementComposite = toolkit.createComposite(ciManagementSection, SWT.NONE); + ciManagementComposite.setLayout(new GridLayout(2, false)); + ciManagementSection.setClient(ciManagementComposite); + + Label ciManagementSystemLabel = toolkit.createLabel(ciManagementComposite, Messages.OverviewPage_lblSystem, + SWT.NONE); + + ciManagementSystemCombo = new CCombo(ciManagementComposite, SWT.FLAT); + GridData gd_ciManagementSystemText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_ciManagementSystemText.widthHint = 150; + ciManagementSystemCombo.setLayoutData(gd_ciManagementSystemText); + ciManagementSystemCombo.setData("name", "ciManagementSystem"); //$NON-NLS-1$ //$NON-NLS-2$ + ciManagementSystemCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + addToHistory(ciManagementSystemCombo); + toolkit.paintBordersFor(ciManagementSystemCombo); + toolkit.adapt(ciManagementSystemCombo, true, true); + + Hyperlink ciManagementUrlLabel = toolkit.createHyperlink(ciManagementComposite, Messages.OverviewPage_lblUrl, + SWT.NONE); + ciManagementUrlLabel.addHyperlinkListener(new HyperlinkAdapter() { + public void linkActivated(HyperlinkEvent e) { + FormUtils.openHyperlink(ciManagementUrlCombo.getText()); + } + }); + + ciManagementUrlCombo = new CCombo(ciManagementComposite, SWT.FLAT); + GridData gd_ciManagementUrlText = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd_ciManagementUrlText.widthHint = 150; + ciManagementUrlCombo.setLayoutData(gd_ciManagementUrlText); + ciManagementUrlCombo.setData("name", "ciManagementUrl"); //$NON-NLS-1$ //$NON-NLS-2$ + ciManagementUrlCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + addToHistory(ciManagementUrlCombo); + toolkit.paintBordersFor(ciManagementUrlCombo); + toolkit.adapt(ciManagementUrlCombo, true, true); + + widthGroup.addControl(ciManagementSystemLabel); + widthGroup.addControl(ciManagementUrlLabel); + + toolkit.paintBordersFor(ciManagementComposite); + ciManagementComposite.setTabList(new Control[] {ciManagementSystemCombo, ciManagementUrlCombo}); + } + + protected void doUpdate(Notification notification) { + EObject object = (EObject) notification.getNotifier(); + Object feature = notification.getFeature(); + + if(object instanceof Model) { + loadThis(); + } + + if(object instanceof PropertyElement) { + propertiesSection.refresh(); + } + + Object notificationObject = getFromNotification(notification); + + if(feature == PomPackage.Literals.MODEL__PARENT + || (object instanceof Parent && (notificationObject == null || notificationObject instanceof Parent))) { + loadParent((Parent) notificationObject); + } + + if(feature == PomPackage.Literals.MODEL__ORGANIZATION + || (object instanceof Organization && (notificationObject == null || notificationObject instanceof Organization))) { + loadOrganization((Organization) notificationObject); + } + + if(feature == PomPackage.Literals.MODEL__SCM + || (object instanceof Scm && (notificationObject == null || notificationObject instanceof Scm))) { + loadScm((Scm) notificationObject); + } + + if(object instanceof CiManagement && (notificationObject == null || notificationObject instanceof CiManagement)) { + loadCiManagement((CiManagement) notificationObject); + } + + if(object instanceof IssueManagement + && (notificationObject == null || notificationObject instanceof IssueManagement)) { + loadIssueManagement((IssueManagement) notificationObject); + } + + if(feature == PomPackage.Literals.MODEL__MODULES) { + modulesEditor.refresh(); + } + + if(feature == PomPackage.Literals.MODEL__PROPERTIES) { + propertiesSection.setModel(model, POM_PACKAGE.getModel_Properties()); + } + } + + public void updateView(final Notification notification) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + doUpdate(notification); + } + }); + } + + public void loadData() { + Parent parent = model.getParent(); + Organization organization = model.getOrganization(); + Scm scm = model.getScm(); + IssueManagement issueManagement = model.getIssueManagement(); + CiManagement ciManagement = model.getCiManagement(); + + loadThis(); + loadParent(parent); + loadOrganization(organization); + loadScm(scm); + loadIssueManagement(issueManagement); + loadCiManagement(ciManagement); + loadModules(model.getModules()); + propertiesSection.setModel(model, POM_PACKAGE.getModel_Properties()); + + boolean expandProjectSection = !isEmpty(model.getName()) || !isEmpty(model.getDescription()) + || !isEmpty(model.getUrl()) || !isEmpty(model.getInceptionYear()); + projectSectionData.grabExcessVerticalSpace = expandProjectSection; + projectSection.setExpanded(expandProjectSection); + + parentSection.setExpanded(parent != null // + && (!isEmpty(parent.getGroupId()) || !isEmpty(parent.getArtifactId()) // + || !isEmpty(parent.getVersion()))); + + organizationSection.setExpanded(organization != null + && (!isEmpty(organization.getName()) || !isEmpty(organization.getUrl()))); + + scmSection.setExpanded(scm != null + && (!isEmpty(scm.getUrl()) || !isEmpty(scm.getConnection()) || !isEmpty(scm.getDeveloperConnection()))); + + ciManagementSection.setExpanded(ciManagement != null + && (!isEmpty(ciManagement.getSystem()) || !isEmpty(ciManagement.getUrl()))); + + issueManagementSection.setExpanded(issueManagement != null + && (!isEmpty(issueManagement.getSystem()) || !isEmpty(issueManagement.getUrl()))); + + propertiesSection.getSection().setExpanded(model.getProperties() != null && !model.getProperties().isEmpty()); + + // Modules modules = model.getModules(); + // modulesSection.setExpanded(modules !=null && modules.getModule().size()>0); + } + + private void loadThis() { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + removeNotifyListener(artifactGroupIdText); + removeNotifyListener(artifactIdText); + removeNotifyListener(artifactVersionText); + removeNotifyListener(artifactPackagingCombo); + + removeNotifyListener(projectNameText); + removeNotifyListener(projectDescriptionText); + removeNotifyListener(projectUrlText); + removeNotifyListener(inceptionYearText); + + setText(artifactGroupIdText, model.getGroupId()); + setText(artifactIdText, model.getArtifactId()); + setText(artifactVersionText, model.getVersion()); + setText(artifactPackagingCombo, "".equals(nvl(model.getPackaging())) ? "jar" : nvl(model.getPackaging())); //$NON-NLS-1$ //$NON-NLS-2$ + //show/hide modules section when packaging changes.. + loadModules(model.getModules()); + + setText(projectNameText, model.getName()); + setText(projectDescriptionText, model.getDescription()); + setText(projectUrlText, model.getUrl()); + setText(inceptionYearText, model.getInceptionYear()); + + ValueProvider<Model> modelProvider = new ValueProvider.DefaultValueProvider<Model>(model); + setModifyListener(artifactGroupIdText, modelProvider, POM_PACKAGE.getModel_GroupId(), ""); //$NON-NLS-1$ + setModifyListener(artifactIdText, modelProvider, POM_PACKAGE.getModel_ArtifactId(), ""); //$NON-NLS-1$ + setModifyListener(artifactVersionText, modelProvider, POM_PACKAGE.getModel_Version(), ""); //$NON-NLS-1$ + setModifyListener(artifactPackagingCombo, modelProvider, POM_PACKAGE.getModel_Packaging(), "jar"); //$NON-NLS-1$ + + setModifyListener(projectNameText, modelProvider, POM_PACKAGE.getModel_Name(), ""); //$NON-NLS-1$ + setModifyListener(projectDescriptionText, modelProvider, POM_PACKAGE.getModel_Description(), ""); //$NON-NLS-1$ + setModifyListener(projectUrlText, modelProvider, POM_PACKAGE.getModel_Url(), ""); //$NON-NLS-1$ + setModifyListener(inceptionYearText, modelProvider, POM_PACKAGE.getModel_InceptionYear(), ""); //$NON-NLS-1$ + } + }); + + } + + private void loadParent(Parent parent) { + removeNotifyListener(parentGroupIdText); + removeNotifyListener(parentArtifactIdText); + removeNotifyListener(parentVersionText); + removeNotifyListener(parentRelativePathText); + + if(parent != null) { + setText(parentGroupIdText, parent.getGroupId()); + setText(parentArtifactIdText, parent.getArtifactId()); + setText(parentVersionText, parent.getVersion()); + setText(parentRelativePathText, parent.getRelativePath()); + } else { + setText(parentGroupIdText, ""); //$NON-NLS-1$ + setText(parentArtifactIdText, ""); //$NON-NLS-1$ + setText(parentVersionText, ""); //$NON-NLS-1$ + setText(parentRelativePathText, ""); //$NON-NLS-1$ + } + +// parentGroupIdText.setEditable(!isReadOnly()); +// parentArtifactIdText.setEditable(!isReadOnly()); +// parentVersionText.setEditable(!isReadOnly()); +// parentRelativePathText.setEditable(!isReadOnly()); + parentSelectAction.setEnabled(!isReadOnly()); + parentOpenAction.setEnabled(parent != null); + + ValueProvider<Parent> parentProvider = new ValueProvider.ParentValueProvider<Parent>(parentGroupIdText, + parentArtifactIdText, parentVersionText, parentRelativePathText) { + public Parent getValue() { + return model.getParent(); + } + + public Parent create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + Parent parent = PomFactory.eINSTANCE.createParent(); + compoundCommand.append(SetCommand.create(editingDomain, model, POM_PACKAGE.getModel_Parent(), parent)); + return parent; + } + }; + setModifyListener(parentGroupIdText, parentProvider, POM_PACKAGE.getParent_GroupId(), ""); //$NON-NLS-1$ + setModifyListener(parentArtifactIdText, parentProvider, POM_PACKAGE.getParent_ArtifactId(), ""); //$NON-NLS-1$ + setModifyListener(parentVersionText, parentProvider, POM_PACKAGE.getParent_Version(), ""); //$NON-NLS-1$ + setModifyListener(parentRelativePathText, parentProvider, POM_PACKAGE.getParent_RelativePath(), ""); //$NON-NLS-1$ + } + + private void loadModules(EList<String> modules) { + modulesEditor.setInput(modules); + modulesEditor.setReadOnly(isReadOnly()); + if("pom".equals(model.getPackaging()) && modulesStack.topControl != modulesEditor) { //$NON-NLS-1$ + modulesStack.topControl = modulesEditor; + modulesSection.setExpanded(true); +// newModuleProjectAction.setEnabled(!isReadOnly()); + newModuleElementAction.setEnabled(!isReadOnly()); + } else if(!"pom".equals(model.getPackaging()) && modulesStack.topControl != noModules) { //$NON-NLS-1$ +// newModuleProjectAction.setEnabled(false); + newModuleElementAction.setEnabled(false); + modulesStack.topControl = noModules; + modulesSection.setExpanded(false); + } + modulesSectionComposite.layout(); + } + + private void loadOrganization(Organization organization) { + removeNotifyListener(organizationNameText); + removeNotifyListener(organizationUrlText); + + if(organization == null) { + setText(organizationNameText, ""); //$NON-NLS-1$ + setText(organizationUrlText, ""); //$NON-NLS-1$ + } else { + setText(organizationNameText, organization.getName()); + setText(organizationUrlText, organization.getUrl()); + } + + ValueProvider<Organization> organizationProvider = new ValueProvider.ParentValueProvider<Organization>( + organizationNameText, organizationUrlText) { + public Organization getValue() { + return model.getOrganization(); + } + + public Organization create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + Organization organization = PomFactory.eINSTANCE.createOrganization(); + compoundCommand.append(SetCommand.create(editingDomain, model, POM_PACKAGE.getModel_Organization(), // + organization)); + return organization; + } + }; + setModifyListener(organizationNameText, organizationProvider, POM_PACKAGE.getOrganization_Name(), ""); //$NON-NLS-1$ + setModifyListener(organizationUrlText, organizationProvider, POM_PACKAGE.getOrganization_Url(), ""); //$NON-NLS-1$ + } + + private void loadScm(Scm scm) { + removeNotifyListener(scmUrlText); + removeNotifyListener(scmConnectionText); + removeNotifyListener(scmDevConnectionText); + removeNotifyListener(scmTagText); + if(scm == null) { + setText(scmUrlText, ""); //$NON-NLS-1$ + setText(scmConnectionText, ""); //$NON-NLS-1$ + setText(scmDevConnectionText, ""); //$NON-NLS-1$ + setText(scmTagText, ""); //$NON-NLS-1$ + } else { + setText(scmUrlText, scm.getUrl()); + setText(scmConnectionText, scm.getConnection()); + setText(scmDevConnectionText, scm.getDeveloperConnection()); + setText(scmTagText, scm.getTag()); + } + + ValueProvider<Scm> scmProvider = new ValueProvider.ParentValueProvider<Scm>(scmUrlText, scmConnectionText, + scmDevConnectionText, scmTagText) { + public Scm getValue() { + return model.getScm(); + } + + public Scm create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + Scm scm = PomFactory.eINSTANCE.createScm(); + compoundCommand.append(SetCommand.create(editingDomain, model, POM_PACKAGE.getModel_Scm(), scm)); + return scm; + } + }; + setModifyListener(scmUrlText, scmProvider, POM_PACKAGE.getScm_Url(), ""); //$NON-NLS-1$ + setModifyListener(scmConnectionText, scmProvider, POM_PACKAGE.getScm_Connection(), ""); //$NON-NLS-1$ + setModifyListener(scmDevConnectionText, scmProvider, POM_PACKAGE.getScm_DeveloperConnection(), ""); //$NON-NLS-1$ + setModifyListener(scmTagText, scmProvider, POM_PACKAGE.getScm_Tag(), ""); //$NON-NLS-1$ + } + + private void loadCiManagement(CiManagement ciManagement) { + removeNotifyListener(ciManagementUrlCombo); + removeNotifyListener(ciManagementSystemCombo); + + if(ciManagement == null) { + setText(ciManagementSystemCombo, ""); //$NON-NLS-1$ + setText(ciManagementUrlCombo, ""); //$NON-NLS-1$ + } else { + setText(ciManagementSystemCombo, ciManagement.getSystem()); + setText(ciManagementUrlCombo, ciManagement.getUrl()); + } + + ValueProvider<CiManagement> ciManagementProvider = new ValueProvider.ParentValueProvider<CiManagement>( + ciManagementUrlCombo, ciManagementSystemCombo) { + public CiManagement getValue() { + return model.getCiManagement(); + } + + public CiManagement create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + CiManagement ciManagement = PomFactory.eINSTANCE.createCiManagement(); + compoundCommand.append(SetCommand.create(editingDomain, model, POM_PACKAGE.getModel_CiManagement(), // + ciManagement)); + return ciManagement; + } + }; + setModifyListener(ciManagementUrlCombo, ciManagementProvider, POM_PACKAGE.getCiManagement_Url(), ""); //$NON-NLS-1$ + setModifyListener(ciManagementSystemCombo, ciManagementProvider, POM_PACKAGE.getCiManagement_System(), ""); //$NON-NLS-1$ + } + + private void loadIssueManagement(IssueManagement issueManagement) { + removeNotifyListener(issueManagementUrlCombo); + removeNotifyListener(issueManagementSystemCombo); + + if(issueManagement == null) { + setText(issueManagementSystemCombo, ""); //$NON-NLS-1$ + setText(issueManagementUrlCombo, ""); //$NON-NLS-1$ + } else { + setText(issueManagementSystemCombo, issueManagement.getSystem()); + setText(issueManagementUrlCombo, issueManagement.getUrl()); + } + + ValueProvider<IssueManagement> issueManagementProvider = new ValueProvider.ParentValueProvider<IssueManagement>( + issueManagementUrlCombo, issueManagementSystemCombo) { + public IssueManagement getValue() { + return model.getIssueManagement(); + } + + public IssueManagement create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + IssueManagement issueManagement = PomFactory.eINSTANCE.createIssueManagement(); + compoundCommand.append(SetCommand.create(editingDomain, model, POM_PACKAGE.getModel_IssueManagement(), // + issueManagement)); + return issueManagement; + } + }; + setModifyListener(issueManagementUrlCombo, issueManagementProvider, POM_PACKAGE.getIssueManagement_Url(), ""); //$NON-NLS-1$ + setModifyListener(issueManagementSystemCombo, issueManagementProvider, POM_PACKAGE.getIssueManagement_System(), ""); //$NON-NLS-1$ + } + + protected void createNewModule(String moduleName) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = getEditingDomain(); + + Command addModule = AddCommand.create(editingDomain, model, POM_PACKAGE.getModel_Modules(), moduleName); + compoundCommand.append(addModule); + + editingDomain.getCommandStack().execute(compoundCommand); + modulesEditor.setInput(model.getModules()); + } + + protected void addSelectedModules(Object[] result, boolean updateParentSection) { + String groupId = model.getGroupId(); + if(groupId == null) { + Parent parent = model.getParent(); + if(parent != null) { + groupId = parent.getGroupId(); + } + } + + String version = model.getVersion(); + if(version == null) { + Parent parent = model.getParent(); + if(parent != null) { + version = parent.getVersion(); + } + } + + final String parentGroupId = groupId; + final String parentArtifactId = model.getArtifactId(); + final String parentVersion = version; + final IPath projectPath = getProject().getLocation(); + + for(Object selection : result) { + IContainer container = null; + IFile pomFile = null; + + if(selection instanceof IFile) { + pomFile = (IFile) selection; + if(!IMavenConstants.POM_FILE_NAME.equals(pomFile.getName())) { + continue; + } + container = pomFile.getParent(); + } else if(selection instanceof IContainer && !selection.equals(getProject())) { + container = (IContainer) selection; + pomFile = container.getFile(new Path(IMavenConstants.POM_FILE_NAME)); + } + + if(pomFile == null || !pomFile.exists() || container == null) { + continue; + } + + IPath resultPath = container.getLocation(); + String path = resultPath.makeRelativeTo(projectPath).toString(); + + if(!model.getModules().contains(path)) { + if(updateParentSection) { + final String relativePath = projectPath.makeRelativeTo(resultPath).toString(); + MavenPlugin.getDefault().getMavenModelManager().updateProject(pomFile, new ProjectUpdater() { + public void update(Model model) { + Parent parent = model.getParent(); + if(parent == null) { + parent = PomFactory.eINSTANCE.createParent(); + model.setParent(parent); + } + parent.setGroupId(parentGroupId); + parent.setArtifactId(parentArtifactId); + parent.setVersion(parentVersion); + parent.setRelativePath(relativePath); + + if(model.getGroupId() == null || model.getGroupId().equals(parentGroupId)) { + model.setGroupId(null); + + if(model.getVersion() != null && model.getVersion().equals(parentVersion)) { + model.setVersion(null); + } + } + } + }); + } + + createNewModule(path); + } + } + } + + private boolean checkDrop() { + return true; + } +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PluginsPage.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PluginsPage.java new file mode 100644 index 00000000..42268e45 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PluginsPage.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.editor.composites.PluginsComposite; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.model.edit.pom.Build; +import org.eclipse.m2e.model.edit.pom.BuildBase; +import org.eclipse.m2e.model.edit.pom.PluginManagement; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.ScrolledForm; + +/** + * @author Eugene Kuleshov + */ +public class PluginsPage extends MavenPomEditorPage { + + private PluginsComposite pluginsComposite; + private SearchControl searchControl; + + public PluginsPage(MavenPomEditor pomEditor) { + super(pomEditor, IMavenConstants.PLUGIN_ID + ".pom.plugins", Messages.PluginsPage_title); //$NON-NLS-1$ + } + + public void dispose() { + if(pluginsComposite != null) { + pluginsComposite.dispose(); + } + super.dispose(); + } + + public void setActive(boolean active) { + super.setActive(active); + if(active) { + pluginsComposite.setSearchControl(searchControl); + searchControl.getSearchText().setEditable(true); + } + } + + protected void createFormContent(IManagedForm managedForm) { + FormToolkit toolkit = managedForm.getToolkit(); + ScrolledForm form = managedForm.getForm(); + form.setText(Messages.PluginsPage_form); + + Composite body = form.getBody(); + toolkit.paintBordersFor(body); + GridLayout gridLayout = new GridLayout(1, true); + gridLayout.marginHeight = 0; + body.setLayout(gridLayout); + + pluginsComposite = new PluginsComposite(body, this, SWT.NONE); + pluginsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + toolkit.adapt(pluginsComposite); + + searchControl = new SearchControl(Messages.PluginsPage_find, managedForm); + + IToolBarManager pageToolBarManager = form.getForm().getToolBarManager(); + pageToolBarManager.add(searchControl); + pageToolBarManager.add(new Separator()); + + form.updateToolBar(); + +// form.pack(); + + super.createFormContent(managedForm); + } + + public void loadData() { + ValueProvider<BuildBase> buildProvider = new ValueProvider<BuildBase>() { + public BuildBase getValue() { + BuildBase build = model.getBuild(); + return build; + } + + public BuildBase create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + Build build = model.getBuild(); + if(build==null) { + build = PomFactory.eINSTANCE.createBuild(); + Command command = SetCommand.create(editingDomain, model, POM_PACKAGE.getModel_Build(), build); + compoundCommand.append(command); + } + + return build; + } + }; + + ValueProvider<PluginManagement> pluginManagementProvider = new ValueProvider<PluginManagement>() { + public PluginManagement getValue() { + Build build = model.getBuild(); + PluginManagement management = build == null ? null : build.getPluginManagement(); + return management; + } + + public PluginManagement create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + Build build = model.getBuild(); + if(build == null) { + build = PomFactory.eINSTANCE.createBuild(); + Command command = SetCommand.create(editingDomain, model, POM_PACKAGE.getModel_Build(), build); + compoundCommand.append(command); + } + + PluginManagement management = build.getPluginManagement(); + if(management == null) { + management = PomFactory.eINSTANCE.createPluginManagement(); + Command command = SetCommand.create(editingDomain, build, // + POM_PACKAGE.getBuildBase_PluginManagement(), management); + compoundCommand.append(command); + } + + return management; + } + }; + + pluginsComposite.loadData(this, buildProvider, pluginManagementProvider); + } + + public void updateView(final Notification notification) { + Display.getDefault().asyncExec(new Runnable(){ + public void run(){ + pluginsComposite.updateView(PluginsPage.this, notification); + } + }); + + } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PomEditorPreferencePage.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PomEditorPreferencePage.java new file mode 100644 index 00000000..8e8f7189 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PomEditorPreferencePage.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.core.Messages; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +public class PomEditorPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + public static final String P_DEFAULT_POM_EDITOR_PAGE = "eclipse.m2.defaultPomEditorPage"; //$NON-NLS-1$ + public static final String P_SHOW_ADVANCED_TABS = "eclipse.m2.showAdvancedTabs"; //$NON-NLS-1$ + + final MavenPlugin plugin; + private Composite parent; + + public PomEditorPreferencePage() { + super(GRID); + setPreferenceStore(MavenPlugin.getDefault().getPreferenceStore()); + + plugin = MavenPlugin.getDefault(); + } + + public void init(IWorkbench workbench) { + } + + /* + * Creates the field editors. Field editors are abstractions of the common GUI + * blocks needed to manipulate various types of preferences. Each field editor + * knows how to save and restore itself. + */ + public void createFieldEditors() { + parent = getFieldEditorParent(); + addField(new BooleanFieldEditor(P_DEFAULT_POM_EDITOR_PAGE, Messages.getString("pomEditor.defaultPage"), parent)); //$NON-NLS-1$ +// addField(new BooleanFieldEditor(P_SHOW_ADVANCED_TABS, Messages.getString("pomEditor.showAdvancedTabs"), parent)); //$NON-NLS-1$ + } +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/ProfilesPage.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/ProfilesPage.java new file mode 100644 index 00000000..4fe1fbee --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/ProfilesPage.java @@ -0,0 +1,933 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import static org.eclipse.m2e.editor.pom.FormUtils.isEmpty; +import static org.eclipse.m2e.editor.pom.FormUtils.setButton; +import static org.eclipse.m2e.editor.pom.FormUtils.setText; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.command.RemoveCommand; +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.IAction; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.viewers.ICellModifier; +import org.eclipse.jface.viewers.IOpenListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.OpenEvent; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.window.Window; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.m2e.core.actions.OpenPomAction; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.wizards.MavenModuleWizard; +import org.eclipse.m2e.core.wizards.WidthGroup; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.composites.BuildComposite; +import org.eclipse.m2e.editor.composites.DependenciesComposite; +import org.eclipse.m2e.editor.composites.ListEditorComposite; +import org.eclipse.m2e.editor.composites.ListEditorContentProvider; +import org.eclipse.m2e.editor.composites.PluginsComposite; +import org.eclipse.m2e.editor.composites.ReportingComposite; +import org.eclipse.m2e.editor.composites.RepositoriesComposite; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.model.edit.pom.Activation; +import org.eclipse.m2e.model.edit.pom.ActivationFile; +import org.eclipse.m2e.model.edit.pom.ActivationOS; +import org.eclipse.m2e.model.edit.pom.ActivationProperty; +import org.eclipse.m2e.model.edit.pom.BuildBase; +import org.eclipse.m2e.model.edit.pom.DependencyManagement; +import org.eclipse.m2e.model.edit.pom.DistributionManagement; +import org.eclipse.m2e.model.edit.pom.PluginManagement; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.m2e.model.edit.pom.PomPackage; +import org.eclipse.m2e.model.edit.pom.Profile; +import org.eclipse.m2e.model.edit.pom.Reporting; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.custom.CTabItem; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +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.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.ScrolledForm; +import org.eclipse.ui.forms.widgets.Section; +import org.eclipse.ui.part.FileEditorInput; + +/** + * @author Eugene Kuleshov + */ +public class ProfilesPage extends MavenPomEditorPage { + + // controls + Button activeByDefaultbutton; + Text activationFileMissingText; + Text activationFileExistText; + Text activationPropertyValueText; + Text activationPropertyNameText; + Text activationOsVersionText; + Text activationOsArchitectureText; + Text activationOsFamilyText; + Text activationOsNameText; + Text activationJdkText; + ListEditorComposite<Profile> profilesEditor; + ListEditorComposite<String> modulesEditor; + Section modulesSection; + PropertiesSection propertiesSection; + + CTabFolder tabFolder; + BuildComposite buildComposite; + PluginsComposite pluginsComposite; + DependenciesComposite dependenciesComposite; + RepositoriesComposite repositoriesComposite; + ReportingComposite reportingComposite; + + Color defaultForegroundColor; + Color defaultSelectionColor; + Color disabledTabColor = Display.getDefault().getSystemColor(SWT.COLOR_GRAY); + + // model + Profile currentProfile; + private IAction newModuleProjectAction; + + public ProfilesPage(MavenPomEditor pomEditor) { + super(pomEditor, IMavenConstants.PLUGIN_ID + ".pom.profiles", Messages.ProfilesPage_title); //$NON-NLS-1$ + } + + protected void createFormContent(IManagedForm managedForm) { + FormToolkit toolkit = managedForm.getToolkit(); + ScrolledForm form = managedForm.getForm(); + form.setText(Messages.ProfilesPage_form); + // form.setExpandHorizontal(true); + + Composite body = form.getBody(); + GridLayout gridLayout = new GridLayout(2, true); + gridLayout.horizontalSpacing = 7; + body.setLayout(gridLayout); + toolkit.paintBordersFor(body); + + createProfilesSection(toolkit, body); + + createModulesSection(toolkit, body); + createPropertiesSection(toolkit, body); + + tabFolder = new CTabFolder(body, SWT.FLAT | SWT.MULTI); + GridData tabFolderData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); + tabFolderData.verticalIndent = 5; + tabFolder.setLayoutData(tabFolderData); + toolkit.adapt(tabFolder, true, true); + + toolkit.getColors().initializeSectionToolBarColors(); + Color selectedColor = toolkit.getColors().getColor("org.eclipse.ui.forms.TB_BG"); //$NON-NLS-1$ + tabFolder.setSelectionBackground(new Color[] {selectedColor, toolkit.getColors().getBackground()}, // + new int[] {100}, true); + defaultForegroundColor = tabFolder.getForeground(); + defaultSelectionColor = tabFolder.getSelectionForeground(); + + tabFolder.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + // updateTabSelection(); + } + }); + + createActivationTab(tabFolder, toolkit); + createDependenciesTab(tabFolder, toolkit); + createRepositoriesTab(toolkit, tabFolder); + createBuildTab(toolkit, tabFolder); + createPluginsTab(toolkit, tabFolder); + createReportsTab(toolkit, tabFolder); + + tabFolder.setSelection(0); + +// form.pack(); + + super.createFormContent(managedForm); + } + + private void createProfilesSection(FormToolkit toolkit, Composite body) { + Section profilesSection = toolkit.createSection(body, ExpandableComposite.TITLE_BAR); + profilesSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 3)); + profilesSection.setText(Messages.ProfilesPage_section_profiles); + profilesEditor = new ListEditorComposite<Profile>(profilesSection, SWT.NONE); + profilesSection.setClient(profilesEditor); + toolkit.adapt(profilesEditor); + toolkit.paintBordersFor(profilesEditor); + + profilesEditor.setContentProvider(new ListEditorContentProvider<Profile>()); + profilesEditor.setLabelProvider(new LabelProvider() { + public String getText(Object element) { + if(element instanceof Profile) { + String profileId = ((Profile) element).getId(); + return isEmpty(profileId) ? "?" : profileId; + } + return super.getText(element); + } + + public Image getImage(Object element) { + return MavenEditorImages.IMG_PROFILE; + } + }); + + profilesEditor.addSelectionListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + List<Profile> selection = profilesEditor.getSelection(); + updateProfileDetails(selection.size()==1 ? selection.get(0) : null); + } + }); + + profilesEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = getEditingDomain(); + + boolean created = false; + + Profile profile = PomFactory.eINSTANCE.createProfile(); + Command addCommand = AddCommand.create(editingDomain, model, POM_PACKAGE.getModel_Profiles(), profile); + compoundCommand.append(addCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + + profilesEditor.setSelection(Collections.singletonList(profile)); + } + }); + + profilesEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = getEditingDomain(); + + List<Profile> selection = profilesEditor.getSelection(); + for(Profile filter : selection) { + Command removeCommand = RemoveCommand.create(editingDomain, model, // + POM_PACKAGE.getModel_Profiles(), filter); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + } + }); + + profilesEditor.setCellModifier(new ICellModifier() { + public boolean canModify(Object element, String property) { + return true; + } + public Object getValue(Object element, String property) { + if(element instanceof Profile) { + String id = ((Profile) element).getId(); + return isEmpty(id) ? "" : id; //$NON-NLS-1$ + } + return ""; //$NON-NLS-1$ + } + + public void modify(Object element, String property, Object value) { + int n = profilesEditor.getViewer().getTable().getSelectionIndex(); + Profile profile = model.getProfiles().get(n); + if(!value.equals(profile.getId())) { + EditingDomain editingDomain = getEditingDomain(); + Command command = SetCommand.create(editingDomain, profile, POM_PACKAGE.getProfile_Id(), value); + editingDomain.getCommandStack().execute(command); + profilesEditor.refresh(); + } + } + }); + + + profilesEditor.setReadOnly(pomEditor.isReadOnly()); + } + + private void createPropertiesSection(FormToolkit toolkit, Composite body) { + propertiesSection = new PropertiesSection(toolkit, body, getEditingDomain()); + } + + private void createModulesSection(FormToolkit toolkit, Composite body) { + modulesSection = toolkit.createSection(body, // + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + modulesSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 2)); + modulesSection.setText(Messages.ProfilesPage_section_modules); + + modulesEditor = new ListEditorComposite<String>(modulesSection, SWT.NONE); + modulesEditor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + modulesSection.setClient(modulesEditor); + toolkit.adapt(modulesEditor); + toolkit.paintBordersFor(modulesEditor); + + modulesEditor.setContentProvider(new ListEditorContentProvider<String>()); + modulesEditor.setLabelProvider(new ModulesLabelProvider(this)); + + modulesEditor.setOpenListener(new IOpenListener() { + public void open(OpenEvent openevent) { + List<String> selection = modulesEditor.getSelection(); + for(String module : selection) { + IMavenProjectFacade projectFacade = findModuleProject(module); + if(projectFacade!=null) { + ArtifactKey mavenProject = projectFacade.getArtifactKey(); + OpenPomAction.openEditor(mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion(), null); + } + } + } + }); + + modulesEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + createNewModule("?"); + } + }); + + modulesEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = getEditingDomain(); + + List<String> selection = modulesEditor.getSelection(); + for(String module : selection) { + Command removeCommand = RemoveCommand.create(editingDomain, currentProfile, // + POM_PACKAGE.getProfile_Modules(), module); + compoundCommand.append(removeCommand); + } + + editingDomain.getCommandStack().execute(compoundCommand); + } + }); + + modulesEditor.setCellModifier(new ICellModifier() { + public boolean canModify(Object element, String property) { + return true; + } + + public Object getValue(Object element, String property) { + return element; + } + + public void modify(Object element, String property, Object value) { + int n = modulesEditor.getViewer().getTable().getSelectionIndex(); + EList<String> modules = currentProfile.getModules(); + if(n >= 0 && n < modules.size() && !value.equals(modules.get(n))) { + EditingDomain editingDomain = getEditingDomain(); + Command command = SetCommand.create(editingDomain, currentProfile, POM_PACKAGE.getProfile_Modules(), value, n); + editingDomain.getCommandStack().execute(command); + modulesEditor.refresh(); + } + } + }); + + newModuleProjectAction = new Action(Messages.ProfilesPage_action_newModuleProject, MavenEditorImages.ADD_MODULE) { + public void run() { + IEditorInput editorInput = pomEditor.getEditorInput(); + if(editorInput instanceof FileEditorInput) { + MavenModuleWizard wizard = new MavenModuleWizard(true); + wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(((FileEditorInput) editorInput).getFile())); + WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard); + int res = dialog.open(); + if(res == Window.OK) { + createNewModule(wizard.getModuleName()); + } + } + } + }; + + ToolBarManager modulesToolBarManager = new ToolBarManager(SWT.FLAT); + modulesToolBarManager.add(newModuleProjectAction); + + Composite toolbarComposite = toolkit.createComposite(modulesSection); + GridLayout toolbarLayout = new GridLayout(1, true); + toolbarLayout.marginHeight = 0; + toolbarLayout.marginWidth = 0; + toolbarComposite.setLayout(toolbarLayout); + toolbarComposite.setBackground(null); + + modulesToolBarManager.createControl(toolbarComposite); + modulesSection.setTextClient(toolbarComposite); + + modulesEditor.setReadOnly(pomEditor.isReadOnly()); + newModuleProjectAction.setEnabled(!pomEditor.isReadOnly()); + + } + + protected void updateProfileDetails(Profile profile) { + currentProfile = profile; + + if(profile==null) { + FormUtils.setEnabled(propertiesSection.getSection(), false); + FormUtils.setEnabled(modulesSection, false); + modulesEditor.setInput(null); + updateProfileTabs(profile); + + return; + } + + FormUtils.setEnabled(propertiesSection.getSection(), true); + FormUtils.setEnabled(modulesSection, true); + + FormUtils.setReadonly(propertiesSection.getSection(), isReadOnly()); + FormUtils.setReadonly(modulesSection, isReadOnly()); + + modulesEditor.setInput(profile.getModules()); + modulesEditor.setReadOnly(isReadOnly()); + + propertiesSection.setModel(profile, POM_PACKAGE.getProfile_Properties()); + + updateProfileTabs(profile); + } + + private void updateProfileTabs(Profile profile) { + if(profile==null) { + FormUtils.setEnabled(tabFolder, false); + tabFolder.setForeground(disabledTabColor); + tabFolder.setSelectionForeground(disabledTabColor); + } else { + FormUtils.setEnabled(tabFolder, true); + FormUtils.setReadonly(tabFolder, isReadOnly()); + tabFolder.setForeground(defaultForegroundColor); + tabFolder.setSelectionForeground(defaultSelectionColor); + } + + updateActivationTab(); + updateDependenciesTab(); + updateRepositoriesTab(); + updateBuildTab(); + updatePluginsTab(); + updateReportsTab(); + } + + private void updateActivationTab() { + removeNotifyListener(activeByDefaultbutton); + removeNotifyListener(activationJdkText); + removeNotifyListener(activationPropertyNameText); + removeNotifyListener(activationPropertyValueText); + removeNotifyListener(activationFileExistText); + removeNotifyListener(activationFileMissingText); + removeNotifyListener(activationOsArchitectureText); + removeNotifyListener(activationOsFamilyText); + removeNotifyListener(activationOsNameText); + removeNotifyListener(activationOsVersionText); + + Activation activation = currentProfile == null ? null : currentProfile.getActivation(); + if(activation == null) { + setButton(activeByDefaultbutton, false); + setText(activationJdkText, ""); //$NON-NLS-1$ + + setText(activationPropertyNameText, ""); //$NON-NLS-1$ + setText(activationPropertyValueText, ""); //$NON-NLS-1$ + + setText(activationFileExistText, ""); //$NON-NLS-1$ + setText(activationFileMissingText, ""); //$NON-NLS-1$ + + setText(activationOsArchitectureText, ""); //$NON-NLS-1$ + setText(activationOsFamilyText, ""); //$NON-NLS-1$ + setText(activationOsNameText, ""); //$NON-NLS-1$ + setText(activationOsVersionText, ""); //$NON-NLS-1$ + + } else { + setButton(activeByDefaultbutton, "true".equals(activation.getActiveByDefault())); + setText(activationJdkText, activation.getJdk()); + + ActivationProperty property = activation.getProperty(); + if(property==null) { + setText(activationPropertyNameText, ""); //$NON-NLS-1$ + setText(activationPropertyValueText, ""); //$NON-NLS-1$ + } else { + setText(activationPropertyNameText, property.getName()); + setText(activationPropertyValueText, property.getValue()); + } + + ActivationFile file = activation.getFile(); + if(file==null) { + setText(activationFileExistText, ""); //$NON-NLS-1$ + setText(activationFileMissingText, ""); //$NON-NLS-1$ + } else { + setText(activationFileExistText, file.getExists()); + setText(activationFileMissingText, file.getMissing()); + } + + ActivationOS os = activation.getOs(); + if(os==null) { + setText(activationOsArchitectureText, ""); //$NON-NLS-1$ + setText(activationOsFamilyText, ""); //$NON-NLS-1$ + setText(activationOsNameText, ""); //$NON-NLS-1$ + setText(activationOsVersionText, ""); //$NON-NLS-1$ + } else { + setText(activationOsArchitectureText, os.getArch()); + setText(activationOsFamilyText, os.getFamily()); + setText(activationOsNameText, os.getName()); + setText(activationOsVersionText, os.getVersion()); + } + } + + ValueProvider<Activation> activationProvider = new ValueProvider<Activation>() { + public Activation getValue() { + return currentProfile.getActivation(); + } + public Activation create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + return createActivation(editingDomain, compoundCommand); + } + }; + setModifyListener(activeByDefaultbutton, activationProvider, POM_PACKAGE.getActivation_ActiveByDefault(), "false"); + setModifyListener(activationJdkText, activationProvider, POM_PACKAGE.getActivation_Jdk(), ""); //$NON-NLS-1$ + + ValueProvider<ActivationProperty> activationPropertyProvider = new ValueProvider<ActivationProperty>() { + public ActivationProperty getValue() { + Activation activation = currentProfile.getActivation(); + return activation==null ? null : activation.getProperty(); + } + public ActivationProperty create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + Activation activation = createActivation(editingDomain, compoundCommand); + ActivationProperty activationProperty = activation.getProperty(); + if(activationProperty == null) { + activationProperty = PomFactory.eINSTANCE.createActivationProperty(); + compoundCommand.append(SetCommand.create(editingDomain, activation, POM_PACKAGE.getActivation_Property(), + activationProperty)); + } + return activationProperty; + } + }; + setModifyListener(activationPropertyNameText, activationPropertyProvider, POM_PACKAGE.getActivationProperty_Name(), ""); //$NON-NLS-1$ + setModifyListener(activationPropertyValueText, activationPropertyProvider, POM_PACKAGE.getActivationProperty_Value(), ""); //$NON-NLS-1$ + + ValueProvider<ActivationFile> activationFileProvider = new ValueProvider<ActivationFile>() { + public ActivationFile getValue() { + Activation activation = currentProfile.getActivation(); + return activation==null ? null : activation.getFile(); + } + public ActivationFile create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + Activation activation = createActivation(editingDomain, compoundCommand); + ActivationFile activationFile = activation.getFile(); + if(activationFile == null) { + activationFile = PomFactory.eINSTANCE.createActivationFile(); + compoundCommand.append(SetCommand.create(editingDomain, activation, POM_PACKAGE.getActivation_File(), + activationFile)); + } + return activationFile; + } + }; + setModifyListener(activationFileExistText, activationFileProvider, POM_PACKAGE.getActivationFile_Exists(), ""); //$NON-NLS-1$ + setModifyListener(activationFileMissingText, activationFileProvider, POM_PACKAGE.getActivationFile_Missing(), ""); //$NON-NLS-1$ + + ValueProvider<ActivationOS> activationOsProvider = new ValueProvider<ActivationOS>() { + public ActivationOS getValue() { + Activation activation = currentProfile.getActivation(); + return activation==null ? null : activation.getOs(); + } + public ActivationOS create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + Activation activation = createActivation(editingDomain, compoundCommand); + ActivationOS activationOS = activation.getOs(); + if(activationOS == null) { + activationOS = PomFactory.eINSTANCE.createActivationOS(); + compoundCommand.append(SetCommand.create(editingDomain, activation, POM_PACKAGE.getActivation_Os(), + activationOS)); + } + return activationOS; + } + }; + setModifyListener(activationOsArchitectureText, activationOsProvider, POM_PACKAGE.getActivationOS_Arch(), ""); //$NON-NLS-1$ + setModifyListener(activationOsFamilyText, activationOsProvider, POM_PACKAGE.getActivationOS_Family(), ""); //$NON-NLS-1$ + setModifyListener(activationOsNameText, activationOsProvider, POM_PACKAGE.getActivationOS_Name(), ""); //$NON-NLS-1$ + setModifyListener(activationOsVersionText, activationOsProvider, POM_PACKAGE.getActivationOS_Version(), ""); //$NON-NLS-1$ + + registerListeners(); + } + + Activation createActivation(EditingDomain editingDomain, CompoundCommand compoundCommand) { + Activation activation = currentProfile.getActivation(); + if(activation == null) { + activation = PomFactory.eINSTANCE.createActivation(); + compoundCommand.append(SetCommand.create(editingDomain, currentProfile, POM_PACKAGE.getProfile_Activation(), + activation)); + } + return activation; + } + + private void updateDependenciesTab() { + ValueProvider<DependencyManagement> dependencyManagementProvider = new ValueProvider<DependencyManagement>() { + public DependencyManagement getValue() { + DependencyManagement management = currentProfile == null ? null : currentProfile.getDependencyManagement(); + return management; + } + + public DependencyManagement create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + DependencyManagement management = currentProfile.getDependencyManagement(); + if(management == null) { + management = PomFactory.eINSTANCE.createDependencyManagement(); + Command command = SetCommand.create(editingDomain, currentProfile, // + POM_PACKAGE.getProfile_DependencyManagement(), management); + compoundCommand.append(command); + } + + return management; + } + }; + + dependenciesComposite.loadData(model, dependencyManagementProvider); + } + + private void updateRepositoriesTab() { + ValueProvider<DistributionManagement> dmProvider = new ValueProvider<DistributionManagement>() { + public DistributionManagement getValue() { + return currentProfile==null ? null : currentProfile.getDistributionManagement(); + } + + public DistributionManagement create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + DistributionManagement dm = PomFactory.eINSTANCE.createDistributionManagement(); + Command command = SetCommand.create(editingDomain, currentProfile, // + POM_PACKAGE.getProfile_DistributionManagement(), dm); + compoundCommand.append(command); + return dm; + } + }; + + repositoriesComposite.loadData(this, model, dmProvider); + } + + private void updateBuildTab() { + ValueProvider<BuildBase> buildProvider = new ValueProvider<BuildBase>() { + public BuildBase getValue() { + return currentProfile == null ? null : currentProfile.getBuild(); + } + + public BuildBase create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + BuildBase buildBase = PomFactory.eINSTANCE.createBuildBase(); + Command command = SetCommand.create(editingDomain, currentProfile, POM_PACKAGE.getProfile_Build(), buildBase); + compoundCommand.append(command); + return buildBase; + } + }; + buildComposite.loadData(this, buildProvider); + } + + private void updatePluginsTab() { + ValueProvider<BuildBase> buildProvider = new ValueProvider<BuildBase>() { + public BuildBase getValue() { + BuildBase build = currentProfile == null ? null : currentProfile.getBuild(); + return build; + } + + public BuildBase create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + BuildBase build = currentProfile.getBuild(); + if(build == null) { + build = PomFactory.eINSTANCE.createBuild(); + Command command = SetCommand.create(editingDomain, currentProfile, POM_PACKAGE.getProfile_Build(), build); + compoundCommand.append(command); + } + + return build; + } + }; + + ValueProvider<PluginManagement> pluginManagementProvider = new ValueProvider<PluginManagement>() { + public PluginManagement getValue() { + BuildBase build = currentProfile == null ? null : currentProfile.getBuild(); + PluginManagement management = build == null ? null : build.getPluginManagement(); + return management; + } + + public PluginManagement create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + BuildBase build = currentProfile.getBuild(); + if(build == null) { + build = PomFactory.eINSTANCE.createBuild(); + Command command = SetCommand.create(editingDomain, currentProfile, POM_PACKAGE.getProfile_Build(), build); + compoundCommand.append(command); + } + + PluginManagement management = build.getPluginManagement(); + if(management == null) { + management = PomFactory.eINSTANCE.createPluginManagement(); + Command command = SetCommand.create(editingDomain, build, // + POM_PACKAGE.getBuildBase_PluginManagement(), management); + compoundCommand.append(command); + } + + return management; + } + }; + + pluginsComposite.loadData(this, buildProvider, pluginManagementProvider); + } + + private void updateReportsTab() { + ValueProvider<Reporting> reportingProvider = new ValueProvider<Reporting>() { + + public Reporting getValue() { + return currentProfile==null ? null : currentProfile.getReporting(); + } + + public Reporting create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + Reporting reporting = currentProfile.getReporting(); + if(reporting == null) { + reporting = PomFactory.eINSTANCE.createReporting(); + Command command = SetCommand.create(editingDomain, currentProfile, POM_PACKAGE.getProfile_Reporting(), reporting); + compoundCommand.append(command); + } + return reporting; + } + }; + + reportingComposite.loadData(this, reportingProvider); + } + + private void createBuildTab(FormToolkit toolkit, CTabFolder tabFolder) { + CTabItem buildTabItem = new CTabItem(tabFolder, SWT.NONE); + buildTabItem.setText(Messages.ProfilesPage_tab_build); + + buildComposite = new BuildComposite(tabFolder, SWT.NONE); + buildTabItem.setControl(buildComposite); + toolkit.adapt(buildComposite); + } + + private void createPluginsTab(FormToolkit toolkit, CTabFolder tabFolder) { + CTabItem pluginsTabItem = new CTabItem(tabFolder, SWT.NONE); + pluginsTabItem.setText(Messages.ProfilesPage_tab_plugins); + + pluginsComposite = new PluginsComposite(tabFolder, this, SWT.NONE); + pluginsTabItem.setControl(pluginsComposite); + toolkit.adapt(pluginsComposite); + } + + private void createDependenciesTab(CTabFolder tabFolder, FormToolkit toolkit) { + CTabItem dependenciesTabItem = new CTabItem(tabFolder, SWT.NONE); + dependenciesTabItem.setText(Messages.ProfilesPage_tab_dependencies); + + dependenciesComposite = new DependenciesComposite(tabFolder, this, SWT.NONE, pomEditor); + dependenciesTabItem.setControl(dependenciesComposite); + toolkit.adapt(dependenciesComposite); + } + + private void createRepositoriesTab(FormToolkit toolkit, CTabFolder tabFolder) { + CTabItem repositoriesTabItem = new CTabItem(tabFolder, SWT.NONE); + repositoriesTabItem.setText(Messages.ProfilesPage_tab_repositories); + + repositoriesComposite = new RepositoriesComposite(tabFolder, SWT.NONE); + repositoriesTabItem.setControl(repositoriesComposite); + toolkit.adapt(repositoriesComposite); + } + + private void createReportsTab(FormToolkit toolkit, CTabFolder tabFolder) { + CTabItem reportingTabItem = new CTabItem(tabFolder, SWT.NONE); + reportingTabItem.setText(Messages.ProfilesPage_tab_reporting); + + reportingComposite = new ReportingComposite(tabFolder, this, SWT.NONE); + toolkit.adapt(reportingComposite); + reportingTabItem.setControl(reportingComposite); + } + + private void createActivationTab(CTabFolder tabFolder, FormToolkit toolkit) { + CTabItem activationTabItem = new CTabItem(tabFolder, SWT.NONE); + activationTabItem.setText(Messages.ProfilesPage_tab_activation); + + Composite activationComposite = new Composite(tabFolder, SWT.NONE); + toolkit.paintBordersFor(activationComposite); + GridLayout activationLayout = new GridLayout(2, false); + activationLayout.marginWidth = 0; + activationComposite.setLayout(activationLayout); + activationTabItem.setControl(activationComposite); + toolkit.adapt(activationComposite); + + activeByDefaultbutton = toolkit.createButton(activationComposite, Messages.ProfilesPage_btnActivateByDefault, SWT.CHECK); + activeByDefaultbutton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); + + Section propertySection = toolkit.createSection(activationComposite, ExpandableComposite.TITLE_BAR); + propertySection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + propertySection.setText(Messages.ProfilesPage_section_property); + + Composite propertyComposite = toolkit.createComposite(propertySection, SWT.NONE); + GridLayout propertyLayout = new GridLayout(2, false); + propertyLayout.marginHeight = 2; + propertyLayout.marginWidth = 1; + propertyComposite.setLayout(propertyLayout); + propertySection.setClient(propertyComposite); + toolkit.paintBordersFor(propertyComposite); + + Label propertyNameLabel = toolkit.createLabel(propertyComposite, Messages.ProfilesPage_lblName, SWT.NONE); + + activationPropertyNameText = toolkit.createText(propertyComposite, null, SWT.NONE); + activationPropertyNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + Label propertyValueLabel = toolkit.createLabel(propertyComposite, Messages.ProfilesPage_lblValue, SWT.NONE); + + activationPropertyValueText = toolkit.createText(propertyComposite, null, SWT.NONE); + activationPropertyValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + Section osSection = toolkit.createSection(activationComposite, ExpandableComposite.TITLE_BAR); + osSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 3)); + osSection.setText(Messages.ProfilesPage_section_os); + + Composite osComposite = new Composite(osSection, SWT.NONE); + GridLayout osLayout = new GridLayout(2, false); + osLayout.marginWidth = 1; + osLayout.marginHeight = 2; + osComposite.setLayout(osLayout); + toolkit.paintBordersFor(osComposite); + toolkit.adapt(osComposite); + osSection.setClient(osComposite); + + toolkit.createLabel(osComposite, Messages.ProfilesPage_lblName, SWT.NONE); + + activationOsNameText = toolkit.createText(osComposite, null, SWT.NONE); + activationOsNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + toolkit.createLabel(osComposite, Messages.ProfilesPage_lblFamily, SWT.NONE); + + activationOsFamilyText = toolkit.createText(osComposite, null, SWT.NONE); + activationOsFamilyText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + toolkit.createLabel(osComposite, Messages.ProfilesPage_lblArchitecture, SWT.NONE); + + activationOsArchitectureText = toolkit.createText(osComposite, null, SWT.NONE); + activationOsArchitectureText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + toolkit.createLabel(osComposite, Messages.ProfilesPage_lblVersion, SWT.NONE); + + activationOsVersionText = toolkit.createText(osComposite, null, SWT.NONE); + activationOsVersionText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + Section fileSection = toolkit.createSection(activationComposite, ExpandableComposite.TITLE_BAR); + GridData fileGridData = new GridData(SWT.FILL, SWT.TOP, false, false); + fileGridData.verticalIndent = 5; + fileSection.setLayoutData(fileGridData); + fileSection.setText(Messages.ProfilesPage_section_file); + + Composite fileComposite = toolkit.createComposite(fileSection, SWT.NONE); + GridLayout fileCompositeLayout = new GridLayout(); + fileCompositeLayout.marginWidth = 1; + fileCompositeLayout.marginHeight = 2; + fileCompositeLayout.numColumns = 2; + fileComposite.setLayout(fileCompositeLayout); + toolkit.paintBordersFor(fileComposite); + fileSection.setClient(fileComposite); + + Label fileExistLabel = toolkit.createLabel(fileComposite, Messages.ProfilesPage_lblExists, SWT.NONE); + + activationFileExistText = toolkit.createText(fileComposite, null, SWT.NONE); + activationFileExistText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + Label fileMissingLabel = toolkit.createLabel(fileComposite, Messages.ProfilesPage_lblMissing, SWT.NONE); + + activationFileMissingText = toolkit.createText(fileComposite, null, SWT.NONE); + activationFileMissingText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + Section jdkSection = toolkit.createSection(activationComposite, ExpandableComposite.TITLE_BAR); + jdkSection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + jdkSection.setText(Messages.ProfilesPage_section_jdk); + + Composite composite = toolkit.createComposite(jdkSection, SWT.NONE); + GridLayout gridLayout = new GridLayout(); + gridLayout.marginHeight = 2; + gridLayout.marginWidth = 1; + gridLayout.numColumns = 2; + composite.setLayout(gridLayout); + toolkit.paintBordersFor(composite); + jdkSection.setClient(composite); + + Label jdkLabel = toolkit.createLabel(composite, Messages.ProfilesPage_lblJdk, SWT.NONE); + + activationJdkText = toolkit.createText(composite, null, SWT.NONE); + activationJdkText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + WidthGroup widthGroup = new WidthGroup(); + activationComposite.addControlListener(widthGroup); + widthGroup.addControl(propertyNameLabel); + widthGroup.addControl(propertyValueLabel); + widthGroup.addControl(fileExistLabel); + widthGroup.addControl(fileMissingLabel); + widthGroup.addControl(jdkLabel); + } + + public void loadData() { + profilesEditor.setInput(model.getProfiles()); + } + + protected void doUpdate(Notification notification){ + Object object = notification.getNotifier(); + Object feature = notification.getFeature(); + + if(feature == PomPackage.Literals.MODEL__PROFILES) { + profilesEditor.refresh(); + } + + if(object instanceof Profile) { + profilesEditor.refresh(); + if(currentProfile == object) + updateProfileDetails((Profile) object); + } + + if(feature == PomPackage.Literals.PROFILE__MODULES) { + modulesEditor.refresh(); + } + + if(object instanceof Activation) { + EObject container = ((Activation) object).eContainer(); + if(container==currentProfile) { + updateActivationTab(); + } + } + + if(object instanceof ActivationFile || object instanceof ActivationOS || object instanceof ActivationProperty) { + Activation activation = (Activation) ((EObject) object).eContainer(); + EObject container = activation.eContainer(); + if(container == currentProfile) { + updateActivationTab(); + } + } + dependenciesComposite.updateView(this, notification); + repositoriesComposite.updateView(this, notification); + buildComposite.updateView(this, notification); + pluginsComposite.updateView(this, notification); + reportingComposite.updateView(this, notification); + } + + public void updateView(final Notification notification) { + Display.getDefault().asyncExec(new Runnable(){ + public void run(){ + doUpdate(notification); + } + }); + + } + + void createNewModule(String moduleName) { + CompoundCommand compoundCommand = new CompoundCommand(); + EditingDomain editingDomain = getEditingDomain(); + + Command addCommand = AddCommand.create(editingDomain, currentProfile, POM_PACKAGE.getProfile_Modules(), moduleName); + compoundCommand.append(addCommand); + + editingDomain.getCommandStack().execute(compoundCommand); + + modulesEditor.setSelection(Collections.singletonList(moduleName)); + } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PropertiesSection.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PropertiesSection.java new file mode 100644 index 00000000..9f17525c --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PropertiesSection.java @@ -0,0 +1,178 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import java.util.List; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.xml.type.internal.DataValue.XMLChar; +import org.eclipse.emf.edit.command.AddCommand; +import org.eclipse.emf.edit.command.RemoveCommand; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.m2e.core.ui.dialogs.MavenPropertyDialog; +import org.eclipse.m2e.editor.composites.ListEditorComposite; +import org.eclipse.m2e.editor.composites.ListEditorContentProvider; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.m2e.model.edit.pom.PomPackage; +import org.eclipse.m2e.model.edit.pom.PropertyElement; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.VerifyEvent; +import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.forms.widgets.ExpandableComposite; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Section; + +/** + * This is properties editor (double click edits the property) + * + * @author Anton Kraev + */ +public class PropertiesSection { + protected static PomPackage POM_PACKAGE = PomPackage.eINSTANCE; + + private EditingDomain editingDomain; + private EObject model; + private EStructuralFeature feature; + private FormToolkit toolkit; + private Composite composite; + private Section propertiesSection; + ListEditorComposite<PropertyElement> propertiesEditor; + + private VerifyListener listener = new VerifyListener() { + public void verifyText(VerifyEvent e) { + e.doit = XMLChar.isValidName(e.text); + } + }; + + public PropertiesSection(FormToolkit toolkit, Composite composite, EditingDomain editingDomain) { + this.toolkit = toolkit; + this.composite = composite; + this.editingDomain = editingDomain; + createSection(); + } + + public void setModel(EObject model, EStructuralFeature feature) { + this.model = model; + this.feature = feature; + this.propertiesEditor.setInput(getProperties()); + } + + private EList<PropertyElement> getProperties() { + return (EList<PropertyElement>) model.eGet(feature); + } + + private Section createSection() { + propertiesSection = toolkit.createSection(composite, // + ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED | ExpandableComposite.TWISTIE); + propertiesSection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); + propertiesSection.setText(Messages.PropertiesSection_section_properties); + propertiesSection.setText("Properties"); + propertiesSection.setData("name", "propertiesSection"); //$NON-NLS-1$ //$NON-NLS-2$ + toolkit.paintBordersFor(propertiesSection); + + propertiesEditor = new ListEditorComposite<PropertyElement>(propertiesSection, SWT.NONE); + propertiesSection.setClient(propertiesEditor); + propertiesEditor.getViewer().getTable().setData("name", "properties"); //$NON-NLS-1$ //$NON-NLS-2$ + + propertiesEditor.setContentProvider(new ListEditorContentProvider<PropertyElement>()); + propertiesEditor.setLabelProvider(new PropertyPairLabelProvider()); + + propertiesEditor.setCreateButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + createNewProperty(); + } + }); + propertiesEditor.setRemoveButtonListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + deleteProperties(propertiesEditor.getSelection()); + } + }); + propertiesEditor.setDoubleClickListener(new IDoubleClickListener() { + public void doubleClick(DoubleClickEvent event) { + editProperty(propertiesEditor.getSelection()); + } + }) ; + + toolkit.paintBordersFor(propertiesEditor); + toolkit.adapt(propertiesEditor); + + return propertiesSection; + } + + public void refresh() { + propertiesEditor.refresh(); + } + + void editProperty(List<PropertyElement> list) { + if (list.size() != 1) { + return; + } + + PropertyElement pp = list.get(0); + + MavenPropertyDialog dialog = new MavenPropertyDialog(propertiesSection.getShell(), // + Messages.PropertiesSection_title_editProperty, pp.getName(), pp.getValue(), listener); + if(dialog.open() == IDialogConstants.OK_ID) { + String key = dialog.getName(); + String value = dialog.getValue(); + CompoundCommand command = new CompoundCommand(); + if (!key.equals(pp.getName())) { + command.append(SetCommand.create(editingDomain, pp, POM_PACKAGE.getPropertyElement_Name(), key)); + } + if (!value.equals(pp.getValue())) { + command.append(SetCommand.create(editingDomain, pp, POM_PACKAGE.getPropertyElement_Value(), value)); + } + editingDomain.getCommandStack().execute(command); + propertiesEditor.setInput(getProperties()); + } + } + + void createNewProperty() { + MavenPropertyDialog dialog = new MavenPropertyDialog(propertiesSection.getShell(), // + Messages.PropertiesSection_title_addProperty, "", "", listener); //$NON-NLS-2$ //$NON-NLS-3$ + if(dialog.open() == IDialogConstants.OK_ID) { + CompoundCommand command = new CompoundCommand(); + + PropertyElement propertyPair = PomFactory.eINSTANCE.createPropertyElement(); + propertyPair.setName(dialog.getName()); + propertyPair.setValue(dialog.getValue()); + command.append(AddCommand.create(editingDomain, model, feature, // + propertyPair, getProperties().size())); + + editingDomain.getCommandStack().execute(command); + propertiesEditor.setInput(getProperties()); + } + } + + void deleteProperties(List<PropertyElement> selection) { + Command deleteProperties = RemoveCommand.create(editingDomain, model, feature, selection); + editingDomain.getCommandStack().execute(deleteProperties); + propertiesEditor.setInput(getProperties()); + } + + public ExpandableComposite getSection() { + return propertiesSection; + } +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PropertyPairLabelProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PropertyPairLabelProvider.java new file mode 100644 index 00000000..b3866afa --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/PropertyPairLabelProvider.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.model.edit.pom.PropertyElement; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.graphics.Image; + +/** + * Label provider for <code>PropertyPair</code> + * + * @author Eugene Kuleshov + */ +public class PropertyPairLabelProvider extends LabelProvider { + + public String getText(Object element) { + if(element instanceof PropertyElement) { + PropertyElement pair = (PropertyElement) element; + return NLS.bind(Messages.PropertyPairLabelProvider_0, pair.getName(), pair.getValue()); + } + return super.getText(element); + } + + public Image getImage(Object element) { + return MavenEditorImages.IMG_PROPERTY; + } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/ReportingPage.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/ReportingPage.java new file mode 100644 index 00000000..85de7e06 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/ReportingPage.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.editor.composites.ReportingComposite; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.m2e.model.edit.pom.Reporting; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.ScrolledForm; + + +/** + * @author Eugene Kuleshov + */ +public class ReportingPage extends MavenPomEditorPage { + + private ReportingComposite reportingComposite; + + private SearchControl searchControl; + + public ReportingPage(MavenPomEditor pomEditor) { + super(pomEditor, IMavenConstants.PLUGIN_ID + ".pom.reporting", Messages.ReportingPage_title); //$NON-NLS-1$ + } + + public void setActive(boolean active) { + super.setActive(active); + if(active) { + reportingComposite.setSearchControl(searchControl); + searchControl.getSearchText().setEditable(true); + } + } + + protected void createFormContent(IManagedForm managedForm) { + FormToolkit toolkit = managedForm.getToolkit(); + ScrolledForm form = managedForm.getForm(); + form.setText(Messages.ReportingPage_form); + + Composite body = form.getBody(); + GridLayout gridLayout = new GridLayout(1, true); + gridLayout.marginHeight = 0; + body.setLayout(gridLayout); + toolkit.paintBordersFor(body); + + reportingComposite = new ReportingComposite(body, this, SWT.NONE); + reportingComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + toolkit.adapt(reportingComposite); + + searchControl = new SearchControl(Messages.ReportingPage_find, managedForm); + + IToolBarManager pageToolBarManager = form.getForm().getToolBarManager(); + pageToolBarManager.add(searchControl); + pageToolBarManager.add(new Separator()); + + form.updateToolBar(); + +// form.pack(); + + super.createFormContent(managedForm); + } + + public void loadData() { + ValueProvider<Reporting> reportingProvider = new ValueProvider<Reporting>() { + public Reporting getValue() { + return model.getReporting(); + } + + public Reporting create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + Reporting reporting = PomFactory.eINSTANCE.createReporting(); + Command createReportingCommand = SetCommand.create(editingDomain, model, POM_PACKAGE.getModel_Reporting(), + reporting); + compoundCommand.append(createReportingCommand); + return reporting; + } + }; + reportingComposite.loadData(this, reportingProvider); + } + + public void updateView(final Notification notification) { + Display.getDefault().asyncExec(new Runnable(){ + public void run(){ + reportingComposite.updateView(ReportingPage.this, notification); + } + }); + } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/RepositoriesPage.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/RepositoriesPage.java new file mode 100644 index 00000000..e6c855eb --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/RepositoriesPage.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.edit.command.SetCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.editor.composites.RepositoriesComposite; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.m2e.model.edit.pom.DistributionManagement; +import org.eclipse.m2e.model.edit.pom.PomFactory; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.ScrolledForm; + +/** + * @author Eugene Kuleshov + */ +public class RepositoriesPage extends MavenPomEditorPage { + + private RepositoriesComposite repositoriesComposite; + + public RepositoriesPage(MavenPomEditor pomEditor) { + super(pomEditor, IMavenConstants.PLUGIN_ID + ".pom.repositories", Messages.RepositoriesPage_title); //$NON-NLS-1$ + } + + public void dispose() { + if(repositoriesComposite!=null) { + repositoriesComposite.dispose(); + } + super.dispose(); + } + + protected void createFormContent(IManagedForm managedForm) { + FormToolkit toolkit = managedForm.getToolkit(); + + ScrolledForm form = managedForm.getForm(); + form.setText(Messages.RepositoriesPage_form); + + Composite body = form.getBody(); + body.setLayout(new GridLayout(1, true)); + + repositoriesComposite = new RepositoriesComposite(body, SWT.NONE); + repositoriesComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + toolkit.adapt(repositoriesComposite); + + // form.pack(); + + super.createFormContent(managedForm); + } + + public void loadData() { + ValueProvider<DistributionManagement> distributionManagementProvider = new ValueProvider<DistributionManagement>() { + public DistributionManagement getValue() { + return model.getDistributionManagement(); + } + + public DistributionManagement create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + DistributionManagement dm = PomFactory.eINSTANCE.createDistributionManagement(); + Command command = SetCommand.create(editingDomain, model, POM_PACKAGE.getModel_DistributionManagement(), dm); + compoundCommand.append(command); + return dm; + } + }; + + repositoriesComposite.loadData(this, model, distributionManagementProvider); + } + + public void updateView(final Notification notification) { + Display.getDefault().asyncExec(new Runnable(){ + public void run(){ + repositoriesComposite.updateView(RepositoriesPage.this, notification); + } + }); + + } + + +// public static class PairNode { +// final String label; +// final Object value; +// +// public PairNode(String label, Object value) { +// this.label = label; +// this.value = value; +// } +// } +// +// +// public static class ExclusionsNode { +// +// final String label; +// final Exclusion exclusions; +// +// public ExclusionsNode(String label, Exclusion exclusions) { +// this.label = label; +// this.exclusions = exclusions; +// } +// +// } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/ScopeArtifactFilter.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/ScopeArtifactFilter.java new file mode 100644 index 00000000..124e90a1 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/ScopeArtifactFilter.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; + +/** + * An artifact filter supporting all dependency scopes + * + * @author Eugene Kuleshov + */ +public class ScopeArtifactFilter implements ArtifactFilter { + private final boolean compileScope; + private final boolean runtimeScope; + private final boolean testScope; + private final boolean providedScope; + private final boolean systemScope; + + public ScopeArtifactFilter(String scope) { + if(Artifact.SCOPE_COMPILE.equals(scope)) { + systemScope = true; + providedScope = true; + compileScope = true; + runtimeScope = false; + testScope = false; + } else if(Artifact.SCOPE_RUNTIME.equals(scope)) { + systemScope = false; + providedScope = false; + compileScope = true; + runtimeScope = true; + testScope = false; + } else if(Artifact.SCOPE_TEST.equals(scope)) { + systemScope = true; + providedScope = true; + compileScope = true; + runtimeScope = true; + testScope = true; + } else if(Artifact.SCOPE_PROVIDED.equals(scope)) { + systemScope = false; + providedScope = true; + compileScope = false; + runtimeScope = false; + testScope = false; + } else if(Artifact.SCOPE_SYSTEM.equals(scope)) { + systemScope = true; + providedScope = false; + compileScope = false; + runtimeScope = false; + testScope = false; + } else { + systemScope = false; + providedScope = false; + compileScope = false; + runtimeScope = false; + testScope = false; + } + } + + public boolean include(Artifact artifact) { + if(Artifact.SCOPE_COMPILE.equals(artifact.getScope())) { + return compileScope; + } else if(Artifact.SCOPE_RUNTIME.equals(artifact.getScope())) { + return runtimeScope; + } else if(Artifact.SCOPE_TEST.equals(artifact.getScope())) { + return testScope; + } else if(Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) { + return providedScope; + } else if(Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) { + return systemScope; + } + return true; + } + +} + diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/SearchControl.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/SearchControl.java new file mode 100644 index 00000000..d74b39b0 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/SearchControl.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import org.eclipse.jface.action.ControlContribution; +import org.eclipse.m2e.editor.MavenEditorImages; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.swt.SWT; +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.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.widgets.FormToolkit; + + +/** + * @author Eugene Kuleshov + */ +public class SearchControl extends ControlContribution { + private final IManagedForm managedForm; + + Text searchText; + + public SearchControl(String id, IManagedForm managedForm) { + super(id); + this.managedForm = managedForm; + } + + public Text getSearchText() { + return searchText; + } + + private boolean isMac(){ + String os =System.getProperty("os.name"); //$NON-NLS-1$ + return os != null && os.startsWith("Mac"); //$NON-NLS-1$ + } + + protected Control createControl(Composite parent) { + if(parent instanceof ToolBar) { + // the FormHeading class sets the toolbar cursor to hand for some reason, + // we change it back so the input control can use a proper I-beam cursor + parent.setCursor(null); + } + + FormToolkit toolkit = managedForm.getToolkit(); + Composite composite = toolkit.createComposite(parent); + + GridLayout layout = new GridLayout(3, false); + layout.marginWidth = 0; + //gross, but on the Mac the search controls are cut off on the bottom, + //so they need to be bumped up a little. other OSs are fine. + if(isMac()){ + layout.marginHeight = -1; + } + layout.verticalSpacing = 0; + composite.setLayout(layout); + composite.setBackground(null); + composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + Control label = toolkit.createLabel(composite, Messages.SearchControl_lblSearch); + label.setBackground(null); + + searchText = toolkit.createText(composite, "", SWT.FLAT | SWT.SEARCH); //$NON-NLS-1$ + searchText.setData(FormToolkit.TEXT_BORDER, Boolean.TRUE); + + searchText.setLayoutData(new GridData(200, -1)); + ToolBar cancelBar = new ToolBar(composite, SWT.FLAT); + + final ToolItem clearToolItem = new ToolItem(cancelBar, SWT.NONE); + clearToolItem.setEnabled(false); + clearToolItem.setImage(MavenEditorImages.IMG_CLEAR); + clearToolItem.setDisabledImage(MavenEditorImages.IMG_CLEAR_DISABLED); + clearToolItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + searchText.setText(""); //$NON-NLS-1$ + } + }); + + searchText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + clearToolItem.setEnabled(searchText.getText().length() > 0); + } + }); + + toolkit.paintBordersFor(composite); + + return composite; + } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/SearchMatcher.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/SearchMatcher.java new file mode 100644 index 00000000..2e244fea --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/SearchMatcher.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + + +/** + * @author Eugene Kuleshov + */ +public class SearchMatcher extends Matcher { + + private final SearchControl searchControl; + + public SearchMatcher(SearchControl searchControl) { + this.searchControl = searchControl; + } + + public boolean isMatchingArtifact(String groupId, String artifactId) { + String text = searchControl.getSearchText().getText(); + return (groupId != null && groupId.indexOf(text) > -1) // + || (artifactId != null && artifactId.indexOf(text) > -1); + } + + public boolean isEmpty() { + return searchControl.getSearchText().getText() == null // + || searchControl.getSearchText().getText().trim().length() == 0; + } + +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/TeamPage.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/TeamPage.java new file mode 100644 index 00000000..a8e5a86d --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/TeamPage.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.m2e.core.core.IMavenConstants; +import org.eclipse.m2e.editor.composites.TeamComposite; +import org.eclipse.m2e.editor.internal.Messages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.ScrolledForm; + + +/** + * @author Eugene Kuleshov + */ +public class TeamPage extends MavenPomEditorPage { + + private TeamComposite teamComposite; + + public TeamPage(MavenPomEditor pomEditor) { + super(pomEditor, IMavenConstants.PLUGIN_ID + ".pom.team", Messages.TeamPage_title); //$NON-NLS-1$ + } + + public void dispose() { + if(teamComposite!=null) { + teamComposite.dispose(); + } + super.dispose(); + } + + protected void createFormContent(IManagedForm managedForm) { + FormToolkit toolkit = managedForm.getToolkit(); + + ScrolledForm form = managedForm.getForm(); + form.setText(Messages.TeamPage_form); + + form.getBody().setLayout(new GridLayout(1, true)); + + teamComposite = new TeamComposite(this, form.getBody(), SWT.NONE); + teamComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + toolkit.adapt(teamComposite); + +// form.pack(); + + super.createFormContent(managedForm); + } + + public void loadData() { + teamComposite.loadData(model ); + } + + public void updateView(final Notification notification) { + Display.getDefault().asyncExec(new Runnable(){ + public void run(){ + if(teamComposite!=null) { + teamComposite.updateView(notification); + } + } + }); + + } +} diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/ValueProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/ValueProvider.java new file mode 100644 index 00000000..4517a5b2 --- /dev/null +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/ValueProvider.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.editor.pom; + +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Text; + +/** + * Value provider for retrieving and creating holder element values + * + * @author Eugene Kuleshov + */ +public abstract class ValueProvider<T> { + + public abstract T getValue(); + + public T create(EditingDomain editingDomain, CompoundCommand compoundCommand) { + return null; + } + + public boolean isEmpty() { + return false; + } + + + /** + * Default value provider + */ + public static class DefaultValueProvider<T> extends ValueProvider<T> { + private T value; + + public DefaultValueProvider(T value) { + this.value = value; + } + + public T getValue() { + return value; + } + } + + /** + * Default value provider + */ + public abstract static class ParentValueProvider<T> extends ValueProvider<T> { + private final Control[] controls; + + public ParentValueProvider(Control... controls) { + this.controls = controls; + } + + public final boolean isEmpty() { + for(Control control : controls) { + if(control instanceof Text) { + if(!FormUtils.isEmpty(((Text) control).getText())) { + return false; + } + } else if(control instanceof CCombo) { + if(!FormUtils.isEmpty(((CCombo) control).getText())) { + return false; + } + } else if(control instanceof Button) { + if(!((Button) control).getSelection()) { + return false; + } + } + } + return true; + } + } + +} |