Commit 583c22a7 authored by Christian Wulf's avatar Christian Wulf

added error messages when the Kieker nature could not be added;

updated repository
parent da479c31
...@@ -54,4 +54,8 @@ public class Activator extends AbstractUIPlugin { ...@@ -54,4 +54,8 @@ public class Activator extends AbstractUIPlugin {
getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message)); getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message));
} }
public void logErrorMsgToErrorLog(final String message) {
getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message));
}
} }
...@@ -12,56 +12,67 @@ import org.eclipse.core.runtime.CoreException; ...@@ -12,56 +12,67 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdapterManager; import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.handlers.HandlerUtil;
import kieker.tools.eclipse.monitoring.KiekerMonitoringNature; import kieker.tools.eclipse.monitoring.*;
public class ProjectNatureHandler extends AbstractHandler { public class ProjectNatureHandler extends AbstractHandler {
@Override @Override
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection currentSelection = HandlerUtil.getCurrentSelection(event); ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
if (currentSelection instanceof IStructuredSelection) { if (!(currentSelection instanceof IStructuredSelection)) {
String message = String.format("Invalid selection type '%s'", currentSelection);
Activator.getDefault().logErrorMsgToErrorLog(message);
return null;
}
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);
Object firstElement = ((IStructuredSelection) currentSelection).getFirstElement(); if (resourceAdapter == null) {
String message = String.format("Cannot find an adapter for '%s'", firstElement);
Activator.getDefault().logErrorMsgToErrorLog(message);
return null;
}
// Get an IResource as an adapter from the current selection addNature(resourceAdapter);
IAdapterManager adapterManager = Platform.getAdapterManager();
IResource resourceAdapter = adapterManager.getAdapter(firstElement, IResource.class);
if (resourceAdapter != null) { return 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 private void addNature(IResource resourceAdapter) throws ExecutionException {
newNatures[natures.length] = KiekerMonitoringNature.NATURE_ID; 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);
// validate the natures // add our new "com.example.project.examplenature" id
IWorkspace workspace = ResourcesPlugin.getWorkspace(); newNatures[natures.length] = KiekerMonitoringNature.NATURE_ID;
IStatus status = workspace.validateNatureSet(newNatures);
// only apply new nature, if the status is ok // validate the natures
if (status.getCode() == IStatus.OK) { IWorkspace workspace = ResourcesPlugin.getWorkspace();
description.setNatureIds(newNatures); IStatus status = workspace.validateNatureSet(newNatures);
project.setDescription(description, null);
}
return status; // only apply new nature, if the status is ok
} catch (CoreException e) { if (status.getCode() == IStatus.OK) {
throw new ExecutionException(e.getMessage(), e); description.setNatureIds(newNatures);
} project.setDescription(description, null);
} else {
String message = String.format("Invalid nature status '%s'", status);
Activator.getDefault().logErrorMsgToErrorLog(message);
} }
} catch (CoreException e) {
throw new ExecutionException(e.getMessage(), e);
} }
return Status.OK_STATUS;
} }
} }
#Wed Jan 10 17:06:06 CET 2018 #Wed Jan 10 17:49:22 CET 2018
version=1 version=1
metadata.repository.factory.order=content.xml.xz,content.xml,\! metadata.repository.factory.order=content.xml.xz,content.xml,\!
artifact.repository.factory.order=artifacts.xml.xz,artifacts.xml,\! artifact.repository.factory.order=artifacts.xml.xz,artifacts.xml,\!
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