Search in sources :

Example 1 with DEPENDENCIES

use of org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCIES in project m2e-core-tests by tesla.

the class ExcludeArtifactRefactoringTest method hasExclusionSet.

/*
   * The editor has the given exclusion set
   */
protected static boolean hasExclusionSet(MavenPomEditor editor, final ArtifactKey dependencyKey, final ArtifactKey excluded) throws Exception {
    final boolean[] found = new boolean[1];
    found[0] = false;
    performOnDOMDocument(new OperationTuple(editor.getDocument(), document -> {
        Element dep = findChild(findChild(document.getDocumentElement(), DEPENDENCIES), DEPENDENCY, childEquals(GROUP_ID, dependencyKey.getGroupId()), childEquals(ARTIFACT_ID, dependencyKey.getArtifactId()), childEquals(VERSION, dependencyKey.getVersion()));
        if (dep != null) {
            Element exclusion = findChild(findChild(dep, EXCLUSIONS), EXCLUSION, childEquals(GROUP_ID, excluded.getGroupId()), childEquals(ARTIFACT_ID, excluded.getArtifactId()));
            found[0] = exclusion != null;
        }
    }, true));
    return found[0];
}
Also used : ArtifactKey(org.eclipse.m2e.core.embedder.ArtifactKey) ParentGatherer(org.eclipse.m2e.core.ui.internal.util.ParentGatherer) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) ExcludeArtifactRefactoring(org.eclipse.m2e.refactoring.exclude.ExcludeArtifactRefactoring) CoreException(org.eclipse.core.runtime.CoreException) IStatus(org.eclipse.core.runtime.IStatus) PomEdits.performOnDOMDocument(org.eclipse.m2e.core.ui.internal.editing.PomEdits.performOnDOMDocument) ARTIFACT_ID(org.eclipse.m2e.core.ui.internal.editing.PomEdits.ARTIFACT_ID) PartInitException(org.eclipse.ui.PartInitException) After(org.junit.After) OperationTuple(org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple) AbstractMavenProjectTestCase(org.eclipse.m2e.tests.common.AbstractMavenProjectTestCase) PomEdits.childEquals(org.eclipse.m2e.core.ui.internal.editing.PomEdits.childEquals) Assert.fail(org.junit.Assert.fail) Change(org.eclipse.ltk.core.refactoring.Change) PomResourceImpl(org.eclipse.m2e.model.edit.pom.util.PomResourceImpl) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) NLS(org.eclipse.osgi.util.NLS) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) MavenPomEditor(org.eclipse.m2e.editor.pom.MavenPomEditor) EXCLUSIONS(org.eclipse.m2e.core.ui.internal.editing.PomEdits.EXCLUSIONS) Status(org.eclipse.core.runtime.Status) Display(org.eclipse.swt.widgets.Display) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DocumentChange(org.eclipse.ltk.core.refactoring.DocumentChange) List(java.util.List) Resource(org.eclipse.emf.ecore.resource.Resource) Model(org.eclipse.m2e.model.edit.pom.Model) EXCLUSION(org.eclipse.m2e.core.ui.internal.editing.PomEdits.EXCLUSION) DEPENDENCY(org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCY) Dependency(org.eclipse.m2e.model.edit.pom.Dependency) Exclusion(org.eclipse.m2e.model.edit.pom.Exclusion) URI(org.eclipse.emf.common.util.URI) HashMap(java.util.HashMap) ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) IDocument(org.eclipse.jface.text.IDocument) IProject(org.eclipse.core.resources.IProject) VERSION(org.eclipse.m2e.core.ui.internal.editing.PomEdits.VERSION) GROUP_ID(org.eclipse.m2e.core.ui.internal.editing.PomEdits.GROUP_ID) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) PomEdits.findChild(org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChild) IFile(org.eclipse.core.resources.IFile) PomResourceFactoryImpl(org.eclipse.m2e.model.edit.pom.util.PomResourceFactoryImpl) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) DEPENDENCIES(org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCIES) Element(org.w3c.dom.Element) StructuredModelManager(org.eclipse.wst.sse.core.StructuredModelManager) ParentHierarchyEntry(org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry) MavenPlugin(org.eclipse.m2e.core.MavenPlugin) Assert.assertEquals(org.junit.Assert.assertEquals) OperationTuple(org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple) Element(org.w3c.dom.Element)

Example 2 with DEPENDENCIES

use of org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCIES in project m2e-core by eclipse-m2e.

the class DependenciesComposite method createDependenciesSection.

private void createDependenciesSection(SashForm verticalSash) {
    Section dependenciesSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR);
    dependenciesSection.marginWidth = 3;
    dependenciesSection.setText(Messages.DependenciesComposite_sectionDependencies);
    dependenciesComparator = new DependenciesComparator<>();
    dependenciesContentProvider.setComparator(dependenciesComparator);
    dependenciesEditor = new DependenciesListComposite<>(dependenciesSection, SWT.NONE, true);
    dependenciesEditor.setCellLabelProvider(new DelegatingStyledCellLabelProvider(dependencyLabelProvider));
    dependenciesEditor.setContentProvider(dependenciesContentProvider);
    dependenciesEditor.setRemoveButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
        final List<Object> dependencyList = dependenciesEditor.getSelection();
        try {
            editorPage.performEditOperation(document -> {
                Element deps = findChild(document.getDocumentElement(), DEPENDENCIES);
                if (deps == null) {
                    // TODO log
                    return;
                }
                for (Object dependency : dependencyList) {
                    if (dependency instanceof Dependency) {
                        Element dep = findChild(deps, DEPENDENCY, childEquals(GROUP_ID, ((Dependency) dependency).groupId), childEquals(ARTIFACT_ID, ((Dependency) dependency).artifactId));
                        removeChild(deps, dep);
                    }
                }
                removeIfNoChildElement(deps);
            }, log, "error removing dependencies");
        } finally {
            setDependenciesInput();
        }
    }));
    dependenciesEditor.setPropertiesListener(SelectionListener.widgetSelectedAdapter(e -> {
        Object selection = dependenciesEditor.getSelection().get(0);
        if (selection instanceof Dependency) {
            Dependency dependency = (Dependency) selection;
            EditDependencyDialog d = new EditDependencyDialog(getShell(), false, editorPage.getProject(), editorPage.getPomEditor().getMavenProject());
            d.setDependency(toApacheDependency(dependency));
            if (d.open() == Window.OK) {
                try {
                    editorPage.performEditOperation(d.getEditOperation(), log, "Error updating dependency");
                } finally {
                    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(SelectionListener.widgetSelectedAdapter(e -> {
        try {
            openManageDependenciesDialog();
        } catch (InvocationTargetException e1) {
            MavenEditorPlugin.getDefault().getLog().log(// $NON-NLS-1$
            new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, "Error: ", e1));
        } catch (InterruptedException e1) {
            MavenEditorPlugin.getDefault().getLog().log(// $NON-NLS-1$
            new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, "Error: ", e1));
        }
    }));
    dependenciesEditor.setAddButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
        final MavenRepositorySearchDialog addDepDialog = MavenRepositorySearchDialog.createSearchDependencyDialog(getShell(), Messages.DependenciesComposite_action_selectDependency, editorPage.getPomEditor().getMavenProject(), editorPage.getProject(), false);
        if (addDepDialog.open() == Window.OK) {
            final IndexedArtifactFile dep = (IndexedArtifactFile) addDepDialog.getFirstResult();
            final String selectedScope = addDepDialog.getSelectedScope();
            try {
                editorPage.performEditOperation(document -> {
                    Element depsEl = getChild(document.getDocumentElement(), DEPENDENCIES);
                    PomHelper.addOrUpdateDependency(depsEl, dep.group, dep.artifact, isManaged(dep.group, dep.artifact, dep.version) ? null : dep.version, dep.type, selectedScope, dep.classifier);
                }, log, "errror adding dependency");
            } finally {
                setDependenciesInput();
                List<Dependency> deps = getDependencies();
                if (!deps.isEmpty()) {
                    dependenciesEditor.setSelection(Collections.<Object>singletonList(deps.get(deps.size() - 1)));
                }
            }
        }
    }));
    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()) {
                showInheritedDependencies = true;
            } else {
                showInheritedDependencies = false;
            }
            ISelection selection = dependenciesEditor.getViewer().getSelection();
            setDependenciesInput();
            dependenciesEditor.getViewer().refresh();
            dependenciesEditor.getViewer().setSelection(selection, true);
        }
    });
    modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_showgroupid, MavenEditorImages.SHOW_GROUP) {

        {
            setChecked(false);
            dependenciesComparator.setSortByGroups(false);
        }

        @Override
        public int getStyle() {
            return AS_CHECK_BOX;
        }

        @Override
        public void run() {
            dependencyLabelProvider.setShowGroupId(isChecked());
            dependenciesComparator.setSortByGroups(isChecked());
            dependenciesEditor.getViewer().refresh();
        }
    });
    modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_filter, MavenEditorImages.FILTER) {

        {
            setChecked(true);
        }

        @Override
        public int getStyle() {
            return AS_CHECK_BOX;
        }

        @Override
        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);
}
Also used : SYSTEM_PATH(org.eclipse.m2e.core.ui.internal.editing.PomEdits.SYSTEM_PATH) ArtifactKey(org.eclipse.m2e.core.embedder.ArtifactKey) TableViewer(org.eclipse.jface.viewers.TableViewer) SashForm(org.eclipse.swt.custom.SashForm) ParentGatherer(org.eclipse.m2e.core.ui.internal.util.ParentGatherer) LoggerFactory(org.slf4j.LoggerFactory) DependencyManagement(org.apache.maven.model.DependencyManagement) CoreException(org.eclipse.core.runtime.CoreException) PomHelper(org.eclipse.m2e.core.ui.internal.editing.PomHelper) CLASSIFIER(org.eclipse.m2e.core.ui.internal.editing.PomEdits.CLASSIFIER) PomEdits.getTextValue(org.eclipse.m2e.core.ui.internal.editing.PomEdits.getTextValue) IStatus(org.eclipse.core.runtime.IStatus) PomEdits.performOnDOMDocument(org.eclipse.m2e.core.ui.internal.editing.PomEdits.performOnDOMDocument) MavenProject(org.apache.maven.project.MavenProject) EditDependencyDialog(org.eclipse.m2e.core.ui.internal.dialogs.EditDependencyDialog) ARTIFACT_ID(org.eclipse.m2e.core.ui.internal.editing.PomEdits.ARTIFACT_ID) Composite(org.eclipse.swt.widgets.Composite) OPTIONAL(org.eclipse.m2e.core.ui.internal.editing.PomEdits.OPTIONAL) OperationTuple(org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple) SCOPE(org.eclipse.m2e.core.ui.internal.editing.PomEdits.SCOPE) PomEdits.childEquals(org.eclipse.m2e.core.ui.internal.editing.PomEdits.childEquals) PomEdits.removeChild(org.eclipse.m2e.core.ui.internal.editing.PomEdits.removeChild) IAdaptable(org.eclipse.core.runtime.IAdaptable) Messages(org.eclipse.m2e.editor.internal.Messages) DEPENDENCY_MANAGEMENT(org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCY_MANAGEMENT) Button(org.eclipse.swt.widgets.Button) PlatformUI(org.eclipse.ui.PlatformUI) MavenPomEditor(org.eclipse.m2e.editor.pom.MavenPomEditor) MavenPomEditorPage(org.eclipse.m2e.editor.pom.MavenPomEditorPage) Status(org.eclipse.core.runtime.Status) Display(org.eclipse.swt.widgets.Display) MavenEditorPlugin(org.eclipse.m2e.editor.MavenEditorPlugin) IMavenProjectRegistry(org.eclipse.m2e.core.project.IMavenProjectRegistry) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) Window(org.eclipse.jface.window.Window) PomEdits.removeIfNoChildElement(org.eclipse.m2e.core.ui.internal.editing.PomEdits.removeIfNoChildElement) SWT(org.eclipse.swt.SWT) ISelection(org.eclipse.jface.viewers.ISelection) DEPENDENCY(org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCY) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionListener(org.eclipse.swt.events.SelectionListener) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) PomEdits.findChilds(org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChilds) TYPE(org.eclipse.m2e.core.ui.internal.editing.PomEdits.TYPE) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) PomEdits.getChild(org.eclipse.m2e.core.ui.internal.editing.PomEdits.getChild) ArrayList(java.util.ArrayList) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider) VERSION(org.eclipse.m2e.core.ui.internal.editing.PomEdits.VERSION) GROUP_ID(org.eclipse.m2e.core.ui.internal.editing.PomEdits.GROUP_ID) MavenRepositorySearchDialog(org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog) PomEdits.findChild(org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChild) GridData(org.eclipse.swt.layout.GridData) SearchMatcher(org.eclipse.m2e.editor.pom.SearchMatcher) ValueProvider(org.eclipse.m2e.editor.pom.ValueProvider) LinkedList(java.util.LinkedList) Section(org.eclipse.ui.forms.widgets.Section) SearchControl(org.eclipse.m2e.editor.pom.SearchControl) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Viewer(org.eclipse.jface.viewers.Viewer) Job(org.eclipse.core.runtime.jobs.Job) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Action(org.eclipse.jface.action.Action) DEPENDENCIES(org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCIES) Element(org.w3c.dom.Element) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ParentHierarchyEntry(org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry) ToolBarManager(org.eclipse.jface.action.ToolBarManager) MavenPlugin(org.eclipse.m2e.core.MavenPlugin) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) MavenEditorImages(org.eclipse.m2e.editor.MavenEditorImages) Collections(java.util.Collections) GridLayout(org.eclipse.swt.layout.GridLayout) ManageDependenciesDialog(org.eclipse.m2e.editor.dialogs.ManageDependenciesDialog) Action(org.eclipse.jface.action.Action) PomEdits.removeIfNoChildElement(org.eclipse.m2e.core.ui.internal.editing.PomEdits.removeIfNoChildElement) Element(org.w3c.dom.Element) EditDependencyDialog(org.eclipse.m2e.core.ui.internal.dialogs.EditDependencyDialog) ToolBarManager(org.eclipse.jface.action.ToolBarManager) GridLayout(org.eclipse.swt.layout.GridLayout) ISelection(org.eclipse.jface.viewers.ISelection) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) MavenRepositorySearchDialog(org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) Section(org.eclipse.ui.forms.widgets.Section) InvocationTargetException(java.lang.reflect.InvocationTargetException) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 3 with DEPENDENCIES

use of org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCIES in project m2e-core by eclipse-m2e.

the class DependenciesComposite method createDependencyManagementSection.

private void createDependencyManagementSection(SashForm verticalSash) {
    Section dependencyManagementSection = toolkit.createSection(verticalSash, ExpandableComposite.TITLE_BAR);
    dependencyManagementSection.marginWidth = 3;
    dependencyManagementSection.setText(Messages.DependenciesComposite_sectionDependencyManagement);
    dependencyManagementComparator = new DependenciesComparator<>();
    dependencyManagementContentProvider.setComparator(dependencyManagementComparator);
    dependencyManagementEditor = new PropertiesListComposite<>(dependencyManagementSection, SWT.NONE, true);
    dependencyManagementEditor.setContentProvider(dependencyManagementContentProvider);
    dependencyManagementEditor.setLabelProvider(dependencyManagementLabelProvider);
    dependencyManagementSection.setClient(dependencyManagementEditor);
    dependencyManagementEditor.setRemoveButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
        final List<Dependency> dependencyList = dependencyManagementEditor.getSelection();
        try {
            editorPage.performEditOperation(document -> {
                Element deps = findChild(findChild(document.getDocumentElement(), DEPENDENCY_MANAGEMENT), DEPENDENCIES);
                if (deps == null) {
                    // TODO log
                    return;
                }
                for (Dependency dependency : dependencyList) {
                    Element dep = findChild(deps, DEPENDENCY, childEquals(GROUP_ID, dependency.groupId), childEquals(ARTIFACT_ID, dependency.artifactId));
                    removeChild(deps, dep);
                }
                removeIfNoChildElement(deps);
            }, log, "error removing managed dependencies");
        } finally {
            setDependencyManagementInput();
            dependenciesEditor.refresh();
        }
    }));
    dependencyManagementEditor.setPropertiesListener(SelectionListener.widgetSelectedAdapter(e -> {
        Dependency dependency = dependencyManagementEditor.getSelection().get(0);
        EditDependencyDialog d = new EditDependencyDialog(getShell(), true, editorPage.getProject(), editorPage.getPomEditor().getMavenProject());
        d.setDependency(toApacheDependency(dependency));
        if (d.open() == Window.OK) {
            try {
                editorPage.performEditOperation(d.getEditOperation(), log, "Error updating dependency");
            } finally {
                setDependencyManagementInput();
                dependencyManagementEditor.setSelection(Collections.singletonList(dependency));
                // refresh this one to update decorations..
                dependenciesEditor.refresh();
            }
        }
    }));
    dependencyManagementEditor.addSelectionListener(event -> {
        List<Dependency> selection = dependencyManagementEditor.getSelection();
        if (!selection.isEmpty()) {
            dependenciesEditor.setSelection(Collections.<Object>emptyList());
        }
    });
    toolkit.adapt(dependencyManagementEditor);
    toolkit.paintBordersFor(dependencyManagementEditor);
    dependencyManagementEditor.setAddButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
        final MavenRepositorySearchDialog addDepDialog = MavenRepositorySearchDialog.createSearchDependencyDialog(getShell(), Messages.DependenciesComposite_action_selectDependency, editorPage.getPomEditor().getMavenProject(), editorPage.getProject(), true);
        if (addDepDialog.open() == Window.OK) {
            final IndexedArtifactFile dep = (IndexedArtifactFile) addDepDialog.getFirstResult();
            final String selectedScope = addDepDialog.getSelectedScope();
            try {
                editorPage.performEditOperation(document -> {
                    Element depsEl = getChild(document.getDocumentElement(), DEPENDENCY_MANAGEMENT, DEPENDENCIES);
                    PomHelper.addOrUpdateDependency(depsEl, dep.group, dep.artifact, dep.version, dep.type, selectedScope, dep.classifier);
                }, log, "errror adding dependency");
            } finally {
                setDependencyManagementInput();
                List<Dependency> dlist = getManagedDependencies();
                if (!dlist.isEmpty()) {
                    dependencyManagementEditor.setSelection(Collections.<Dependency>singletonList(dlist.get(dlist.size() - 1)));
                }
                // refresh this one to update decorations..
                dependenciesEditor.refresh();
            }
        }
    }));
    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);
        }

        @Override
        public int getStyle() {
            return AS_CHECK_BOX;
        }

        @Override
        public void run() {
            dependencyManagementLabelProvider.setShowGroupId(isChecked());
            dependencyManagementComparator.setSortByGroups(isChecked());
            dependencyManagementEditor.getViewer().refresh();
        }
    });
    modulesToolBarManager.add(new Action(Messages.DependenciesComposite_action_filter, MavenEditorImages.FILTER) {

        {
            setChecked(true);
        }

        @Override
        public int getStyle() {
            return AS_CHECK_BOX;
        }

        @Override
        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);
}
Also used : SYSTEM_PATH(org.eclipse.m2e.core.ui.internal.editing.PomEdits.SYSTEM_PATH) ArtifactKey(org.eclipse.m2e.core.embedder.ArtifactKey) TableViewer(org.eclipse.jface.viewers.TableViewer) SashForm(org.eclipse.swt.custom.SashForm) ParentGatherer(org.eclipse.m2e.core.ui.internal.util.ParentGatherer) LoggerFactory(org.slf4j.LoggerFactory) DependencyManagement(org.apache.maven.model.DependencyManagement) CoreException(org.eclipse.core.runtime.CoreException) PomHelper(org.eclipse.m2e.core.ui.internal.editing.PomHelper) CLASSIFIER(org.eclipse.m2e.core.ui.internal.editing.PomEdits.CLASSIFIER) PomEdits.getTextValue(org.eclipse.m2e.core.ui.internal.editing.PomEdits.getTextValue) IStatus(org.eclipse.core.runtime.IStatus) PomEdits.performOnDOMDocument(org.eclipse.m2e.core.ui.internal.editing.PomEdits.performOnDOMDocument) MavenProject(org.apache.maven.project.MavenProject) EditDependencyDialog(org.eclipse.m2e.core.ui.internal.dialogs.EditDependencyDialog) ARTIFACT_ID(org.eclipse.m2e.core.ui.internal.editing.PomEdits.ARTIFACT_ID) Composite(org.eclipse.swt.widgets.Composite) OPTIONAL(org.eclipse.m2e.core.ui.internal.editing.PomEdits.OPTIONAL) OperationTuple(org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple) SCOPE(org.eclipse.m2e.core.ui.internal.editing.PomEdits.SCOPE) PomEdits.childEquals(org.eclipse.m2e.core.ui.internal.editing.PomEdits.childEquals) PomEdits.removeChild(org.eclipse.m2e.core.ui.internal.editing.PomEdits.removeChild) IAdaptable(org.eclipse.core.runtime.IAdaptable) Messages(org.eclipse.m2e.editor.internal.Messages) DEPENDENCY_MANAGEMENT(org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCY_MANAGEMENT) Button(org.eclipse.swt.widgets.Button) PlatformUI(org.eclipse.ui.PlatformUI) MavenPomEditor(org.eclipse.m2e.editor.pom.MavenPomEditor) MavenPomEditorPage(org.eclipse.m2e.editor.pom.MavenPomEditorPage) Status(org.eclipse.core.runtime.Status) Display(org.eclipse.swt.widgets.Display) MavenEditorPlugin(org.eclipse.m2e.editor.MavenEditorPlugin) IMavenProjectRegistry(org.eclipse.m2e.core.project.IMavenProjectRegistry) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) Window(org.eclipse.jface.window.Window) PomEdits.removeIfNoChildElement(org.eclipse.m2e.core.ui.internal.editing.PomEdits.removeIfNoChildElement) SWT(org.eclipse.swt.SWT) ISelection(org.eclipse.jface.viewers.ISelection) DEPENDENCY(org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCY) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionListener(org.eclipse.swt.events.SelectionListener) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) PomEdits.findChilds(org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChilds) TYPE(org.eclipse.m2e.core.ui.internal.editing.PomEdits.TYPE) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) PomEdits.getChild(org.eclipse.m2e.core.ui.internal.editing.PomEdits.getChild) ArrayList(java.util.ArrayList) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider) VERSION(org.eclipse.m2e.core.ui.internal.editing.PomEdits.VERSION) GROUP_ID(org.eclipse.m2e.core.ui.internal.editing.PomEdits.GROUP_ID) MavenRepositorySearchDialog(org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog) PomEdits.findChild(org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChild) GridData(org.eclipse.swt.layout.GridData) SearchMatcher(org.eclipse.m2e.editor.pom.SearchMatcher) ValueProvider(org.eclipse.m2e.editor.pom.ValueProvider) LinkedList(java.util.LinkedList) Section(org.eclipse.ui.forms.widgets.Section) SearchControl(org.eclipse.m2e.editor.pom.SearchControl) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Viewer(org.eclipse.jface.viewers.Viewer) Job(org.eclipse.core.runtime.jobs.Job) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Action(org.eclipse.jface.action.Action) DEPENDENCIES(org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCIES) Element(org.w3c.dom.Element) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ParentHierarchyEntry(org.eclipse.m2e.core.ui.internal.util.ParentHierarchyEntry) ToolBarManager(org.eclipse.jface.action.ToolBarManager) MavenPlugin(org.eclipse.m2e.core.MavenPlugin) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) MavenEditorImages(org.eclipse.m2e.editor.MavenEditorImages) Collections(java.util.Collections) GridLayout(org.eclipse.swt.layout.GridLayout) ManageDependenciesDialog(org.eclipse.m2e.editor.dialogs.ManageDependenciesDialog) MavenRepositorySearchDialog(org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog) Action(org.eclipse.jface.action.Action) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) PomEdits.removeIfNoChildElement(org.eclipse.m2e.core.ui.internal.editing.PomEdits.removeIfNoChildElement) Element(org.w3c.dom.Element) EditDependencyDialog(org.eclipse.m2e.core.ui.internal.dialogs.EditDependencyDialog) Section(org.eclipse.ui.forms.widgets.Section) ToolBarManager(org.eclipse.jface.action.ToolBarManager) GridLayout(org.eclipse.swt.layout.GridLayout) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

List (java.util.List)3 CoreException (org.eclipse.core.runtime.CoreException)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 MavenPlugin (org.eclipse.m2e.core.MavenPlugin)3 ArtifactKey (org.eclipse.m2e.core.embedder.ArtifactKey)3 IMavenProjectFacade (org.eclipse.m2e.core.project.IMavenProjectFacade)3 ARTIFACT_ID (org.eclipse.m2e.core.ui.internal.editing.PomEdits.ARTIFACT_ID)3 DEPENDENCIES (org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCIES)3 DEPENDENCY (org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEPENDENCY)3 GROUP_ID (org.eclipse.m2e.core.ui.internal.editing.PomEdits.GROUP_ID)3 OperationTuple (org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 DependencyManagement (org.apache.maven.model.DependencyManagement)2 MavenProject (org.apache.maven.project.MavenProject)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)2