Search in sources :

Example 1 with IndexedArtifactFile

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

the class OpenPomAction method run.

@Override
public void run(IAction action) {
    // on something as vague as selection passed in is unreadable..
    if (selection != null) {
        Object element = this.selection.getFirstElement();
        if (IIndex.SEARCH_ARTIFACT.equals(type) && element != null) {
            final ArtifactKey ak = SelectionUtil.getArtifactKey(element);
            if (ak != null) {
                new Job(Messages.OpenPomAction_job_opening) {

                    @Override
                    protected IStatus run(IProgressMonitor monitor) {
                        openEditor(ak.getGroupId(), ak.getArtifactId(), ak.getVersion(), getMavenProject(), monitor);
                        return Status.OK_STATUS;
                    }
                }.schedule();
                return;
            }
        }
    }
    String title = Messages.OpenPomAction_title_pom;
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    MavenRepositorySearchDialog dialog = MavenRepositorySearchDialog.createOpenPomDialog(shell, title);
    if (dialog.open() == Window.OK) {
        final IndexedArtifactFile iaf = (IndexedArtifactFile) dialog.getFirstResult();
        new Job(Messages.OpenPomAction_job_opening) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                if (iaf != null) {
                    openEditor(iaf.group, iaf.artifact, iaf.version, monitor);
                }
                return Status.OK_STATUS;
            }
        }.schedule();
    }
}
Also used : MavenRepositorySearchDialog(org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) Shell(org.eclipse.swt.widgets.Shell) ArtifactKey(org.eclipse.m2e.core.embedder.ArtifactKey) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) Job(org.eclipse.core.runtime.jobs.Job)

Example 2 with IndexedArtifactFile

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

the class OverviewPage method createParentsection.

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);
    // $NON-NLS-1$ //$NON-NLS-2$
    parentSection.setData("name", "parentSection");
    parentSelectAction = new Action(Messages.OverviewPage_action_selectParent, MavenEditorImages.SELECT_ARTIFACT) {

        @Override
        public void run() {
            // calculate current list of artifacts for the project - that's the current parent..
            Set<ArtifactKey> current = new HashSet<>();
            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 = MavenRepositorySearchDialog.createSearchParentDialog(getEditorSite().getShell(), Messages.OverviewPage_searchDialog_selectParent, getPomEditor().getMavenProject(), getProject());
            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.
                        // $NON-NLS-1$
                        artifactGroupIdText.setText("");
                    }
                    if (ver.equals(artifactVersionText.getText())) {
                        // if the version is the same, just remove it in child.
                        // $NON-NLS-1$
                        artifactVersionText.setText("");
                    }
                    parentSection.setExpanded(true);
                }
            }
        }
    };
    parentSelectAction.setEnabled(false);
    parentOpenAction = new Action(Messages.OverviewPage_job_open, MavenEditorImages.PARENT_POM) {

        @Override
        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 })) {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    OpenPomAction.openEditor(groupId, artifactId, version, getPomEditor().getMavenProject(), 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);
    // $NON-NLS-1$ //$NON-NLS-2$
    parentGroupIdText.setData("name", "parentGroupId");
    ProposalUtil.addGroupIdProposal(getProject(), parentGroupIdText, Packaging.POM);
    M2EUIUtils.addRequiredDecoration(parentGroupIdText);
    createEvaluatorInfo(parentGroupIdText);
    setElementValueProvider(parentGroupIdText, new ElementValueProvider(PomEdits.PARENT, PomEdits.GROUP_ID));
    setModifyListener(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);
    // $NON-NLS-1$ //$NON-NLS-2$
    parentArtifactIdText.setData("name", "parentArtifactId");
    ProposalUtil.addArtifactIdProposal(getProject(), parentGroupIdText, parentArtifactIdText, Packaging.POM);
    M2EUIUtils.addRequiredDecoration(parentArtifactIdText);
    createEvaluatorInfo(parentArtifactIdText);
    setElementValueProvider(parentArtifactIdText, new ElementValueProvider(PomEdits.PARENT, PomEdits.ARTIFACT_ID));
    setModifyListener(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);
    // $NON-NLS-1$ //$NON-NLS-2$
    parentVersionText.setData("name", "parentVersion");
    ProposalUtil.addVersionProposal(getProject(), null, /**
     * null because we don't want expressions from parent pom here
     */
    parentGroupIdText, parentArtifactIdText, parentVersionText, Packaging.POM);
    M2EUIUtils.addRequiredDecoration(parentVersionText);
    createEvaluatorInfo(parentVersionText);
    setElementValueProvider(parentVersionText, new ElementValueProvider(PomEdits.PARENT, PomEdits.VERSION));
    setModifyListener(parentVersionText);
    ModifyListener ml = e -> {
        // apparently the loadParent() method also participates in the enablement logic from time to time..
        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);
    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);
    // $NON-NLS-1$ //$NON-NLS-2$
    parentRelativePathText.setData("name", "parentRelativePath");
    createEvaluatorInfo(parentRelativePathText);
    setElementValueProvider(parentRelativePathText, new ElementValueProvider(PomEdits.PARENT, PomEdits.RELATIVE_PATH));
    setModifyListener(parentRelativePathText);
    widthGroup.addControl(parentGroupIdLabel);
    widthGroup.addControl(parentArtifactIdLabel);
    widthGroup.addControl(parentVersionLabel);
    widthGroup.addControl(parentRealtivePathLabel);
    toolkit.paintBordersFor(parentComposite);
    parentComposite.setTabList(new Control[] { parentGroupIdText, parentArtifactIdText, parentVersionText, parentRelativePathText });
}
Also used : MavenRepositorySearchDialog(org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog) Notification(org.eclipse.emf.common.notify.Notification) MavenModuleWizard(org.eclipse.m2e.core.ui.internal.wizards.MavenModuleWizard) DND(org.eclipse.swt.dnd.DND) CoreException(org.eclipse.core.runtime.CoreException) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) RELATIVE_PATH(org.eclipse.m2e.core.ui.internal.editing.PomEdits.RELATIVE_PATH) Document(org.w3c.dom.Document) Composite(org.eclipse.swt.widgets.Composite) SCM(org.eclipse.m2e.core.ui.internal.editing.PomEdits.SCM) PomEdits.removeChild(org.eclipse.m2e.core.ui.internal.editing.PomEdits.removeChild) Text(org.eclipse.swt.widgets.Text) M2EUIUtils(org.eclipse.m2e.core.ui.internal.util.M2EUIUtils) IEditorInput(org.eclipse.ui.IEditorInput) PlatformUI(org.eclipse.ui.PlatformUI) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) ResourceTransfer(org.eclipse.ui.part.ResourceTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Window(org.eclipse.jface.window.Window) NAME(org.eclipse.m2e.core.ui.internal.editing.PomEdits.NAME) PomEdits.createElementWithText(org.eclipse.m2e.core.ui.internal.editing.PomEdits.createElementWithText) MavenImages(org.eclipse.m2e.core.ui.internal.MavenImages) PomEdits.removeIfNoChildElement(org.eclipse.m2e.core.ui.internal.editing.PomEdits.removeIfNoChildElement) Path(org.eclipse.core.runtime.Path) SWT(org.eclipse.swt.SWT) CI_MANAGEMENT(org.eclipse.m2e.core.ui.internal.editing.PomEdits.CI_MANAGEMENT) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Operation(org.eclipse.m2e.core.ui.internal.editing.PomEdits.Operation) SelectionListener(org.eclipse.swt.events.SelectionListener) ISSUE_MANAGEMENT(org.eclipse.m2e.core.ui.internal.editing.PomEdits.ISSUE_MANAGEMENT) URL(org.eclipse.m2e.core.ui.internal.editing.PomEdits.URL) PARENT(org.eclipse.m2e.core.ui.internal.editing.PomEdits.PARENT) StringLabelProvider(org.eclipse.m2e.editor.composites.StringLabelProvider) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) PomEdits(org.eclipse.m2e.core.ui.internal.editing.PomEdits) PomEdits.getChild(org.eclipse.m2e.core.ui.internal.editing.PomEdits.getChild) ArrayList(java.util.ArrayList) IContainer(org.eclipse.core.resources.IContainer) IMavenConstants(org.eclipse.m2e.core.internal.IMavenConstants) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) INCEPTION_YEAR(org.eclipse.m2e.core.ui.internal.editing.PomEdits.INCEPTION_YEAR) VERSION(org.eclipse.m2e.core.ui.internal.editing.PomEdits.VERSION) MavenRepositorySearchDialog(org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog) IFile(org.eclipse.core.resources.IFile) GridData(org.eclipse.swt.layout.GridData) OpenPomAction(org.eclipse.m2e.core.ui.internal.actions.OpenPomAction) LinkedHashSet(java.util.LinkedHashSet) Section(org.eclipse.ui.forms.widgets.Section) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) FileEditorInput(org.eclipse.ui.part.FileEditorInput) StackLayout(org.eclipse.swt.custom.StackLayout) ListEditorContentProvider(org.eclipse.m2e.editor.composites.ListEditorContentProvider) FormUtils.setText(org.eclipse.m2e.editor.pom.FormUtils.setText) PROPERTIES(org.eclipse.m2e.core.ui.internal.editing.PomEdits.PROPERTIES) Plugin(org.apache.maven.model.Plugin) ModifyListener(org.eclipse.swt.events.ModifyListener) DocumentBuilder(javax.xml.parsers.DocumentBuilder) MODULES(org.eclipse.m2e.core.ui.internal.editing.PomEdits.MODULES) MavenEditorImages(org.eclipse.m2e.editor.MavenEditorImages) GridLayout(org.eclipse.swt.layout.GridLayout) ArtifactKey(org.eclipse.m2e.core.embedder.ArtifactKey) LoggerFactory(org.slf4j.LoggerFactory) Hyperlink(org.eclipse.ui.forms.widgets.Hyperlink) JarFile(java.util.jar.JarFile) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) MavenModuleSelectionDialog(org.eclipse.m2e.editor.dialogs.MavenModuleSelectionDialog) 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) DropTargetAdapter(org.eclipse.swt.dnd.DropTargetAdapter) MavenPluginActivator(org.eclipse.m2e.core.internal.MavenPluginActivator) IPath(org.eclipse.core.runtime.IPath) ARTIFACT_ID(org.eclipse.m2e.core.ui.internal.editing.PomEdits.ARTIFACT_ID) OperationTuple(org.eclipse.m2e.core.ui.internal.editing.PomEdits.OperationTuple) TAG(org.eclipse.m2e.core.ui.internal.editing.PomEdits.TAG) Artifact(org.apache.maven.artifact.Artifact) ListEditorComposite(org.eclipse.m2e.editor.composites.ListEditorComposite) PomEdits.setText(org.eclipse.m2e.core.ui.internal.editing.PomEdits.setText) CCombo(org.eclipse.swt.custom.CCombo) Messages(org.eclipse.m2e.editor.internal.Messages) PomEdits.format(org.eclipse.m2e.core.ui.internal.editing.PomEdits.format) NLS(org.eclipse.osgi.util.NLS) WidthGroup(org.eclipse.m2e.core.ui.internal.wizards.WidthGroup) Display(org.eclipse.swt.widgets.Display) IManagedForm(org.eclipse.ui.forms.IManagedForm) MODULE(org.eclipse.m2e.core.ui.internal.editing.PomEdits.MODULE) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) PomEdits.textEquals(org.eclipse.m2e.core.ui.internal.editing.PomEdits.textEquals) WizardDialog(org.eclipse.jface.wizard.WizardDialog) SYSTEM(org.eclipse.m2e.core.ui.internal.editing.PomEdits.SYSTEM) Label(org.eclipse.swt.widgets.Label) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) PomEdits.findChilds(org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChilds) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) CONNECTION(org.eclipse.m2e.core.ui.internal.editing.PomEdits.CONNECTION) ORGANIZATION(org.eclipse.m2e.core.ui.internal.editing.PomEdits.ORGANIZATION) Image(org.eclipse.swt.graphics.Image) PACKAGING(org.eclipse.m2e.core.ui.internal.editing.PomEdits.PACKAGING) HashSet(java.util.HashSet) ProposalUtil(org.eclipse.m2e.core.ui.internal.util.ProposalUtil) JarEntry(java.util.jar.JarEntry) DESCRIPTION(org.eclipse.m2e.core.ui.internal.editing.PomEdits.DESCRIPTION) GROUP_ID(org.eclipse.m2e.core.ui.internal.editing.PomEdits.GROUP_ID) Node(org.w3c.dom.Node) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) PomEdits.findChild(org.eclipse.m2e.core.ui.internal.editing.PomEdits.findChild) FormUtils.nvl(org.eclipse.m2e.editor.pom.FormUtils.nvl) ICellModifier(org.eclipse.jface.viewers.ICellModifier) Packaging(org.eclipse.m2e.core.ui.internal.search.util.Packaging) Logger(org.slf4j.Logger) NodeList(org.w3c.dom.NodeList) 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) PomEdits.childAt(org.eclipse.m2e.core.ui.internal.editing.PomEdits.childAt) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) Element(org.w3c.dom.Element) ToolBarManager(org.eclipse.jface.action.ToolBarManager) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter) DEV_CONNECTION(org.eclipse.m2e.core.ui.internal.editing.PomEdits.DEV_CONNECTION) Control(org.eclipse.swt.widgets.Control) OpenPomAction(org.eclipse.m2e.core.ui.internal.actions.OpenPomAction) Action(org.eclipse.jface.action.Action) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) ArtifactKey(org.eclipse.m2e.core.embedder.ArtifactKey) Composite(org.eclipse.swt.widgets.Composite) ListEditorComposite(org.eclipse.m2e.editor.composites.ListEditorComposite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) ToolBarManager(org.eclipse.jface.action.ToolBarManager) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GridLayout(org.eclipse.swt.layout.GridLayout) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) GridData(org.eclipse.swt.layout.GridData) Job(org.eclipse.core.runtime.jobs.Job)

Example 3 with IndexedArtifactFile

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

the class MavenDependenciesWizardPage method createArtifacts.

private void createArtifacts(Composite composite) {
    Label mavenArtifactsLabel = new Label(composite, SWT.NONE);
    mavenArtifactsLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
    mavenArtifactsLabel.setText(org.eclipse.m2e.core.ui.internal.Messages.MavenDependenciesWizardPage_lblArtifacts);
    dependencyViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    dependencyViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 2));
    dependencyViewer.setUseHashlookup(true);
    dependencyViewer.setLabelProvider(new ArtifactLabelProvider());
    dependencyViewer.setComparator(new DependencySorter());
    dependencyViewer.add(dependencies);
    Button addDependencyButton = new Button(composite, SWT.PUSH);
    GridData gd_addDependencyButton = new GridData(SWT.FILL, SWT.TOP, false, false);
    addDependencyButton.setLayoutData(gd_addDependencyButton);
    addDependencyButton.setText(Messages.wizardProjectPageDependenciesAdd);
    addDependencyButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        MavenRepositorySearchDialog dialog = // 
        MavenRepositorySearchDialog.createSearchDependencyDialog(// 
        getShell(), org.eclipse.m2e.core.ui.internal.Messages.MavenDependenciesWizardPage_searchDialog_title, null, null, false);
        if (dialog.open() == Window.OK) {
            Object result = dialog.getFirstResult();
            if (result instanceof IndexedArtifactFile) {
                Dependency dependency = ((IndexedArtifactFile) result).getDependency();
                dependency.setScope(dialog.getSelectedScope());
                dependencyViewer.add(dependency);
                notifyListeners();
            } else if (result instanceof IndexedArtifact) {
                // If we have an ArtifactInfo, we add the first FileInfo it contains
                // which corresponds to the latest version of the artifact.
                Set<IndexedArtifactFile> files = ((IndexedArtifact) result).getFiles();
                if (files != null && !files.isEmpty()) {
                    dependencyViewer.add(files.iterator().next().getDependency());
                    notifyListeners();
                }
            }
        }
    }));
    final Button removeDependencyButton = new Button(composite, SWT.PUSH);
    removeDependencyButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true));
    removeDependencyButton.setText(Messages.wizardProjectPageDependenciesRemove);
    removeDependencyButton.setEnabled(false);
    removeDependencyButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        IStructuredSelection selection = (IStructuredSelection) dependencyViewer.getSelection();
        if (selection != null) {
            dependencyViewer.remove(selection.toArray());
            notifyListeners();
        }
    }));
    dependencyViewer.addSelectionChangedListener(event -> {
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        removeDependencyButton.setEnabled(selection.size() > 0);
    });
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Dependency(org.apache.maven.model.Dependency) Image(org.eclipse.swt.graphics.Image) ArrayList(java.util.ArrayList) IndexedArtifact(org.eclipse.m2e.core.internal.index.IndexedArtifact) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) MavenRepositorySearchDialog(org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog) GridData(org.eclipse.swt.layout.GridData) Viewer(org.eclipse.jface.viewers.Viewer) Button(org.eclipse.swt.widgets.Button) Set(java.util.Set) ProjectImportConfiguration(org.eclipse.m2e.core.project.ProjectImportConfiguration) List(java.util.List) Window(org.eclipse.jface.window.Window) MavenImages(org.eclipse.m2e.core.ui.internal.MavenImages) SWT(org.eclipse.swt.SWT) Messages(org.eclipse.m2e.core.ui.internal.Messages) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IWizardContainer(org.eclipse.jface.wizard.IWizardContainer) Label(org.eclipse.swt.widgets.Label) LabelProvider(org.eclipse.jface.viewers.LabelProvider) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) MavenRepositorySearchDialog(org.eclipse.m2e.core.ui.internal.dialogs.MavenRepositorySearchDialog) IndexedArtifact(org.eclipse.m2e.core.internal.index.IndexedArtifact) Label(org.eclipse.swt.widgets.Label) Dependency(org.apache.maven.model.Dependency) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Button(org.eclipse.swt.widgets.Button) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 4 with IndexedArtifactFile

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

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

the class AddDependencyAction 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.createSearchDependencyDialog(getShell(), Messages.AddDependencyAction_searchDialog_title, mp, prj, false);
    if (dialog.open() == Window.OK) {
        IndexedArtifactFile indexedArtifactFile = (IndexedArtifactFile) dialog.getFirstResult();
        if (indexedArtifactFile != null) {
            try {
                final Dependency dependency = indexedArtifactFile.getDependency();
                String selectedScope = dialog.getSelectedScope();
                dependency.setScope(selectedScope);
                if (indexedArtifactFile.version == null) {
                    dependency.setVersion(null);
                }
                performOnDOMDocument(new OperationTuple(file, (Operation) document -> {
                    Element depsEl = getChild(document.getDocumentElement(), DEPENDENCIES);
                    Element dep = findChild(depsEl, DEPENDENCY, childEquals(GROUP_ID, dependency.getGroupId()), childEquals(ARTIFACT_ID, dependency.getArtifactId()));
                    if (dep == null) {
                        dep = PomHelper.createDependency(depsEl, dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
                    } else {
                        if (dependency.getVersion() != null) {
                            setText(getChild(dep, VERSION), dependency.getVersion());
                        }
                    }
                    if (dependency.getType() != null && !"jar".equals(dependency.getType()) && !"null".equals(dependency.getType())) {
                        setText(getChild(dep, TYPE), dependency.getType());
                    }
                    if (dependency.getClassifier() != null) {
                        setText(getChild(dep, CLASSIFIER), dependency.getClassifier());
                    }
                    if (dependency.getScope() != null && !"compile".equals(dependency.getScope())) {
                        setText(getChild(dep, SCOPE), dependency.getScope());
                    }
                }));
            } catch (Exception ex) {
                String msg = NLS.bind(Messages.AddDependencyAction_error_msg, file);
                log.error(msg, ex);
                MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.AddDependencyAction_error_title, msg);
            }
        }
    }
}
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) Dependency(org.apache.maven.model.Dependency) Operation(org.eclipse.m2e.core.ui.internal.editing.PomEdits.Operation) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) IProject(org.eclipse.core.resources.IProject)

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