Skip to content
This repository has been archived by the owner on Feb 11, 2020. It is now read-only.

Commit

Permalink
Import binary project from right-click Maven menu
Browse files Browse the repository at this point in the history
... works for selection in Maven Dependencies classpath
container. As a good side effect, the import wizard now
generally honours current selection.

Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
  • Loading branch information
ifedorenko committed Dec 21, 2012
1 parent ea9fb32 commit 6cc536f
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 20 deletions.
31 changes: 30 additions & 1 deletion com.ifedorenko.m2e.binaryproject.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,37 @@
class="com.ifedorenko.m2e.binaryproject.ui.internal.BinaryProjectImportWizard"
icon="icons/binary_project.gif"
id="com.ifedorenko.m2e.binaryproject.ui.binaryProjectImportWizard"
name="Materialize Maven Binary Projects">
name="Materialize Maven Binary Project">
</wizard>
</extension>
<extension
point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
id="com.ifedorenko.m2e.binaryproject.ui.importBinaryProject"
objectClass="org.eclipse.jdt.core.IPackageFragmentRoot">
<action
class="com.ifedorenko.m2e.binaryproject.ui.internal.BinaryProjectImportAction"
enablesFor="+"
icon="icons/binary_project.gif"
id="com.ifedorenko.m2e.binaryproject.ui.action.importBinaryProjects"
label="Materialize Maven Binary Project"
menubarPath="org.eclipse.m2e.classpathMenu/import"
style="push">
</action>
<enablement>
<and>
<test
property="org.eclipse.m2e.hasArtifactKey">
</test>
<not>
<test
property="org.eclipse.m2e.hasProjectArtifactKey">
</test>
</not>
</and>
</enablement>
</objectContribution>
</extension>

</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*******************************************************************************
* Copyright (c) 2012 Igor Fedorenko
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Igor Fedorenko - initial API and implementation
*******************************************************************************/
package com.ifedorenko.m2e.binaryproject.ui.internal;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;

public class BinaryProjectImportAction
implements IObjectActionDelegate
{

private IStructuredSelection selection;

private IWorkbench workbench;

private IWorkbenchPartSite site;

@Override
public void run( IAction action )
{
BinaryProjectImportWizard wizard = new BinaryProjectImportWizard();
wizard.init( workbench, selection );
if ( !wizard.getInitialDependencies().isEmpty() )
{
WizardDialog dialog = new WizardDialog( site.getShell(), wizard );
dialog.open();
}
else
{
wizard.dispose();
}
}

@Override
public void selectionChanged( IAction action, ISelection selection )
{
if ( selection instanceof IStructuredSelection )
{
this.selection = (IStructuredSelection) selection;
}
else
{
selection = null;
}
}

@Override
public void setActivePart( IAction action, IWorkbenchPart targetPart )
{
site = targetPart.getSite();
workbench = site.getWorkbenchWindow().getWorkbench();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
package com.ifedorenko.m2e.binaryproject.ui.internal;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.apache.maven.model.Dependency;
Expand All @@ -22,6 +24,7 @@
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.project.ProjectImportConfiguration;
import org.eclipse.m2e.core.ui.internal.actions.SelectionUtil;
import org.eclipse.m2e.core.ui.internal.wizards.MavenDependenciesWizardPage;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
Expand All @@ -38,13 +41,50 @@ public class BinaryProjectImportWizard

private MavenDependenciesWizardPage artifactsPage;

private List<Dependency> initialDependencies;

public BinaryProjectImportWizard()
{
}

@Override
public void init( IWorkbench workbench, IStructuredSelection selection )
{
final List<Dependency> dependencies = new ArrayList<Dependency>();
for ( Iterator<?> it = selection.iterator(); it.hasNext(); )
{
Object element = it.next();
ArtifactKey artifactKey = SelectionUtil.getType( element, ArtifactKey.class );
if ( artifactKey != null )
{
Dependency d = new Dependency();
d.setGroupId( artifactKey.getGroupId() );
d.setArtifactId( artifactKey.getArtifactId() );
d.setVersion( artifactKey.getVersion() );
d.setClassifier( artifactKey.getClassifier() );
dependencies.add( d );
}
}
artifactsPage =
new MavenDependenciesWizardPage( new ProjectImportConfiguration(), "Artifacts",
"Select artifacts to import" )
{
@Override
protected void createAdvancedSettings( Composite composite, GridData gridData )
{
// TODO profile can theoretically be usedful
}
};
artifactsPage.setDependencies( dependencies.toArray( new Dependency[dependencies.size()] ) );
artifactsPage.addListener( new ISelectionChangedListener()
{
@Override
public void selectionChanged( SelectionChangedEvent event )
{
getContainer().updateButtons();
}
} );
this.initialDependencies = Collections.unmodifiableList( dependencies );
}

@Override
Expand Down Expand Up @@ -87,25 +127,11 @@ public boolean canFinish()
@Override
public void addPages()
{
artifactsPage =
new MavenDependenciesWizardPage( new ProjectImportConfiguration(), "Artifacts",
"Select artifacts to import" )
{
@Override
protected void createAdvancedSettings( Composite composite, GridData gridData )
{
// TODO profile can theoretically be usedful
}
};
artifactsPage.setDependencies( new Dependency[0] );
artifactsPage.addListener( new ISelectionChangedListener()
{
@Override
public void selectionChanged( SelectionChangedEvent event )
{
getContainer().updateButtons();
}
} );
addPage( artifactsPage );
}

public List<Dependency> getInitialDependencies()
{
return initialDependencies;
}
}

0 comments on commit 6cc536f

Please sign in to comment.