Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[eclipse] Add contributions to the configure menus.
Signed-off-by: Stéphane Galland <galland@arakhne.org>
- Loading branch information
1 parent
1484d56
commit 2c6f6fc
Showing
8 changed files
with
434 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/natures/AddSarlNatureHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* $Id$ | ||
* | ||
* SARL is an general-purpose agent programming language. | ||
* More details on http://www.sarl.io | ||
* | ||
* Copyright (C) 2014-2016 the original authors or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.sarl.eclipse.natures; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.text.MessageFormat; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.eclipse.core.commands.AbstractHandler; | ||
import org.eclipse.core.commands.ExecutionEvent; | ||
import org.eclipse.core.commands.ExecutionException; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.SubMonitor; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.eclipse.jface.dialogs.ProgressMonitorDialog; | ||
import org.eclipse.jface.operation.IRunnableWithProgress; | ||
import org.eclipse.jface.viewers.ISelection; | ||
import org.eclipse.jface.viewers.IStructuredSelection; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.eclipse.ui.handlers.HandlerUtil; | ||
|
||
/** | ||
* Action for converting the nature of a project to SARL. | ||
* | ||
* @author $Author: sgalland$ | ||
* @version $FullVersion$ | ||
* @mavengroupid $GroupId$ | ||
* @mavenartifactid $ArtifactId$ | ||
*/ | ||
public class AddSarlNatureHandler extends AbstractHandler { | ||
|
||
@Inject | ||
private SARLProjectConfigurator configurator; | ||
|
||
@Override | ||
public Object execute(ExecutionEvent event) throws ExecutionException { | ||
final ISelection currentSelection = HandlerUtil.getCurrentSelection(event); | ||
if (currentSelection instanceof IStructuredSelection) { | ||
final IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection; | ||
final List<IProject> projects = new ArrayList<>(); | ||
final Iterator<?> iterator = structuredSelection.iterator(); | ||
while (iterator.hasNext()) { | ||
final Object obj = iterator.next(); | ||
if (obj instanceof IJavaProject) { | ||
projects.add(((IJavaProject) obj).getProject()); | ||
} else if (obj instanceof IProject) { | ||
projects.add((IProject) obj); | ||
} | ||
} | ||
final Shell activeShell = HandlerUtil.getActiveShell(event); | ||
convertAllWithProgress(activeShell, projects); | ||
} | ||
return null; | ||
} | ||
|
||
private boolean convertAllWithProgress(Shell shell, List<IProject> projects) throws ExecutionException { | ||
final IRunnableWithProgress op = new IRunnableWithProgress() { | ||
@Override | ||
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { | ||
monitor.beginTask(Messages.RemoveSarlNatureHandler_0, projects.size()); | ||
final SubMonitor mon = SubMonitor.convert(monitor); | ||
try { | ||
for (final IProject project : projects) { | ||
doConvert(project, mon.newChild(1)); | ||
} | ||
} catch (ExecutionException e) { | ||
throw new InvocationTargetException(e); | ||
} finally { | ||
monitor.done(); | ||
} | ||
} | ||
}; | ||
try { | ||
new ProgressMonitorDialog(shell).run(true, true, op); | ||
} catch (InvocationTargetException exception) { | ||
throw new ExecutionException( | ||
MessageFormat.format(Messages.RemoveSarlNatureHandler_1, exception.getLocalizedMessage()), exception); | ||
} catch (InterruptedException exception) { | ||
//interrupted by user | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** Convert the given project. | ||
* | ||
* @param project the project to convert.. | ||
* @param monitor the progress monitor. | ||
* @throws ExecutionException if something going wrong. | ||
*/ | ||
protected void doConvert(IProject project, IProgressMonitor monitor) throws ExecutionException { | ||
monitor.setTaskName(MessageFormat.format(Messages.AddSarlNatureHandler_2, project.getName())); | ||
final SubMonitor mon = SubMonitor.convert(monitor, 2); | ||
if (this.configurator.canConfigure(project, Collections.emptySet(), mon.newChild(1))) { | ||
this.configurator.configure(project, Collections.emptySet(), mon.newChild(1)); | ||
} | ||
monitor.done(); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
eclipse-sarl/plugins/io.sarl.eclipse/src/io/sarl/eclipse/natures/IProjectUnconfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* $Id$ | ||
* | ||
* SARL is an general-purpose agent programming language. | ||
* More details on http://www.sarl.io | ||
* | ||
* Copyright (C) 2014-2016 the original authors or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.sarl.eclipse.natures; | ||
|
||
import com.google.inject.ImplementedBy; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
|
||
/** | ||
* Configurator for a SARL project. | ||
* | ||
* @author $Author: sgalland$ | ||
* @version $FullVersion$ | ||
* @mavengroupid $GroupId$ | ||
* @mavenartifactid $ArtifactId$ | ||
*/ | ||
@ImplementedBy(SARLProjectConfigurator.class) | ||
public interface IProjectUnconfigurator { | ||
|
||
/** Replies if the project can be unconfigured. | ||
* | ||
* @param project the project. | ||
* @param monitor the progress monitor. | ||
* @return <code>true</code> if the project could be unconfigured. | ||
*/ | ||
boolean canUnconfigure(IProject project, IProgressMonitor monitor); | ||
|
||
/** Unconfigure the given project. | ||
* | ||
* @param project the project. | ||
* @param monitor the progress monitor. | ||
* @throws CoreException if the project cannot be unconfigured. | ||
*/ | ||
void unconfigure(IProject project, IProgressMonitor monitor) throws CoreException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.