refactor to integrate design browser

This commit is contained in:
Eyck Jentzsch 2020-10-04 16:20:16 +02:00
parent 563b6e2b01
commit cc9be70708
15 changed files with 655 additions and 83 deletions

View File

@ -4,4 +4,5 @@ org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -98,4 +98,5 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -4,4 +4,5 @@ org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -5,4 +5,5 @@ org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -9,4 +9,5 @@ org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -1,3 +1,2 @@
eclipse.preferences.version=1
pluginProject.extensions=false
resolve.requirebundle=false

View File

@ -3,34 +3,11 @@
<children xsi:type="basic:TrimmedWindow" xmi:id="_95PfsXNmEeWBq8z1Dv39LA" label="SC Viewer" bindingContexts="_95PfunNmEeWBq8z1Dv39LA" width="1280" height="700">
<children xsi:type="advanced:PerspectiveStack" xmi:id="_95QGxnNmEeWBq8z1Dv39LA">
<children xsi:type="advanced:Perspective" xmi:id="_95QGx3NmEeWBq8z1Dv39LA">
<children xsi:type="basic:PartSashContainer" xmi:id="_95QGyHNmEeWBq8z1Dv39LA" horizontal="true">
<children xsi:type="basic:Part" xmi:id="_95QGynNmEeWBq8z1Dv39LA" elementId="com.minres.scviewer.e4.application.parts.DesignBrowser" containerData="2000" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.parts.DesignBrowser" label="Design Browser" bindingContexts="_iQ3kQGVmEeqSQM-A6dw9ig">
<handlers xmi:id="_JIWOYIq-EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.handler.addWaveformCommand" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.handlers.AddWaveformHandler" command="_2PehEHr9EeWVM_sKoXvptg"/>
<menus xsi:type="menu:PopupMenu" xmi:id="_HvUl8Iq-EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.parts.DesignBrowser.popupmenu">
<children xsi:type="menu:HandledMenuItem" xmi:id="_HvUl8Yq-EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.handledmenuitem.append" label="Append after" iconURI="platform:/plugin/com.minres.scviewer.e4.application/icons/append_wave.png" command="_2PehEHr9EeWVM_sKoXvptg">
<parameters xmi:id="_HvUl8oq-EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.parameter.21" name="com.minres.scviewer.e4.application.command.addwaveform.where" value="after"/>
<parameters xmi:id="_HvUl84q-EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.parameter.25" name="com.minres.scviewer.e4.application.command.addwaveform.all" value="false"/>
</children>
<children xsi:type="menu:HandledMenuItem" xmi:id="_HvUl9Iq-EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.handledmenuitem.insertbefore" label="Insert before" iconURI="platform:/plugin/com.minres.scviewer.e4.application/icons/insert_wave.png" command="_2PehEHr9EeWVM_sKoXvptg">
<parameters xmi:id="_HvUl9Yq-EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.parameter.22" name="com.minres.scviewer.e4.application.command.addwaveform.where" value="before"/>
<parameters xmi:id="_HvUl9oq-EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.parameter.26" name="com.minres.scviewer.e4.application.command.addwaveform.all" value="false"/>
</children>
<children xsi:type="menu:HandledMenuItem" xmi:id="_HvUl94q-EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.handledmenuitem.appendall" label="Append all" iconURI="platform:/plugin/com.minres.scviewer.e4.application/icons/append_all_waves.png" command="_2PehEHr9EeWVM_sKoXvptg">
<parameters xmi:id="_HvUl-Iq-EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.parameter.23" name="com.minres.scviewer.e4.application.command.addwaveform.where" value="after"/>
<parameters xmi:id="_HvUl-Yq-EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.parameter.27" name="com.minres.scviewer.e4.application.command.addwaveform.all" value="true"/>
</children>
<children xsi:type="menu:HandledMenuItem" xmi:id="_HvUl-oq-EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.handledmenuitem.insertall" label="Insert All" iconURI="platform:/plugin/com.minres.scviewer.e4.application/icons/insert_all_waves.png" command="_2PehEHr9EeWVM_sKoXvptg">
<parameters xmi:id="_HvUl-4q-EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.parameter.24" name="com.minres.scviewer.e4.application.command.addwaveform.where" value="before"/>
<parameters xmi:id="_HvUl_Iq-EeWid7xO48ZBXw" elementId="com.minres.scviewer.e4.application.parameter.28" name="com.minres.scviewer.e4.application.command.addwaveform.all" value="true"/>
</children>
</menus>
</children>
<children xsi:type="basic:PartSashContainer" xmi:id="_uT9BIHgtEeWwZ-9vrAR2UQ" elementId="" containerData="8000">
<children xsi:type="basic:PartStack" xmi:id="_95QGyXNmEeWBq8z1Dv39LA" elementId="org.eclipse.editorss" containerData="7500">
<tags>NoAutoCollapse</tags>
</children>
<children xsi:type="basic:Part" xmi:id="_vtfm8HgtEeWwZ-9vrAR2UQ" elementId="com.minres.scviewer.e4.application.parts.WaveformDetails" containerData="2500" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.parts.TransactionDetails" label="Waveform Details"/>
<children xsi:type="basic:PartSashContainer" xmi:id="_uT9BIHgtEeWwZ-9vrAR2UQ" elementId="" containerData="8000">
<children xsi:type="basic:PartStack" xmi:id="_95QGyXNmEeWBq8z1Dv39LA" elementId="org.eclipse.editorss" containerData="7500">
<tags>NoAutoCollapse</tags>
</children>
<children xsi:type="basic:Part" xmi:id="_vtfm8HgtEeWwZ-9vrAR2UQ" elementId="com.minres.scviewer.e4.application.parts.WaveformDetails" containerData="2500" contributionURI="bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.parts.TransactionDetails" label="Waveform Details"/>
</children>
</children>
</children>

View File

@ -28,7 +28,8 @@ Require-Bundle: javax.inject;bundle-version="1.0.0",
com.opcoach.e4.preferences,
org.eclipse.e4.core.di.extensions,
org.eclipse.e4.ui.css.swt.theme;bundle-version="0.10.0",
org.eclipse.core.resources;bundle-version="3.13.0"
org.eclipse.core.resources;bundle-version="3.13.0",
javax.annotation;bundle-version="1.2.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: com.minres.scviewer.database,
javax.inject;version="1.0.0"

View File

@ -123,7 +123,7 @@ public class RelationTypeToolControl extends PartListener implements ISelectionC
return;
}
}
comboViewer.getCombo().setEnabled(false);
if(comboViewer!=null) comboViewer.getCombo().setEnabled(false);
}
/* (non-Javadoc)

View File

@ -11,6 +11,7 @@
package com.minres.scviewer.e4.application.handlers;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.e4.core.contexts.IEclipseContext;
@ -39,12 +40,12 @@ public class OpenHandler {
part.setLabel(files.get(0).getName());
MPartStack partStack = (MPartStack)modelService.find("org.eclipse.editorss", app); //$NON-NLS-1$
partStack.getChildren().add(part);
partService.showPart(part, PartState.ACTIVATE);
partService.showPart(part, PartState.CREATE);
final IEclipseContext ctx=part.getContext();
files.stream()
.map(x -> x.getAbsolutePath())
.reduce((s1, s2) -> s1 + "," + s2)
.ifPresent(s -> ctx.modify("input", s)); //$NON-NLS-1$
List<String> inputs=new ArrayList<>();
for(File f: files)
inputs.add(f.getAbsolutePath());
ctx.modify("input", inputs);
ctx.modify("config", ""); //$NON-NLS-1$
}

View File

@ -0,0 +1,575 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.e4.application.internal.ui;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.di.Focus;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.services.EMenuService;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.ITreePathContentProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;
import com.minres.scviewer.database.HierNode;
import com.minres.scviewer.database.IHierNode;
import com.minres.scviewer.database.ITx;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.e4.application.Messages;
import com.minres.scviewer.e4.application.parts.LoadingWaveformDb;
import com.minres.scviewer.e4.application.provider.TxDbContentProvider;
import com.minres.scviewer.e4.application.provider.TxDbLabelProvider;
/**
* The Class DesignBrowser. It contains the design tree, a list of Streams & signals and a few buttons to
* add them them to the waveform view
*/
public abstract class AbstractDesignBrowser {
public TreeViewer getDbTreeViewer() {
return dbTreeViewer;
}
public TableViewer getStreamTableViewer() {
return streamTableViewer;
}
/** The Constant POPUP_ID. */
private static final String POPUP_ID="com.minres.scviewer.e4.application.parts.DesignBrowser.popupmenu"; //$NON-NLS-1$
/** The event broker. */
@Inject IEventBroker eventBroker;
/** The selection service. */
@Inject ESelectionService selectionService;
/** The menu service. */
@Inject EMenuService menuService;
/** The eclipse ctx. */
@Inject IEclipseContext eclipseCtx;
/** The sash form. */
private SashForm sashForm;
/** The top. */
Composite top;
/** The bottom. */
private Composite bottom;
/** The tree viewer. */
private TreeViewer dbTreeViewer;
/** The name filter of the design browser tree. */
private Text treeNameFilter;
/** The attribute filter. */
StreamTTreeFilter treeAttributeFilter;
/** The name filter. */
private Text tableNameFilter;
/** The attribute filter. */
StreamTableFilter tableAttributeFilter;
/** The tx table viewer. */
protected TableViewer streamTableViewer;
/** The append all item. */
protected ToolItem appendItem, insertItem;
/** The other selection count. */
int thisSelectionCount=0, otherSelectionCount=0;
IWaveformDb waveformDb=null;
/** The tree viewer pcl. */
private PropertyChangeListener treeViewerPCL = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if("CHILDS".equals(evt.getPropertyName())){ //$NON-NLS-1$
dbTreeViewer.getTree().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
dbTreeViewer.refresh();
}
});
}
}
};
/** The sash paint listener. */
protected PaintListener sashPaintListener=new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
int size=Math.min(e.width, e.height)-1;
e.gc.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY));
e.gc.setFillRule(SWT.FILL_EVEN_ODD);
if(e.width>e.height)
e.gc.drawArc(e.x+(e.width-size)/2, e.y, size, size, 0, 360);
else
e.gc.drawArc(e.x, e.y+(e.height-size)/2, size, size, 0, 360);
}
};
/**
* Creates the composite.
*
* @param parent the parent
*/
@PostConstruct
public void createComposite(Composite parent) {
sashForm = new SashForm(parent, SWT.BORDER | SWT.SMOOTH | SWT.VERTICAL);
top = new Composite(sashForm, SWT.NONE);
createTreeViewerComposite(top);
bottom = new Composite(sashForm, SWT.NONE);
createTableComposite(bottom);
sashForm.setWeights(new int[] {100, 100});
sashForm.SASH_WIDTH=5;
top.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
sashForm.getChildren()[2].addPaintListener(sashPaintListener);
top.removeControlListener(this);
}
});
}
/**
* Creates the tree viewer composite.
*
* @param parent the parent
*/
public void createTreeViewerComposite(Composite parent) {
parent.setLayout(new GridLayout(1, false));
treeNameFilter = new Text(parent, SWT.BORDER);
treeNameFilter.setMessage(Messages.DesignBrowser_3);
treeNameFilter.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
treeAttributeFilter.setSearchText(((Text) e.widget).getText());
dbTreeViewer.refresh();
}
});
treeNameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
treeAttributeFilter = new StreamTTreeFilter();
dbTreeViewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
dbTreeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
dbTreeViewer.setContentProvider(new TxDbContentProvider());
dbTreeViewer.setLabelProvider(new TxDbLabelProvider());
dbTreeViewer.addFilter(treeAttributeFilter);
dbTreeViewer.setUseHashlookup(true);
dbTreeViewer.setAutoExpandLevel(2);
dbTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection=event.getSelection();
if( selection instanceof IStructuredSelection) {
Object object= ((IStructuredSelection)selection).getFirstElement();
if(object instanceof IHierNode && ((IHierNode)object).getChildNodes().size()!=0){
streamTableViewer.setInput(object);
updateButtons();
}
else { //if selection is changed but empty
streamTableViewer.setInput(null);
updateButtons();
}
}
}
});
}
/**
* Creates the table composite.
*
* @param parent the parent
*/
public void createTableComposite(Composite parent) {
parent.setLayout(new GridLayout(1, false));
tableNameFilter = new Text(parent, SWT.BORDER);
tableNameFilter.setMessage(Messages.DesignBrowser_2);
tableNameFilter.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
tableAttributeFilter.setSearchText(((Text) e.widget).getText());
updateButtons();
streamTableViewer.refresh();
}
});
tableNameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
tableAttributeFilter = new StreamTableFilter();
streamTableViewer = new TableViewer(parent);
streamTableViewer.setContentProvider(new TxDbContentProvider(true));
streamTableViewer.setLabelProvider(new TxDbLabelProvider());
streamTableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
streamTableViewer.addFilter(tableAttributeFilter);
streamTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
selectionService.setSelection(event.getSelection());
updateButtons();
}
});
menuService.registerContextMenu(streamTableViewer.getControl(), POPUP_ID);
ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.RIGHT);
toolBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
toolBar.setBounds(0, 0, 87, 20);
appendItem = new ToolItem(toolBar, SWT.NONE);
appendItem.setToolTipText(Messages.DesignBrowser_4);
appendItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/append_wave.png")); //$NON-NLS-1$ //$NON-NLS-2$
appendItem.setEnabled(false);
insertItem = new ToolItem(toolBar, SWT.NONE);
insertItem.setToolTipText(Messages.DesignBrowser_8);
insertItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/insert_wave.png")); //$NON-NLS-1$ //$NON-NLS-2$
insertItem.setEnabled(false);
}
public IWaveformDb getWaveformDb() {
return waveformDb;
}
@SuppressWarnings("unchecked")
public void setWaveformDb(IWaveformDb waveformDb) {
this.waveformDb = waveformDb;
Object input = dbTreeViewer.getInput();
if(input!=null && input instanceof List<?>){
IWaveformDb db = ((List<IWaveformDb>)input).get(0);
if(db==waveformDb) return; // do nothing if old and new database is the same
((List<IWaveformDb>)input).get(0).removePropertyChangeListener(treeViewerPCL);
}
dbTreeViewer.setInput(Arrays.asList(waveformDb.isLoaded()?new IWaveformDb[]{waveformDb}:new IWaveformDb[]{new LoadingWaveformDb()}));
// Set up the tree viewer
waveformDb.addPropertyChangeListener(treeViewerPCL);
}
/**
* Sets the focus.
*/
@Focus
public void setFocus() {
if(streamTableViewer!=null) {
streamTableViewer.getTable().setFocus();
IStructuredSelection selection = (IStructuredSelection)streamTableViewer.getSelection();
if(selection.size()==0){
appendItem.setEnabled(false);
}
selectionService.setSelection(selection);
thisSelectionCount=selection.toList().size();
}
updateButtons();
}
/**
* reset tree viewer and tableviewer after every closed tab
*/
protected void resetTreeViewer() {
//reset tree- and tableviewer
dbTreeViewer.setInput(null);
streamTableViewer.setInput(null);
streamTableViewer.setSelection(null);
}
public void selectAllWaveforms() {
int itemCount = streamTableViewer.getTable().getItemCount();
ArrayList<Object> list = new ArrayList<>();
for(int i=0; i<itemCount; i++) {
list.add(streamTableViewer.getElementAt(i));
}
StructuredSelection sel = new StructuredSelection(list);
streamTableViewer.setSelection(sel);
}
/**
* Sets the selection.
*
* @param selection the selection
* @param partService the part service
*/
@Inject
public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection, EPartService partService){
MPart part = partService.getActivePart();
if(part!=null && part.getObject() != this && selection!=null){
if( selection instanceof IStructuredSelection) {
Object object= ((IStructuredSelection)selection).getFirstElement();
if(object instanceof IHierNode&& ((IHierNode)object).getChildNodes().size()!=0)
streamTableViewer.setInput(object);
otherSelectionCount = (object instanceof IWaveform || object instanceof ITx)?1:0;
}
}
updateButtons();
}
/**
* Initialize the listeners for the buttons.
*/
protected abstract void initializeButtonListeners();
/**
* Update buttons.
*/
protected abstract void updateButtons();
/**
* The Class StreamTableFilter.
*/
public class StreamTableFilter extends ViewerFilter {
/** The search string. */
private String searchString;
private Pattern pattern;
/**
* Sets the search text.
*
* @param s the new search text
*/
public void setSearchText(String s) {
try {
pattern = Pattern.compile(".*" + s + ".*"); //$NON-NLS-1$ //$NON-NLS-2$
this.searchString = ".*" + s + ".*"; //$NON-NLS-1$ //$NON-NLS-2$
} catch (PatternSyntaxException e) {}
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (searchString == null || searchString.length() == 0) {
return true;
}
if(element instanceof IWaveform) {
if (pattern.matcher(((IWaveform) element).getName()).matches())
return true;
}
return false;
}
}
public class StreamTTreeFilter extends ViewerFilter {
/** The search string. */
private String searchString;
private Pattern pattern;
/**
* Sets the search text.
*
* @param s the new search text
*/
public void setSearchText(String s) {
try {
pattern = Pattern.compile(".*" + s + ".*");
this.searchString = ".*" + s + ".*"; //$NON-NLS-1$ //$NON-NLS-2$
} catch (PatternSyntaxException e) {}
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
return selectTreePath(viewer, new TreePath(new Object[] { parentElement }), element);
}
private boolean selectTreePath(Viewer viewer, TreePath parentPath, Object element) {
// Cut off children of elements that are shown repeatedly.
for (int i = 0; i < parentPath.getSegmentCount() - 1; i++) {
if (element.equals(parentPath.getSegment(i))) {
return false;
}
}
if (!(viewer instanceof TreeViewer)) {
return true;
}
if (searchString == null || searchString.length() == 0) {
return true;
}
TreeViewer treeViewer = (TreeViewer) viewer;
Boolean matchingResult = isMatchingOrNull(element);
if (matchingResult != null) {
return matchingResult;
}
return hasUnfilteredChild(treeViewer, parentPath, element);
}
Boolean isMatchingOrNull(Object element) {
if(element instanceof IWaveform) {
if (pattern.matcher(((IWaveform) element).getName()).matches())
return Boolean.TRUE;
} else if(element instanceof IWaveformDb) {
return Boolean.TRUE;
} else if(element instanceof HierNode) {
HierNode n = (HierNode) element;
try {
if (pattern.matcher(n.getFullName()).matches())
return Boolean.TRUE;
} catch (PatternSyntaxException e) {
return Boolean.TRUE;
}
} else {
return Boolean.FALSE;
}
/* maybe children are matching */
return null;
}
private boolean hasUnfilteredChild(TreeViewer viewer, TreePath parentPath, Object element) {
TreePath elementPath = parentPath.createChildPath(element);
IContentProvider contentProvider = viewer.getContentProvider();
Object[] children = contentProvider instanceof ITreePathContentProvider
? ((ITreePathContentProvider) contentProvider).getChildren(elementPath)
: ((ITreeContentProvider) contentProvider).getChildren(element);
/* avoid NPE + guard close */
if (children == null || children.length == 0) {
return false;
}
for (int i = 0; i < children.length; i++) {
if (selectTreePath(viewer, elementPath, children[i])) {
return true;
}
}
return false;
}
}
/**
* Gets the filtered children.
*
* @param viewer the viewer
* @return the filtered children
*/
protected Object[] getFilteredChildren(TableViewer viewer){
Object parent = viewer.getInput();
if(parent==null) return new Object[0];
Object[] result = null;
if (parent != null) {
IStructuredContentProvider cp = (IStructuredContentProvider) viewer.getContentProvider();
if (cp != null) {
result = cp.getElements(parent);
if(result==null) return new Object[0];
for (int i = 0, n = result.length; i < n; ++i) {
if(result[i]==null) return new Object[0];
}
}
}
ViewerFilter[] filters = viewer.getFilters();
if (filters != null) {
for (ViewerFilter f:filters) {
Object[] filteredResult = f.filter(viewer, parent, result);
result = filteredResult;
}
}
return result;
}
/**
* Gets the filtered children.
*
* @return the filtered children
*/
public Object[] getFilteredChildren() {
return getFilteredChildren(streamTableViewer);
}
/**
* The Class DBState.
*/
class DBState {
/**
* Instantiates a new DB state.
*/
public DBState() {
this.expandedElements=dbTreeViewer.getExpandedElements();
this.treeSelection=dbTreeViewer.getSelection();
this.tableSelection=streamTableViewer.getSelection();
}
/**
* Apply.
*/
public void apply() {
dbTreeViewer.setExpandedElements(expandedElements);
dbTreeViewer.setSelection(treeSelection, true);
streamTableViewer.setSelection(tableSelection, true);
}
/** The expanded elements. */
private Object[] expandedElements;
/** The tree selection. */
private ISelection treeSelection;
/** The table selection. */
private ISelection tableSelection;
}
};

View File

@ -262,7 +262,8 @@ public class TransactionDetails {
*/
@Focus
public void setFocus() {
treeViewer.getTree().setFocus();
if(treeViewer!=null)
treeViewer.getTree().setFocus();
}
/**

View File

@ -103,10 +103,13 @@ import com.minres.scviewer.database.ui.swt.WaveformViewFactory;
import com.minres.scviewer.database.ui.WaveformColors;
import com.minres.scviewer.e4.application.Messages;
import com.minres.scviewer.e4.application.internal.status.WaveStatusBarControl;
import com.minres.scviewer.e4.application.internal.ui.AbstractDesignBrowser;
import com.minres.scviewer.e4.application.internal.util.FileMonitor;
import com.minres.scviewer.e4.application.internal.util.IFileChangeListener;
import com.minres.scviewer.e4.application.internal.util.IModificationChecker;
import com.minres.scviewer.e4.application.preferences.PreferenceConstants;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.layout.FillLayout;
/**
* The Class WaveformViewerPart.
@ -166,6 +169,20 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
/** The factory. */
WaveformViewFactory factory = new WaveformViewFactory();
AbstractDesignBrowser browser = new AbstractDesignBrowser() {
@Override
protected void updateButtons() {
// TODO Auto-generated method stub
}
@Override
protected void initializeButtonListeners() {
// TODO Auto-generated method stub
}
};
/** The waveform pane. */
private IWaveformView waveformPane;
@ -199,7 +216,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
private boolean checkForUpdates;
/** The my part. */
private MPart myPart;
@Inject private MPart myPart;
/** The my parent. */
private Composite myParent;
@ -207,6 +224,8 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
/** The files to load. */
ArrayList<File> filesToLoad = new ArrayList<>();
String partConfig = "";
/** The persisted state. */
Map<String, String> persistedState;
@ -225,6 +244,10 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
/** The file checker. */
IModificationChecker fileChecker;
@Inject IWaveformDbFactory dbFactory;
@Inject Composite parent;
private Boolean showHover;
/**
@ -235,7 +258,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
* @param dbFactory the db factory
*/
@PostConstruct
public void createComposite(MPart part, Composite parent, IWaveformDbFactory dbFactory, @Preference(nodePath = PreferenceConstants.PREFERENCES_SCOPE) IEclipsePreferences prefs, @Preference(value = PreferenceConstants.SHOW_HOVER) Boolean hover) {
public void createComposite(MPart part, EMenuService menuService, @Preference(nodePath = PreferenceConstants.PREFERENCES_SCOPE) IEclipsePreferences prefs, @Preference(value = PreferenceConstants.SHOW_HOVER) Boolean hover) {
disposeListenerNumber += 1;
myPart = part;
@ -256,7 +279,20 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
}
}
});
waveformPane = factory.createPanel(parent);
parent.setLayout(new FillLayout(SWT.HORIZONTAL));
SashForm sashFormTop = new SashForm(parent, SWT.NONE);
Composite left = new Composite(sashFormTop, SWT.NONE);
left.setLayout(new FillLayout(SWT.HORIZONTAL));
browser.createComposite(left);
browser.setWaveformDb(database);
Composite right = new Composite(sashFormTop, SWT.NONE);
waveformPane = factory.createPanel(right);
sashFormTop.setWeights(new int[] {25, 75});
waveformPane.setMaxTime(0);
setupColors();
//set selection to empty selection when opening a new waveformPane
@ -614,48 +650,21 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
*/
@Inject
@Optional
public void setPartInput(@Named("input") Object partInput, @Named("config") Object partConfig) {
if (partInput instanceof String) {
String name = (String)partInput;
filesToLoad = new ArrayList<File>();
boolean explicit = name.contains(",");
for(String tok: name.split(",")) {
File file = new File(tok);
if(file.isFile() && "CURRENT".equals(file.getName())){
file=file.getParentFile();
}
if (file.exists()) {
filesToLoad.add(file);
}
if(!explicit)
try {
String ext = getFileExtension(file.getName());
if (Messages.WaveformViewer_19.equals(ext.toLowerCase())) {
if (askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_20)))) {
filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_20)));
} else if (askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_21)))) {
filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_21)));
} else if (askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_22)))) {
filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_22)));
}
} else if (Messages.WaveformViewer_20.equals(ext.toLowerCase()) ||
Messages.WaveformViewer_21.equals(ext.toLowerCase()) ||
Messages.WaveformViewer_22.equals(ext.toLowerCase())
) {
if (askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_19)))) {
filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), Messages.WaveformViewer_19)));
}
}
} catch (IOException e) { // silently ignore any error
}
}
if (filesToLoad.size() > 0)
loadDatabase(persistedState);
if(partConfig instanceof String && ((String)partConfig).length()>0) {
loadState((String) partConfig);
}
public void setPartInput(@Named("input") List<String> partInput, @Named("config") String partConfig) {
for(String s:partInput) {
File file = new File(s);
if(file.isFile() && "CURRENT".equals(file.getName()))
file=file.getParentFile();
if (file.exists())
filesToLoad.add(file);
}
if(partConfig!=null) {
this.partConfig=partConfig;
}
if (filesToLoad.size() > 0)
loadDatabase(persistedState);
if(partConfig.length()>0)
loadState(partConfig);
}
/**
@ -663,7 +672,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
*/
@Focus
public void setFocus() {
waveformPane.getWaveformControl().setFocus();
if(waveformPane!=null) waveformPane.getWaveformControl().setFocus();
}
/**
@ -1108,7 +1117,10 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
* @return the selection
*/
public ISelection getSelection() {
return waveformPane.getSelection();
if(waveformPane!=null)
return waveformPane.getSelection();
else
return new StructuredSelection();
}
/**
@ -1259,5 +1271,4 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
eventBroker.post(WaveStatusBarControl.MARKER_DIFF, null);
}
}
}

View File

@ -9,4 +9,5 @@ org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -5,4 +5,5 @@ org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8