Search in sources :

Example 1 with OpenPomAction

use of org.eclipse.m2e.core.ui.internal.actions.OpenPomAction in project m2e-core by eclipse-m2e.

the class M2EEditorTest method testOpenPomEditor.

@Test
public void testOpenPomEditor() throws Exception {
    IProject project = null;
    try (InputStream stream = getClass().getResourceAsStream("pom.xml")) {
        project = createProject("basic", stream);
        IProjectDescription desc = project.getDescription();
        desc.setNatureIds(new String[] { IMavenConstants.NATURE_ID });
        project.setDescription(desc, monitor);
        refreshMavenProject(project);
    }
    waitForJobsToComplete();
    MavenPomEditor editor = (MavenPomEditor) new OpenPomAction().openPomEditor("org.apache.commons", "commons-math3", "3.2", MavenPlugin.getMavenProjectRegistry().getProject(project).getMavenProject(), new NullProgressMonitor());
    assertNotEquals(-1, editor.getActivePage());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) MavenPomEditor(org.eclipse.m2e.editor.pom.MavenPomEditor) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IProjectDescription(org.eclipse.core.resources.IProjectDescription) OpenPomAction(org.eclipse.m2e.core.ui.internal.actions.OpenPomAction) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 2 with OpenPomAction

use of org.eclipse.m2e.core.ui.internal.actions.OpenPomAction in project m2e-core by eclipse-m2e.

the class MavenRepositoryView method makeActions.

private void makeActions() {
    collapseAllAction = new Action(Messages.MavenRepositoryView_btnCollapse) {

        @Override
        public void run() {
            viewer.collapseAll();
        }
    };
    collapseAllAction.setToolTipText(Messages.MavenRepositoryView_btnCollapse_tooltip);
    collapseAllAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_ELCL_COLLAPSEALL));
    reloadSettings = new Action(Messages.MavenRepositoryView_action_reload) {

        @Override
        public void run() {
            String msg = Messages.MavenRepositoryView_reload_msg;
            boolean res = // 
            MessageDialog.openConfirm(// 
            getViewSite().getShell(), Messages.MavenRepositoryView_reload_title, msg);
            if (res) {
                Job job = new WorkspaceJob(Messages.MavenRepositoryView_job_reloading) {

                    @Override
                    public IStatus runInWorkspace(IProgressMonitor monitor) {
                        try {
                            MavenPlugin.getMaven().reloadSettings();
                        } catch (CoreException ex) {
                            return ex.getStatus();
                        }
                        return Status.OK_STATUS;
                    }
                };
                job.schedule();
            }
        }
    };
    reloadSettings.setImageDescriptor(MavenImages.REFRESH);
    openPomAction = new BaseSelectionListenerAction(Messages.MavenRepositoryView_action_open) {

        @Override
        public void run() {
            ISelection selection = viewer.getSelection();
            Object element = ((IStructuredSelection) selection).getFirstElement();
            if (element instanceof IArtifactNode) {
                Artifact f = ((IArtifactNode) element).getArtifact();
                OpenPomAction.openEditor(f.getGroupId(), f.getArtifactId(), f.getVersion(), null);
            }
        }

        @Override
        protected boolean updateSelection(IStructuredSelection selection) {
            return selection.getFirstElement() instanceof IArtifactNode;
        }
    };
    openPomAction.setToolTipText(Messages.MavenRepositoryView_action_open_tooltip);
    openPomAction.setImageDescriptor(MavenImages.POM);
    copyUrlAction = new BaseSelectionListenerAction(Messages.MavenRepositoryView_action_copy) {

        @Override
        public void run() {
            Object element = getStructuredSelection().getFirstElement();
            String url = null;
            if (element instanceof RepositoryNode) {
                url = ((RepositoryNode) element).getRepositoryUrl();
            } else if (element instanceof IndexedArtifact) {
            // 
            } else if (element instanceof IndexedArtifactFile) {
            // 
            }
            if (url != null) {
                Clipboard clipboard = new Clipboard(Display.getCurrent());
                clipboard.setContents(new String[] { url }, new Transfer[] { TextTransfer.getInstance() });
                clipboard.dispose();
            }
        }

        @Override
        protected boolean updateSelection(IStructuredSelection selection) {
            Object element = selection.getFirstElement();
            return element instanceof RepositoryNode;
        }
    };
    copyUrlAction.setToolTipText(Messages.MavenRepositoryView_action_copy_tooltip);
    copyUrlAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
    // materializeProjectAction = new BaseSelectionListenerAction(Messages.MavenRepositoryView_action_materialize) {
    // public void run() {
    // Object element = getStructuredSelection().getFirstElement();
    // if(element instanceof IndexedArtifactFileNode){
    // MaterializeAction action = new MaterializeAction();
    // StructuredSelection sel = new StructuredSelection(new Object[]{((IndexedArtifactFileNode) element).getIndexedArtifactFile()});
    // action.selectionChanged(this, sel);
    // action.run(this);
    // }
    // }
    // 
    // protected boolean updateSelection(IStructuredSelection selection) {
    // return selection.getFirstElement() instanceof IndexedArtifactFileNode;
    // }
    // };
    // materializeProjectAction.setImageDescriptor(MavenImages.IMPORT_PROJECT);
    viewer.addSelectionChangedListener(openPomAction);
    viewer.addSelectionChangedListener(copyUrlAction);
// viewer.addSelectionChangedListener(materializeProjectAction);
}
Also used : IAction(org.eclipse.jface.action.IAction) OpenPomAction(org.eclipse.m2e.core.ui.internal.actions.OpenPomAction) Action(org.eclipse.jface.action.Action) BaseSelectionListenerAction(org.eclipse.ui.actions.BaseSelectionListenerAction) IStatus(org.eclipse.core.runtime.IStatus) IndexedArtifact(org.eclipse.m2e.core.internal.index.IndexedArtifact) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IArtifactNode(org.eclipse.m2e.core.ui.internal.views.nodes.IArtifactNode) BaseSelectionListenerAction(org.eclipse.ui.actions.BaseSelectionListenerAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IMavenRepositoryNode(org.eclipse.m2e.core.ui.internal.views.nodes.IMavenRepositoryNode) RepositoryNode(org.eclipse.m2e.core.ui.internal.views.nodes.RepositoryNode) IndexedArtifact(org.eclipse.m2e.core.internal.index.IndexedArtifact) Artifact(org.eclipse.aether.artifact.Artifact) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IndexedArtifactFile(org.eclipse.m2e.core.internal.index.IndexedArtifactFile) ISelection(org.eclipse.jface.viewers.ISelection) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Clipboard(org.eclipse.swt.dnd.Clipboard) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob)

Example 3 with OpenPomAction

use of org.eclipse.m2e.core.ui.internal.actions.OpenPomAction in project m2e-core-tests by tesla.

the class OpenPomActionTest method test454759_openEditor.

@Test
public void test454759_openEditor() throws Exception {
    IProject project = importProject("projects/454759_openEditor/pom.xml");
    waitForJobsToComplete();
    IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getProject(project);
    MavenProject mavenProject = facade.getMavenProject(monitor);
    OpenPomAction action = new OpenPomAction() {

        @Override
        protected void openDialog(String msg) {
        // don't open any dialogs
        }
    };
    IEditorPart editor = action.openPomEditor("test", "b", "1.0", null, monitor);
    assertNull(editor);
    editor = action.openPomEditor("test", "b", "1.0", mavenProject, monitor);
    assertNotNull(editor);
    assertTrue(editor instanceof MavenPomEditor);
}
Also used : MavenPomEditor(org.eclipse.m2e.editor.pom.MavenPomEditor) MavenProject(org.apache.maven.project.MavenProject) OpenPomAction(org.eclipse.m2e.core.ui.internal.actions.OpenPomAction) IEditorPart(org.eclipse.ui.IEditorPart) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Aggregations

OpenPomAction (org.eclipse.m2e.core.ui.internal.actions.OpenPomAction)3 IProject (org.eclipse.core.resources.IProject)2 MavenPomEditor (org.eclipse.m2e.editor.pom.MavenPomEditor)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 MavenProject (org.apache.maven.project.MavenProject)1 Artifact (org.eclipse.aether.artifact.Artifact)1 IProjectDescription (org.eclipse.core.resources.IProjectDescription)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 Action (org.eclipse.jface.action.Action)1 IAction (org.eclipse.jface.action.IAction)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IndexedArtifact (org.eclipse.m2e.core.internal.index.IndexedArtifact)1