Commit 4f7d4464 authored by Florian's avatar Florian

added Kieker Monitoring Nature

Context menu only visible when Nature is set to project
parent 4fede0df
......@@ -59,15 +59,45 @@
</command>
<visibleWhen
checkEnabled="false">
<with
variable="selection">
<count
value="+">
</count>
</with>
<and>
<with variable="activeMenuSelection">
<iterate ifEmpty="false">
<reference
definitionId="kieker.tools.eclipse.monitoring.hasNature">
</reference>
</iterate>
</with>
<with
variable="selection">
<count
value="+">
</count>
</with>
</and>
</visibleWhen>
</menu>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.projectConfigure">
<command
commandId="kieker.tools.eclipse.monitoring.commands.AddProjectNature"
label="Convert to Kieker Monitoring Project"
style="push">
<visibleWhen
checkEnabled="false">
<with variable="activeMenuSelection">
<iterate ifEmpty="false">
<not>
<reference
definitionId="kieker.tools.eclipse.monitoring.hasNature">
</reference>
</not>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.handlers">
......@@ -79,6 +109,10 @@
class="kieker.tools.eclipse.monitoring.handlers.Properties"
commandId="kieker.tools.eclipse.monitoring.commands.Properties">
</handler>
<handler
class="kieker.tools.eclipse.monitoring.handlers.ProjectNatureHandler"
commandId="kieker.tools.eclipse.monitoring.commands.AddProjectNature">
</handler>
</extension>
<extension
point="org.eclipse.ui.commands">
......@@ -90,6 +124,32 @@
id="kieker.tools.eclipse.monitoring.commands.Properties"
name="ShowProperties">
</command>
<command
id="kieker.tools.eclipse.monitoring.commands.AddProjectNature"
name="Convert to Kieker Monitoring Project">
</command>
</extension>
<extension
id="kiekerMonitoringNature"
point="org.eclipse.core.resources.natures">
<runtime>
<run
class="kieker.tools.eclipse.monitoring.KiekerMonitoringNature">
</run>
</runtime>
</extension>
<extension
point="org.eclipse.core.expressions.definitions">
<definition
id="kieker.tools.eclipse.monitoring.hasNature">
<adapt
type="org.eclipse.core.resources.IProject">
<test
property="org.eclipse.core.resources.projectNature"
value="kieker.tools.eclipse.monitoring.kiekerMonitoringNature">
</test>
</adapt>
</definition>
</extension>
</plugin>
package kieker.tools.eclipse.monitoring;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;
public class KiekerMonitoringNature implements IProjectNature {
public static final String NATURE_ID = "kieker.tools.eclipse.monitoring.kiekerMonitoringNature";
private IProject project;
@Override
public void configure() throws CoreException {
// TODO Configure project
}
@Override
public void deconfigure() throws CoreException {
// TODO Deconfigure project
}
@Override
public IProject getProject() {
return project;
}
@Override
public void setProject(IProject project) {
this.project = project;
}
}
package kieker.tools.eclipse.monitoring.handlers;
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.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
import kieker.tools.eclipse.monitoring.KiekerMonitoringNature;
public class ProjectNatureHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
if (currentSelection instanceof IStructuredSelection) {
Object firstElement = ((IStructuredSelection) currentSelection).getFirstElement();
// Get an IResource as an adapter from the current selection
IAdapterManager adapterManager = Platform.getAdapterManager();
IResource resourceAdapter = adapterManager.getAdapter(firstElement, IResource.class);
if (resourceAdapter != null) {
IResource resource = resourceAdapter;
IProject project = resource.getProject();
try {
IProjectDescription description = project.getDescription();
String[] natures = description.getNatureIds();
String[] newNatures = new String[natures.length + 1];
System.arraycopy(natures, 0, newNatures, 0, natures.length);
// add our new "com.example.project.examplenature" id
newNatures[natures.length] = KiekerMonitoringNature.NATURE_ID;
// validate the natures
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IStatus status = workspace.validateNatureSet(newNatures);
// only apply new nature, if the status is ok
if (status.getCode() == IStatus.OK) {
description.setNatureIds(newNatures);
project.setDescription(description, null);
}
return status;
} catch (CoreException e) {
throw new ExecutionException(e.getMessage(), e);
}
}
}
return Status.OK_STATUS;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment