Search in sources :

Example 6 with IndexedArtifactFile

use of org.eclipse.m2e.core.internal.index.IndexedArtifactFile in project m2e-core by eclipse-m2e.

the class AddPluginAction method run.

@Override
public void run(IAction action) {
    IFile file = getPomFileFromPomEditorOrViewSelection();
    if (file == null) {
        return;
    }
    MavenProject mp = null;
    IProject prj = file.getProject();
    if (prj != null && IMavenConstants.POM_FILE_NAME.equals(file.getProjectRelativePath().toString())) {
        IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getProject(prj);
        if (facade != null) {
            mp = facade.getMavenProject();
        }
    }
    MavenRepositorySearchDialog dialog = MavenRepositorySearchDialog.createSearchPluginDialog(getShell(), Messages.AddPluginAction_searchDialog_title, mp, prj, false);
    if (dialog.open() == Window.OK) {
        final IndexedArtifactFile indexedArtifactFile = (IndexedArtifactFile) dialog.getFirstResult();
        if (indexedArtifactFile != null) {
            try {
                performOnDOMDocument(new OperationTuple(file, (Operation) document -> {
                    Element pluginsEl = getChild(document.getDocumentElement(), BUILD, PLUGINS);
                    PomHelper.createPlugin(pluginsEl, indexedArtifactFile.group, indexedArtifactFile.artifact, indexedArtifactFile.version);
                }));
            } catch (Exception ex) {
                // $NON-NLS-1$
                log.error("Can't add plugin to " + file, ex);
            }
        }
    }
}
Also used : MavenRepositorySearchDialog(org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog) IFile(org.eclipse.core.resources.IFile) OperationTuple(org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple) MavenProject(org.apache.maven.project.MavenProject) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) Element(org.w3c.dom.Element) Operation(org.eclipse.m2e.core.ui.internal.editing.PomEdits.Operation) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) IProject(org.eclipse.core.resources.IProject)

Example 7 with IndexedArtifactFile

use of org.eclipse.m2e.core.internal.index.IndexedArtifactFile in project m2e-core by eclipse-m2e.

the class MavenProjectWizardArtifactPage method createControl.

/**
 * {@inheritDoc} This wizard page contains a <code>MavenArtifactComponent</code> to gather information about the Maven
 * artifact and a <code>Maven2DirectoriesComponent</code> which allows to choose which directories of the default
 * Maven directory structure to create.
 */
@Override
public void createControl(Composite parent) {
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(layout);
    WidthGroup widthGroup = new WidthGroup();
    container.addControlListener(widthGroup);
    ModifyListener modifyingListener = e -> validate();
    artifactComponent = new MavenArtifactComponent(container, SWT.NONE);
    artifactComponent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    artifactComponent.setWidthGroup(widthGroup);
    artifactComponent.setModifyingListener(modifyingListener);
    artifactComponent.setArtifactIdEditable(!readonlyParent);
    parentComponent = new MavenParentComponent(container, readonlyParent ? SWT.READ_ONLY : SWT.NONE);
    parentComponent.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    parentComponent.setWidthGroup(widthGroup);
    parentComponent.addModifyListener(modifyingListener);
    parentComponent.addBrowseButtonListener(SelectionListener.widgetSelectedAdapter(e -> {
        MavenRepositorySearchDialog dialog = MavenRepositorySearchDialog.createSearchParentDialog(getShell(), org.eclipse.m2e.core.ui.internal.Messages.MavenProjectWizardArtifactPage_searchDialog_title, null, null);
        if (dialog.open() == Window.OK) {
            IndexedArtifactFile indexedArtifactFile = (IndexedArtifactFile) dialog.getFirstResult();
            if (indexedArtifactFile != null) {
                parentComponent.setValues(indexedArtifactFile.group, indexedArtifactFile.artifact, indexedArtifactFile.version);
            }
        }
    }));
    createAdvancedSettings(container, new GridData(SWT.FILL, SWT.TOP, false, false, 2, 1));
    resolverConfigurationComponent.setModifyListener(e -> validate());
    // $NON-NLS-1$
    addFieldWithHistory("groupId", artifactComponent.getGroupIdCombo());
    // $NON-NLS-1$
    addFieldWithHistory("artifactId", artifactComponent.getArtifactIdCombo());
    // $NON-NLS-1$
    addFieldWithHistory("version", artifactComponent.getVersionCombo());
    // $NON-NLS-1$
    addFieldWithHistory("name", artifactComponent.getNameCombo());
    // $NON-NLS-1$
    addFieldWithHistory("groupId", parentComponent.getGroupIdCombo());
    // $NON-NLS-1$
    addFieldWithHistory("artifactId", parentComponent.getArtifactIdCombo());
    // $NON-NLS-1$
    addFieldWithHistory("version", parentComponent.getVersionCombo());
    container.layout();
    validate();
    setControl(container);
}
Also used : HashMap(java.util.HashMap) ProjectImportConfiguration(org.eclipse.m2e.core.project.ProjectImportConfiguration) IStatus(org.eclipse.core.runtime.IStatus) Window(org.eclipse.jface.window.Window) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) SWT(org.eclipse.swt.SWT) Messages(org.eclipse.m2e.core.ui.internal.Messages) MavenRepositorySearchDialog(org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog) GridData(org.eclipse.swt.layout.GridData) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) Model(org.apache.maven.model.Model) MavenRepositorySearchDialog(org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) GridData(org.eclipse.swt.layout.GridData)

Example 8 with IndexedArtifactFile

use of org.eclipse.m2e.core.internal.index.IndexedArtifactFile in project m2e-core by eclipse-m2e.

the class MavenInstallFileArtifactWizardPage method updateFileName.

void updateFileName(String fileName) {
    if (!getArtifactFileName().equals(fileName)) {
        artifactFileNameText.setText(fileName);
    }
    File file = new File(fileName);
    if (!file.exists() || !file.isFile()) {
        return;
    }
    if (fileName.endsWith(".jar") || fileName.endsWith(".war") || fileName.endsWith(".ear")) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        packagingCombo.setText(fileName.substring(fileName.length() - 3));
    }
    int n = fileName.lastIndexOf('.');
    if (n > -1) {
        // $NON-NLS-1$
        String pomFileName = fileName.substring(0, n) + ".pom";
        if (new File(pomFileName).exists()) {
            pomFileNameText.setText(pomFileName);
        }
    } else {
        // $NON-NLS-1$
        pomFileNameText.setText("");
    }
    // TODO used to be some indexer request
    IndexedArtifactFile iaf = null;
    if (iaf != null) {
        groupIdCombo.setText(iaf.group);
        artifactIdCombo.setText(iaf.artifact);
        versionCombo.setText(iaf.version);
        if (iaf.classifier != null) {
            classifierCombo.setText(iaf.classifier);
        }
        String name = // //$NON-NLS-1$ //$NON-NLS-2$
        iaf.group + ":" + iaf.artifact + "-" + iaf.version + // $NON-NLS-1$
        (iaf.classifier == null ? "" : iaf.classifier);
        setMessage(NLS.bind(Messages.MavenInstallFileArtifactWizardPage_message, name), WARNING);
        return;
    }
    if (n > -1) {
        // $NON-NLS-1$
        String pomFileName = fileName.substring(0, n) + ".pom";
        if (new File(pomFileName).exists()) {
            pomFileNameText.setText(pomFileName);
            readPOMFile(pomFileName);
        }
    }
    ArtifactKey artifactKey = SelectionUtil.getType(file, ArtifactKey.class);
    if (artifactKey != null) {
        groupIdCombo.setText(artifactKey.getGroupId());
        artifactIdCombo.setText(artifactKey.getArtifactId());
        versionCombo.setText(artifactKey.getVersion());
        if (artifactKey.getClassifier() != null) {
            classifierCombo.setText(artifactKey.getClassifier());
        }
    }
}
Also used : ArtifactKey(org.eclipse.m2e.core.embedder.ArtifactKey) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile)

Example 9 with IndexedArtifactFile

use of org.eclipse.m2e.core.internal.index.IndexedArtifactFile 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)

Example 10 with IndexedArtifactFile

use of org.eclipse.m2e.core.internal.index.IndexedArtifactFile in project m2e-core by eclipse-m2e.

the class MavenPomSelectionComponent method init.

public void init(String queryText, String queryType, IProject project, Set<ArtifactKey> artifacts, Set<ArtifactKey> managed) {
    this.queryType = queryType;
    this.project = project;
    if (queryText != null) {
        searchText.setText(queryText);
    }
    if (artifacts != null) {
        for (ArtifactKey a : artifacts) {
            // $NON-NLS-1$
            artifactKeys.add(a.getGroupId() + ":" + a.getArtifactId());
            // $NON-NLS-1$ //$NON-NLS-2$
            artifactKeys.add(a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion());
        }
    }
    if (managed != null) {
        for (ArtifactKey a : managed) {
            // $NON-NLS-1$
            managedKeys.add(a.getGroupId() + ":" + a.getArtifactId());
            // $NON-NLS-1$ //$NON-NLS-2$
            managedKeys.add(a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion());
        }
    }
    searchResultViewer.setContentProvider(new SearchResultContentProvider());
    SearchResultLabelProvider labelProvider = new SearchResultLabelProvider(artifactKeys, managedKeys);
    DecoratingStyledCellLabelProvider decoratingLabelProvider = new DecoratingStyledCellLabelProvider(labelProvider, PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(), null);
    DecorationContext decorationContext = new DecorationContext();
    if (project != null) {
        decorationContext.putProperty(PROP_DECORATION_CONTEXT_PROJECT, project);
    }
    decoratingLabelProvider.setDecorationContext(decorationContext);
    searchResultViewer.setLabelProvider(decoratingLabelProvider);
    searchResultViewer.addSelectionChangedListener(event -> {
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        if (!selection.isEmpty()) {
            List<IndexedArtifactFile> files = getSelectedIndexedArtifactFiles(selection);
            ArtifactFilterManager filterManager = MavenPluginActivator.getDefault().getArifactFilterManager();
            for (IndexedArtifactFile file : files) {
                ArtifactKey key = file.getAdapter(ArtifactKey.class);
                IStatus status = filterManager.filter(MavenPomSelectionComponent.this.project, key);
                if (!status.isOK()) {
                    setStatus(IStatus.ERROR, status.getMessage());
                    // TODO not nice to exit method like this
                    return;
                }
            }
            if (files.size() == 1) {
                IndexedArtifactFile f = files.get(0);
                // int severity = artifactKeys.contains(f.group + ":" + f.artifact) ? IStatus.ERROR : IStatus.OK;
                int severity = IStatus.OK;
                String date = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(f.date);
                setStatus(severity, NLS.bind(Messages.MavenPomSelectionComponent_detail1, f.fname, (f.size != -1 ? NLS.bind(Messages.MavenPomSelectionComponent_details2, date, f.size) : date)));
            } else {
                setStatus(IStatus.OK, NLS.bind(Messages.MavenPomSelectionComponent_selected, selection.size()));
            }
        } else {
            setStatus(IStatus.ERROR, Messages.MavenPomSelectionComponent_nosel);
        }
    });
    setupClassifiers();
    // $NON-NLS-1$
    setStatus(IStatus.ERROR, "");
    scheduleSearch(queryText, false);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ArtifactKey(org.eclipse.m2e.core.embedder.ArtifactKey) DecoratingStyledCellLabelProvider(org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) DecorationContext(org.eclipse.jface.viewers.DecorationContext) ArtifactFilterManager(org.eclipse.m2e.core.internal.index.filter.ArtifactFilterManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StyledString(org.eclipse.jface.viewers.StyledString)

Aggregations

IndexedArtifactFile (org.eclipse.m2e.core.internal.index.IndexedArtifactFile)13 MavenRepositorySearchDialog (org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog)8 IStatus (org.eclipse.core.runtime.IStatus)7 ArrayList (java.util.ArrayList)6 ArtifactKey (org.eclipse.m2e.core.embedder.ArtifactKey)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 Job (org.eclipse.core.runtime.jobs.Job)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 Window (org.eclipse.jface.window.Window)5 SWT (org.eclipse.swt.SWT)5 SelectionListener (org.eclipse.swt.events.SelectionListener)5 GridData (org.eclipse.swt.layout.GridData)5 GridLayout (org.eclipse.swt.layout.GridLayout)5 Composite (org.eclipse.swt.widgets.Composite)5 List (java.util.List)4 MavenProject (org.apache.maven.project.MavenProject)4 IFile (org.eclipse.core.resources.IFile)4 CoreException (org.eclipse.core.runtime.CoreException)4 Action (org.eclipse.jface.action.Action)4 IMavenProjectFacade (org.eclipse.m2e.core.project.IMavenProjectFacade)4