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 {
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;
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;
import kieker.tools.eclipse.monitoring.*;
public class ProjectNatureHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
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
IAdapterManager adapterManager = Platform.getAdapterManager();
IResource resourceAdapter = adapterManager.getAdapter(firstElement, IResource.class);
addNature(resourceAdapter);
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);
return null;
}
// add our new "com.example.project.examplenature" id
newNatures[natures.length] = KiekerMonitoringNature.NATURE_ID;
private void addNature(IResource resourceAdapter) throws ExecutionException {
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
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IStatus status = workspace.validateNatureSet(newNatures);
// add our new "com.example.project.examplenature" id
newNatures[natures.length] = KiekerMonitoringNature.NATURE_ID;
// only apply new nature, if the status is ok
if (status.getCode() == IStatus.OK) {
description.setNatureIds(newNatures);
project.setDescription(description, null);
}
// validate the natures
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IStatus status = workspace.validateNatureSet(newNatures);
return status;
} catch (CoreException e) {
throw new ExecutionException(e.getMessage(), e);
}
// only apply new nature, if the status is ok
if (status.getCode() == IStatus.OK) {
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
metadata.repository.factory.order=content.xml.xz,content.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