Commit c658fd61 authored by Florian's avatar Florian

code refactoring

parent 2a1747c8
......@@ -293,7 +293,7 @@
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
class="kieker.tools.eclipse.analysis.helper.PreferenceInitializer">
class="kieker.tools.eclipse.analysis.PreferenceInitializer">
</initializer>
</extension>
</plugin>
package kieker.tools.eclipse.analysis.helper;
package kieker.tools.eclipse.analysis;
import java.util.concurrent.TimeUnit;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
import kieker.tools.eclipse.analysis.Activator;
import kieker.tools.eclipse.analysis.model.Properties;
public class PreferenceInitializer extends AbstractPreferenceInitializer {
......
package kieker.tools.eclipse.analysis.helper;
import java.util.List;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TreeColumn;
public class ColumnViewerHelper {
public static void packCols(List<ColumnViewer> viewerList, int i) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (i < 4) {
TreeColumn[] treeColumns = ((TreeViewer) viewerList.get(i)).getTree().getColumns();
for (TreeColumn treeColumn : treeColumns)
treeColumn.pack();
}
if (i == 4) {
for (TableColumn col : ((TableViewer) viewerList.get(i)).getTable().getColumns()) {
col.pack();
}
}
}
});
}
public static void packCols(ColumnViewer v) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if(v instanceof TreeViewer){
TreeColumn[] treeColumns = ((TreeViewer) v).getTree().getColumns();
for (TreeColumn treeColumn : treeColumns)
treeColumn.pack();
} else if(v instanceof TableViewer){
for (TableColumn col : ((TableViewer) v).getTable().getColumns()) {
col.pack();
}
}
}
});
}
}
package kieker.tools.eclipse.analysis.helper;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import kieker.tools.eclipse.analysis.filter.TreeFilter;
import kieker.tools.eclipse.analysis.listener.FilterModifyListener;
public class FilterHelper {
public static Text createFilterText(Composite composite, String message) {
Text searchText = new Text(composite, SWT.BORDER | SWT.SEARCH);
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalSpan = 1;
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
searchText.setLayoutData(gridData);
searchText.setMessage(message);
return searchText;
}
public static TreeFilter createFilter(TreeViewer viewer, int col, Text text) {
TreeFilter filter = new TreeFilter(col);
text.addModifyListener(new FilterModifyListener(viewer, filter, text));
return filter;
}
}
package kieker.tools.eclipse.analysis.helper;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Properties;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
import org.eclipse.jface.resource.ResourceManager;
import org.eclipse.swt.widgets.Composite;
public class ImageHelper {
// Create Image Registry from properties
public static ImageRegistry setupImageRegistry(Composite parent) {
ResourceManager resourceManager = JFaceResources.getResources();
LocalResourceManager localResourceManager = new LocalResourceManager(resourceManager, parent);
ImageRegistry ir = new ImageRegistry(localResourceManager);
Properties props = new Properties();
InputStream inStream = ImageRegistry.class.getClassLoader().getResourceAsStream("resources/images.properties"); //$NON-NLS-1$
try {
props.load(inStream);
inStream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
Enumeration<?> e = props.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
URL icon = ImageRegistry.class.getResource(props.getProperty(key));
ir.put(key, ImageDescriptor.createFromURL(icon));
}
return ir;
}
}
package kieker.tools.eclipse.analysis.helper;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.TableColumn;
public class TableHelper {
public static TableViewerColumn createTableViewerColumn(TableViewer viewer, String title, int bound) {
final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
final TableColumn column = viewerColumn.getColumn();
column.setText(title);
column.setWidth(bound);
column.setResizable(true);
column.setMoveable(false);
return viewerColumn;
}
}
package kieker.tools.eclipse.analysis.view;
package kieker.tools.eclipse.analysis.helper;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
import org.eclipse.jface.resource.ResourceManager;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.TreeViewerColumn;
import org.eclipse.swt.SWT;
......@@ -31,77 +19,28 @@ import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.IWorkbenchPartSite;
import kieker.tools.eclipse.analysis.comparator.AnalysisViewerComparator;
import kieker.tools.eclipse.analysis.helper.TreeFilter;
import kieker.tools.eclipse.analysis.listener.FilterModifyListener;
import kieker.tools.eclipse.analysis.filter.TreeFilter;
import kieker.tools.eclipse.analysis.model.ColumnDef;
import kieker.tools.eclipse.analysis.resources.view.Messages;
public abstract class AbstractJFaceView extends ViewPart {
public class TreeHelper {
protected ImageRegistry ir;
List<List<Text>> filterTextLists = new ArrayList<List<Text>>();
public List<List<Text>> getFilterTextLists() {
return filterTextLists;
}
@Override
public void createPartControl(Composite parent) {
setupImageRegistry(parent);
}
@Override
public void setFocus() {
}
TableViewerColumn createTableViewerColumn(TableViewer viewer, String title, int bound) {
final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
final TableColumn column = viewerColumn.getColumn();
column.setText(title);
column.setWidth(bound);
column.setResizable(true);
column.setMoveable(false);
return viewerColumn;
}
Text createFilterText(Composite composite, String message) {
Text searchText = new Text(composite, SWT.BORDER | SWT.SEARCH);
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalSpan = 1;
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
searchText.setLayoutData(gridData);
searchText.setMessage(message);
return searchText;
}
TreeFilter createFilter(TreeViewer viewer, int col, Text text) {
TreeFilter filter = new TreeFilter(col);
text.addModifyListener(new FilterModifyListener(viewer, filter, text));
return filter;
}
TreeViewer createTree(Composite parent, TabItem tab, int operationCol, int componentCol, int containerCol) {
public static TreeViewer createTree(IWorkbenchPartSite site, Composite parent, TabItem tab, int operationCol, int componentCol, int containerCol, List<List<Text>> filterTextLists ) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(3, false);
composite.setLayout(layout);
Text methodSearchText = createFilterText(composite, Messages.AnalysisTreeView_FilterOperations);
Text componentSearchText = createFilterText(composite, Messages.AnalysisTreeView_FilterComponents);
Text containerSearchText = createFilterText(composite, Messages.AnalysisTreeView_FilterContainer);
Text methodSearchText = FilterHelper.createFilterText(composite, Messages.AnalysisTreeView_FilterOperations);
Text componentSearchText = FilterHelper.createFilterText(composite, Messages.AnalysisTreeView_FilterComponents);
Text containerSearchText = FilterHelper.createFilterText(composite, Messages.AnalysisTreeView_FilterContainer);
List<Text> filterTexts = new ArrayList<Text>();
filterTexts.add(methodSearchText);
......@@ -144,12 +83,12 @@ public abstract class AbstractJFaceView extends ViewPart {
};
tree.addListener(SWT.Collapse, listener);
tree.addListener(SWT.Expand, listener);
addTreeViewerContextMenu(viewer);
addTreeViewerContextMenu(site, viewer);
List<TreeFilter> filterList = new ArrayList<TreeFilter>();
filterList.add(createFilter(viewer, operationCol, methodSearchText));
filterList.add(createFilter(viewer, componentCol, componentSearchText));
filterList.add(createFilter(viewer, containerCol, containerSearchText));
filterList.add(FilterHelper.createFilter(viewer, operationCol, methodSearchText));
filterList.add(FilterHelper.createFilter(viewer, componentCol, componentSearchText));
filterList.add(FilterHelper.createFilter(viewer, containerCol, containerSearchText));
for (TreeFilter f : filterList) {
viewer.addFilter(f);
......@@ -157,18 +96,18 @@ public abstract class AbstractJFaceView extends ViewPart {
return viewer;
}
void addTreeViewerContextMenu(TreeViewer viewer) {
static void addTreeViewerContextMenu(IWorkbenchPartSite site, TreeViewer viewer) {
MenuManager manager = new MenuManager();
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
Menu menu = manager.createContextMenu(viewer.getTree());
viewer.getTree().setMenu(menu);
getSite().registerContextMenu(manager, viewer);
getSite().setSelectionProvider(viewer);
site.registerContextMenu(manager, viewer);
site.setSelectionProvider(viewer);
}
void createTreeViewerColumns(TreeViewer viewer, AnalysisViewerComparator comparator, ColumnDef[] cols) {
public static void createTreeViewerColumns(TreeViewer viewer, AnalysisViewerComparator comparator, ColumnDef[] cols) {
int i = 0;
for (ColumnDef col : cols) {
createTreeViewerColumn(viewer, comparator, col.getStyle(), col.getName(), col.getWidth(),
......@@ -176,7 +115,7 @@ public abstract class AbstractJFaceView extends ViewPart {
}
}
void createTreeViewerColumn(TreeViewer viewer, AnalysisViewerComparator comparator, int style, String title, int width,
public static void createTreeViewerColumn(TreeViewer viewer, AnalysisViewerComparator comparator, int style, String title, int width,
ColumnLabelProvider provider, int index) {
TreeViewerColumn viewCol = new TreeViewerColumn(viewer, style);
TreeColumn col = viewCol.getColumn();
......@@ -186,8 +125,8 @@ public abstract class AbstractJFaceView extends ViewPart {
col.addSelectionListener(getSelectionAdapter(viewer, comparator, col, index));
viewCol.setLabelProvider(provider);
}
SelectionAdapter getSelectionAdapter(final TreeViewer viewer, final AnalysisViewerComparator comparator,
static SelectionAdapter getSelectionAdapter(final TreeViewer viewer, final AnalysisViewerComparator comparator,
final TreeColumn column, final int index) {
SelectionAdapter selectionAdapter = new SelectionAdapter() {
@Override
......@@ -201,29 +140,5 @@ public abstract class AbstractJFaceView extends ViewPart {
};
return selectionAdapter;
}
// Create Image Registry from properties
void setupImageRegistry(Composite parent) {
ResourceManager resourceManager = JFaceResources.getResources();
LocalResourceManager localResourceManager = new LocalResourceManager(resourceManager, parent);
ir = new ImageRegistry(localResourceManager);
Properties props = new Properties();
InputStream inStream = this.getClass().getClassLoader().getResourceAsStream("resources/images.properties"); //$NON-NLS-1$
try {
props.load(inStream);
inStream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
Enumeration<?> e = props.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
URL icon = getClass().getResource(props.getProperty(key));
ir.put(key, ImageDescriptor.createFromURL(icon));
}
}
}
......@@ -6,7 +6,7 @@ import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.TreeColumn;
import kieker.tools.eclipse.analysis.helper.TreeFilter;
import kieker.tools.eclipse.analysis.filter.TreeFilter;
public class FilterModifyListener implements ModifyListener {
......
package kieker.tools.eclipse.analysis.listener;
import java.util.List;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.TypedListener;
import kieker.tools.eclipse.analysis.helper.ColumnViewerHelper;
import kieker.tools.eclipse.analysis.model.Properties;
import kieker.tools.eclipse.analysis.view.AnalysisTreeView;
public class PreferencePropertyChangeListener implements IPropertyChangeListener {
AnalysisTreeView view;
public PreferencePropertyChangeListener(AnalysisTreeView view) {
this.view = view;
}
@Override
public void propertyChange(PropertyChangeEvent event) {
String propertyName = event.getProperty();
if (propertyName.equals(Properties.Names.FILTERCASESENSITIVE.toString())
|| propertyName.equals(Properties.Names.FILTERREGEX.toString())) {
List<List<Text>> lists = view.getFilterTextLists();
for (List<Text> list : lists) {
for (Text t : list) {
Listener[] listener = t.getListeners(SWT.Modify);
if (listener.length > 0) {
TypedListener l = (TypedListener) listener[0];
if (l.getEventListener() instanceof FilterModifyListener) {
((FilterModifyListener) l.getEventListener()).setText();
}
}
}
}
}
List<ColumnViewer> viewerList = view.getViewerList();
for (ColumnViewer v : viewerList ) {
v.refresh();
ColumnViewerHelper.packCols(v);
}
}
}
package kieker.tools.eclipse.analysis.listener;
import java.util.List;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.TabFolder;
import kieker.tools.eclipse.analysis.provider.SelectionProviderIntermediate;
import kieker.tools.eclipse.analysis.view.AnalysisTreeView;
public class TabFolderSelectionListener implements SelectionListener {
AnalysisTreeView view;
TabFolder tabFolder;
List<ColumnViewer> viewerList;
SelectionProviderIntermediate selIntermediate;
public TabFolderSelectionListener(AnalysisTreeView view, TabFolder tabFolder, List<ColumnViewer> viewerList, SelectionProviderIntermediate selIntermediate) {
this.view = view;
this.tabFolder = tabFolder;
this.viewerList = viewerList;
this.selIntermediate = selIntermediate;
}
@Override
public void widgetSelected(SelectionEvent e) {
int tabIdx = tabFolder.getSelectionIndex();
ColumnViewer viewer = viewerList.get(tabIdx);
selIntermediate.setSelectionProviderDelegate(viewer);
if (viewer.getInput() == null) {
view.setInputs(tabIdx);
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
}
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