Commit 05b71727 authored by Florian's avatar Florian

refactoring and improved open file handler

parent f74d77db
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
name="Handler" name="Handler"
point="org.eclipse.ui.handlers"> point="org.eclipse.ui.handlers">
<handler <handler
class="kieker.tools.eclipse.analysis.handler.TraceTreeViewHandler" class="kieker.tools.eclipse.analysis.handler.folder.TraceTreeViewHandler"
commandId="kieker.tools.eclipse.analysis.commands.showTracesCommand"> commandId="kieker.tools.eclipse.analysis.commands.showTracesCommand">
<enabledWhen> <enabledWhen>
<with <with
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
</enabledWhen> </enabledWhen>
</handler> </handler>
<handler <handler
class="kieker.tools.eclipse.analysis.handler.AggregatedTraceTreeViewHandler" class="kieker.tools.eclipse.analysis.handler.folder.AggregatedTraceTreeViewHandler"
commandId="kieker.tools.eclipse.analysis.commands.showAggregatedTracesCommand"> commandId="kieker.tools.eclipse.analysis.commands.showAggregatedTracesCommand">
<enabledWhen> <enabledWhen>
<with variable="activeMenuSelection"> <with variable="activeMenuSelection">
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
</enabledWhen> </enabledWhen>
</handler> </handler>
<handler <handler
class="kieker.tools.eclipse.analysis.handler.OperationCallTreeViewHandler" class="kieker.tools.eclipse.analysis.handler.folder.OperationCallTreeViewHandler"
commandId="kieker.tools.eclipse.analysis.commands.showOperationCallsCommand"> commandId="kieker.tools.eclipse.analysis.commands.showOperationCallsCommand">
<enabledWhen> <enabledWhen>
<with variable="activeMenuSelection"> <with variable="activeMenuSelection">
...@@ -109,7 +109,7 @@ ...@@ -109,7 +109,7 @@
</enabledWhen> </enabledWhen>
</handler> </handler>
<handler <handler
class="kieker.tools.eclipse.analysis.handler.AggregatedOperationCallTreeViewHandler" class="kieker.tools.eclipse.analysis.handler.folder.AggregatedOperationCallTreeViewHandler"
commandId="kieker.tools.eclipse.analysis.commands.showAggregatedOperationCallsCommand"> commandId="kieker.tools.eclipse.analysis.commands.showAggregatedOperationCallsCommand">
<enabledWhen> <enabledWhen>
<with <with
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
</enabledWhen> </enabledWhen>
</handler> </handler>
<handler <handler
class="kieker.tools.eclipse.analysis.handler.ShowMonitoringLogsHandler" class="kieker.tools.eclipse.analysis.handler.folder.ShowMonitoringLogsHandler"
commandId="kieker.tools.eclipse.analysis.commands.showMonitoringStatsCommand"> commandId="kieker.tools.eclipse.analysis.commands.showMonitoringStatsCommand">
<enabledWhen> <enabledWhen>
<with <with
...@@ -158,11 +158,11 @@ ...@@ -158,11 +158,11 @@
</enabledWhen> </enabledWhen>
</handler> </handler>
<handler <handler
class="kieker.tools.eclipse.analysis.handler.SelectTraceFromOpCallHandler" class="kieker.tools.eclipse.analysis.handler.view.SelectTraceFromOpCallHandler"
commandId="kieker.tools.eclipse.analysis.commands.selectTraceFromOpCallCommand"> commandId="kieker.tools.eclipse.analysis.commands.selectTraceFromOpCallCommand">
</handler> </handler>
<handler <handler
class="kieker.tools.eclipse.analysis.handler.SelectOpCallsFromAggregatedOpCallHandler" class="kieker.tools.eclipse.analysis.handler.view.SelectOpCallsFromAggregatedOpCallHandler"
commandId="kieker.tools.eclipse.analysis.commands.selectOpCallFromAggrOpCallCommand"> commandId="kieker.tools.eclipse.analysis.commands.selectOpCallFromAggrOpCallCommand">
</handler> </handler>
</extension> </extension>
...@@ -261,21 +261,21 @@ ...@@ -261,21 +261,21 @@
<extension <extension
point="org.eclipse.core.expressions.propertyTesters"> point="org.eclipse.core.expressions.propertyTesters">
<propertyTester <propertyTester
class="kieker.tools.eclipse.analysis.helper.KiekerLogFolderTester" class="kieker.tools.eclipse.analysis.tester.KiekerLogFolderTester"
id="kieker.tools.eclipse.analysis.helper.kiekerLogFolderTester" id="kieker.tools.eclipse.analysis.helper.kiekerLogFolderTester"
namespace="kieker.tools.eclipse.analysis.helper.kiekerLogFolderTester" namespace="kieker.tools.eclipse.analysis.helper.kiekerLogFolderTester"
properties="checkFolder" properties="checkFolder"
type="org.eclipse.core.resources.IResource"> type="org.eclipse.core.resources.IResource">
</propertyTester> </propertyTester>
<propertyTester <propertyTester
class="kieker.tools.eclipse.analysis.helper.OpCallTabTester" class="kieker.tools.eclipse.analysis.tester.OpCallTabTester"
id="kieker.tools.eclipse.analysis.helper.opCallTabTester" id="kieker.tools.eclipse.analysis.helper.opCallTabTester"
namespace="kieker.tools.eclipse.analysis.helper.opCallTabTester" namespace="kieker.tools.eclipse.analysis.helper.opCallTabTester"
properties="checkOpCallTab" properties="checkOpCallTab"
type="kieker.analysis.domain.OperationCall"> type="kieker.analysis.domain.OperationCall">
</propertyTester> </propertyTester>
<propertyTester <propertyTester
class="kieker.tools.eclipse.analysis.helper.OpCallTabTester" class="kieker.tools.eclipse.analysis.tester.OpCallTabTester"
id="kieker.tools.eclipse.analysis.helper.aggrOpCallTabTester" id="kieker.tools.eclipse.analysis.helper.aggrOpCallTabTester"
namespace="kieker.tools.eclipse.analysis.helper.aggrOpCallTabTester" namespace="kieker.tools.eclipse.analysis.helper.aggrOpCallTabTester"
properties="checkAggrOpCallTab" properties="checkAggrOpCallTab"
......
...@@ -32,19 +32,19 @@ import kieker.tools.eclipse.analysis.provider.DataProvider; ...@@ -32,19 +32,19 @@ import kieker.tools.eclipse.analysis.provider.DataProvider;
public class OpenFileHandler extends AbstractHandler { public class OpenFileHandler extends AbstractHandler {
IType type; IType type;
IProject project; // TODO need to set project... IProject project;
@Override @Override
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection sel = HandlerUtil.getCurrentSelection(event); ISelection sel = HandlerUtil.getCurrentSelection(event);
if (sel instanceof IStructuredSelection) { if (sel instanceof IStructuredSelection) {
Object selected= ((IStructuredSelection) sel).getFirstElement(); Object selected = ((IStructuredSelection) sel).getFirstElement();
project = DataProvider.getProject(); project = DataProvider.getProject();
openFile(selected); openFile(selected);
} }
return null; return null;
} }
private void openFile(Object selectedNode) { private void openFile(Object selectedNode) {
if (project != null) { if (project != null) {
String component = null; String component = null;
...@@ -63,34 +63,34 @@ public class OpenFileHandler extends AbstractHandler { ...@@ -63,34 +63,34 @@ public class OpenFileHandler extends AbstractHandler {
try { try {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IFile file = getFile(component); IFile file = getFile(component);
if(file == null) if (file == null)
return; return;
IEditorPart editorPart = IDE.openEditor(page, file); IEditorPart editorPart = IDE.openEditor(page, file);
highlightCodeline(editorPart, component, operation); highlightCodeline(editorPart, operation);
} catch (CoreException e) { } catch (CoreException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }
private IFile getFile(String filename) { private IFile getFile(String filename) {
try { try {
IJavaProject javaProject = JavaCore.create(project); IJavaProject javaProject = JavaCore.create(project);
if(javaProject != null) if (javaProject != null)
type = javaProject.findType(filename); type = javaProject.findType(filename);
IPath path = null; IPath path = null;
if(type != null) if (type != null)
path = type.getPath(); path = type.getPath();
if(path != null) if (path != null)
return ResourcesPlugin.getWorkspace().getRoot().getFile(path); return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
} catch (JavaModelException e) { } catch (JavaModelException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
private void highlightCodeline(IEditorPart editorPart, String component, String operation) { private void highlightCodeline(IEditorPart editorPart, String operation) {
if (editorPart instanceof ITextEditor) { if (editorPart instanceof ITextEditor) {
ITextEditor editor = (ITextEditor) editorPart; ITextEditor editor = (ITextEditor) editorPart;
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput()); IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
...@@ -102,42 +102,54 @@ public class OpenFileHandler extends AbstractHandler { ...@@ -102,42 +102,54 @@ public class OpenFileHandler extends AbstractHandler {
e1.printStackTrace(); e1.printStackTrace();
} }
operation = operation.replace(component + ".", ""); String parameter = operation.substring(operation.indexOf("("), operation.length());
parameter = parameter.replace("(", "").replace(")", "").replace(" ", "");
String[] parameters;
if (parameter.equals("")) {
parameters = new String[0];
} else {
parameters = parameter.split(",");
}
int length = 0; operation = operation.substring(0, operation.indexOf("("));
int offset = 0; String method = operation.substring(operation.lastIndexOf(".") + 1, operation.length());
String returnType = operation.substring(0, operation.lastIndexOf(" "));
returnType = returnType.substring(returnType.lastIndexOf(" ") + 1, returnType.length());
returnType = returnType.substring(returnType.lastIndexOf(".") + 1, returnType.length());
for (IMethod meth : methArray) { methodloop: for (IMethod meth : methArray) {
try { try {
boolean hasName = operation.contains(meth.getElementName()); boolean hasName = method.contains(meth.getElementName());
if(!hasName) String returnTypeMeth = Signature.getSignatureSimpleName(meth.getReturnType());
hasName &= returnTypeMeth.contains(returnType);
if (!hasName)
continue; continue;
boolean hasParams = true; String[] parametersMeth = meth.getParameterTypes();
String[] parameters = meth.getParameterTypes();
if (parameters.length != parametersMeth.length)
continue;
for (String param : parameters) { for (String param : parameters) {
param = Signature.getSignatureSimpleName(param); param = param.substring(param.lastIndexOf(".") + 1, param.length());
int index = param.indexOf("<"); boolean contains = false;
if(index > 0){ for (String paramMeth : parametersMeth) {
param = param.substring(0, index); paramMeth = Signature.getSignatureSimpleName(paramMeth);
contains |= paramMeth.contains(param);
} }
if (!operation.contains(param)) { if (!contains)
hasParams = false; continue methodloop;
}
}
if (hasName && hasParams) {
length = meth.getSourceRange().getLength();
offset = meth.getSourceRange().getOffset();
break;
} }
editor.selectAndReveal(meth.getSourceRange().getOffset(), meth.getSourceRange().getLength());
break;
} catch (JavaModelException e) { } catch (JavaModelException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
editor.selectAndReveal(offset, length);
} }
} }
} }
......
package kieker.tools.eclipse.analysis.handler;
import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
import kieker.analysis.domain.AggregatedOperationCall;
import kieker.tools.eclipse.analysis.provider.label.ComponentLabelProvider;
import kieker.tools.eclipse.analysis.provider.label.ContainerLabelProvider;
import kieker.tools.eclipse.analysis.provider.label.OperationLabelProvider;
import kieker.tools.eclipse.analysis.view.AnalysisTreeView;
public class SelectOpCallsFromAggregatedOpCallHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
IViewPart partView = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
.showView(AnalysisTreeView.VIEWNAME);
ISelection sel = HandlerUtil.getCurrentSelection(event);
if (sel instanceof IStructuredSelection) {
Object selected = ((IStructuredSelection) sel).getFirstElement();
if (selected instanceof AggregatedOperationCall) {
AggregatedOperationCall aggrOpCall = (AggregatedOperationCall) selected;
ContainerLabelProvider containerLabelProvider = new ContainerLabelProvider();
String container = containerLabelProvider.getString(aggrOpCall);
ComponentLabelProvider componentLabelProvider = new ComponentLabelProvider();
String component = componentLabelProvider.getString(aggrOpCall);
OperationLabelProvider operationLabelProvider = new OperationLabelProvider();
String operation = operationLabelProvider.getString(aggrOpCall);
if (partView instanceof AnalysisTreeView) {
AnalysisTreeView view = (AnalysisTreeView) partView;
List<Text> filterTexts = view.getFilterTextLists().get(AnalysisTreeView.OPCALLTAB);
filterTexts.get(0).setText(operation);
filterTexts.get(1).setText(component);
filterTexts.get(2).setText(container);
view.getViewerList().get(AnalysisTreeView.OPCALLTAB).refresh();
view.setFocus(AnalysisTreeView.OPCALLTAB);
}
}
}
} catch (PartInitException e) {
e.printStackTrace();
}
return null;
}
}
package kieker.tools.eclipse.analysis.handler; package kieker.tools.eclipse.analysis.handler.folder;
import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
......
package kieker.tools.eclipse.analysis.handler; package kieker.tools.eclipse.analysis.handler.folder;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.ui.IViewPart; import org.eclipse.ui.IViewPart;
......
package kieker.tools.eclipse.analysis.handler; package kieker.tools.eclipse.analysis.handler.folder;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.ui.IViewPart; import org.eclipse.ui.IViewPart;
......
package kieker.tools.eclipse.analysis.handler; package kieker.tools.eclipse.analysis.handler.folder;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.ui.IViewPart; import org.eclipse.ui.IViewPart;
......
package kieker.tools.eclipse.analysis.handler; package kieker.tools.eclipse.analysis.handler.folder;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.ui.IViewPart; import org.eclipse.ui.IViewPart;
......
package kieker.tools.eclipse.analysis.handler; package kieker.tools.eclipse.analysis.handler.folder;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.ui.IViewPart; import org.eclipse.ui.IViewPart;
......
package kieker.tools.eclipse.analysis.handler; package kieker.tools.eclipse.analysis.handler.view;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ColumnViewer;
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.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.ui.IViewPart; import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PartInitException; import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.handlers.HandlerUtil;
import kieker.analysis.domain.OperationCall;
import kieker.tools.eclipse.analysis.view.AnalysisTreeView; import kieker.tools.eclipse.analysis.view.AnalysisTreeView;
public class SelectTraceFromOpCallHandler extends AbstractHandler { public abstract class AbstractViewHandler extends AbstractHandler {
@Override @Override
public Object execute(ExecutionEvent event) throws ExecutionException { public Object execute(ExecutionEvent event) throws ExecutionException {
...@@ -28,30 +21,17 @@ public class SelectTraceFromOpCallHandler extends AbstractHandler { ...@@ -28,30 +21,17 @@ public class SelectTraceFromOpCallHandler extends AbstractHandler {
ISelection sel = HandlerUtil.getCurrentSelection(event); ISelection sel = HandlerUtil.getCurrentSelection(event);
if (sel instanceof IStructuredSelection) { if (sel instanceof IStructuredSelection) {
Object selected= ((IStructuredSelection) sel).getFirstElement(); Object selected= ((IStructuredSelection) sel).getFirstElement();
execute(selected, partView);
if (selected instanceof OperationCall) {
OperationCall opCall = (OperationCall) selected;
List<Object> path = new ArrayList<>();
path.add(opCall);
if (partView instanceof AnalysisTreeView) {
AnalysisTreeView view = (AnalysisTreeView) partView;
List<ColumnViewer> viewer = view.getViewerList();
ColumnViewer colView = viewer.get(AnalysisTreeView.TRACETAB);
colView.setSelection(new TreeSelection(new TreePath(path.toArray())), true);
view.setFocus(AnalysisTreeView.TRACETAB);
}
}
} }
} catch (PartInitException e) { } catch (PartInitException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
public abstract void execute(Object selected, IViewPart partView);
} }
package kieker.tools.eclipse.analysis.handler.view;
import java.util.List;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IViewPart;
import kieker.analysis.domain.AggregatedOperationCall;
import kieker.tools.eclipse.analysis.provider.label.ComponentLabelProvider;
import kieker.tools.eclipse.analysis.provider.label.ContainerLabelProvider;
import kieker.tools.eclipse.analysis.provider.label.OperationLabelProvider;
import kieker.tools.eclipse.analysis.view.AnalysisTreeView;
public class SelectOpCallsFromAggregatedOpCallHandler extends AbstractViewHandler {
@Override
public void execute(Object selected, IViewPart partView) {
if (selected instanceof AggregatedOperationCall) {
AggregatedOperationCall aggrOpCall = (AggregatedOperationCall) selected;
String container = new ContainerLabelProvider().getString(aggrOpCall);
String component = new ComponentLabelProvider().getString(aggrOpCall);
String operation = new OperationLabelProvider().getString(aggrOpCall);
if (partView instanceof AnalysisTreeView) {
AnalysisTreeView view = (AnalysisTreeView) partView;
List<Text> filterTexts = view.getFilterTextLists().get(AnalysisTreeView.OPCALLTAB);
filterTexts.get(0).setText(operation);
filterTexts.get(1).setText(component);
filterTexts.get(2).setText(container);
view.getViewerList().get(AnalysisTreeView.OPCALLTAB).refresh();
view.setFocus(AnalysisTreeView.OPCALLTAB);
}
}
}
}
package kieker.tools.eclipse.analysis.handler.view;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.ui.IViewPart;
import kieker.analysis.domain.OperationCall;
import kieker.tools.eclipse.analysis.view.AnalysisTreeView;
public class SelectTraceFromOpCallHandler extends AbstractViewHandler {
@Override
public void execute(Object selected, IViewPart partView){
if (selected instanceof OperationCall) {
OperationCall opCall = (OperationCall) selected;
List<Object> path = new ArrayList<>();
path.add(opCall);
if (partView instanceof AnalysisTreeView) {
AnalysisTreeView view = (AnalysisTreeView) partView;
List<ColumnViewer> viewer = view.getViewerList();
ColumnViewer colView = viewer.get(AnalysisTreeView.TRACETAB);
colView.setSelection(new TreeSelection(new TreePath(path.toArray())), true);
view.setFocus(AnalysisTreeView.TRACETAB);
}
}
}
}
package kieker.tools.eclipse.analysis.helper;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
/**
* @author Florian Echternkamp
*/
public class ComponentFilter extends ViewerFilter {
private String searchString;
private int index;
public ComponentFilter() {
index = 0;
}
public ComponentFilter(int i) {
index = i;
}
public void setSearchText(String s) {
// ensure that the value can be used for matching
this.searchString = ".*" + s + ".*";
}
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (searchString == null || searchString.length() == 0) {
return true;
}
TreeViewer treeViewer = (TreeViewer) viewer;
ColumnLabelProvider labelProvider = (ColumnLabelProvider) treeViewer.getLabelProvider(index);
String labelText = labelProvider.getText(element);
return labelText.matches(searchString);
}
}
package kieker.tools.eclipse.analysis.helper; package kieker.tools.eclipse.analysis.listener;
import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyEvent;
...@@ -6,6 +6,8 @@ import org.eclipse.swt.events.ModifyListener; ...@@ -6,6 +6,8 @@ import org.eclipse.swt.events.ModifyListener;