Finished version 1.0
- added relation navigation - improved about dialog
This commit is contained in:
@ -0,0 +1,76 @@
|
||||
/*******************************************************************************
|
||||
* 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.elements;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.ui.di.AboutToShow;
|
||||
import org.eclipse.e4.ui.model.application.MApplication;
|
||||
import org.eclipse.e4.ui.model.application.commands.MCommand;
|
||||
import org.eclipse.e4.ui.model.application.commands.MCommandParameter;
|
||||
import org.eclipse.e4.ui.model.application.commands.MParameter;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
||||
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
||||
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
||||
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.e4.application.parts.WaveformViewerPart;
|
||||
|
||||
public class NavigateContribution {
|
||||
@Inject EPartService partService;
|
||||
|
||||
@AboutToShow
|
||||
public void aboutToShow(List<MMenuElement> items, MApplication application, EModelService modelService) {
|
||||
// modelService.getActivePerspective(window)
|
||||
// modelService.findElements(application,"myID",MPart.class, EModelService.IN_ACTIVE_PERSPECTIVE);
|
||||
// MDirectMenuItem dynamicItem = MMenuFactory.INSTANCE.createDirectMenuItem();
|
||||
MPart part = partService.getActivePart();
|
||||
if(part.getObject()instanceof WaveformViewerPart){
|
||||
WaveformViewerPart waveformViewerPart = (WaveformViewerPart) part.getObject();
|
||||
RelationType relationTypeFilter = waveformViewerPart.getRelationTypeFilter();
|
||||
MCommand command = modelService.findElements(application,
|
||||
"com.minres.scviewer.e4.application.command.setrelationtype", MCommand.class, null).get(0);
|
||||
MCommandParameter commandParameter = command.getParameters().get(0);
|
||||
for(RelationType relationType:waveformViewerPart.getAllRelationTypes()){
|
||||
// MDirectMenuItem dynamicItem = modelService.createModelElement(MDirectMenuItem.class);
|
||||
//
|
||||
// dynamicItem.setLabel(relationType.getName());
|
||||
// dynamicItem.setIconURI(relationTypeFilter.equals(relationType)?
|
||||
// "platform:/plugin/com.minres.scviewer.e4.application/icons/tick.png":
|
||||
// "platform:/plugin/com.minres.scviewer.e4.application/icons/empty.png");
|
||||
// dynamicItem.setContributorURI("platform:/plugin/com.minres.scviewer.e4.application");
|
||||
// dynamicItem.setContributionURI("bundleclass://com.minres.scviewer.e4.application/com.minres.scviewer.e4.application.parts.DirectMenuItem?blah=1");
|
||||
// items.add(dynamicItem);
|
||||
MParameter parameter=modelService.createModelElement(MParameter.class);
|
||||
parameter.setName(commandParameter.getElementId());
|
||||
parameter.setValue(relationType.getName());
|
||||
parameter.setContributorURI("platform:/plugin/com.minres.scviewer.e4.application");
|
||||
MHandledMenuItem handledMenuItem= modelService.createModelElement(MHandledMenuItem.class);
|
||||
handledMenuItem.setLabel(relationType.getName());
|
||||
if(relationTypeFilter.equals(relationType)){
|
||||
handledMenuItem.setEnabled(false);
|
||||
handledMenuItem.setIconURI("platform:/plugin/com.minres.scviewer.e4.application/icons/tick.png");
|
||||
}else
|
||||
handledMenuItem.setIconURI("platform:/plugin/com.minres.scviewer.e4.application/icons/empty.png");
|
||||
handledMenuItem.setContributorURI("platform:/plugin/com.minres.scviewer.e4.application");
|
||||
handledMenuItem.setCommand(command);
|
||||
handledMenuItem.getParameters().add(parameter);
|
||||
items.add(handledMenuItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
/*******************************************************************************
|
||||
* 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.elements;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.Optional;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
||||
import org.eclipse.e4.ui.services.IServiceConstants;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
||||
import org.eclipse.jface.viewers.ArrayContentProvider;
|
||||
import org.eclipse.jface.viewers.ComboViewer;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.e4.application.parts.PartListener;
|
||||
import com.minres.scviewer.e4.application.parts.WaveformViewerPart;
|
||||
|
||||
public class RelationTypeToolControl extends PartListener implements ISelectionChangedListener {
|
||||
|
||||
EPartService partService;
|
||||
|
||||
ComboViewer comboViewer;
|
||||
|
||||
WaveformViewerPart waveformViewerPart;
|
||||
|
||||
RelationType dummy = RelationType.create("------------");
|
||||
|
||||
@Inject
|
||||
public RelationTypeToolControl(EPartService partService) {
|
||||
this.partService=partService;
|
||||
partService.addPartListener(this);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void createGui(Composite parent) {
|
||||
comboViewer = new ComboViewer(parent, SWT.NONE);
|
||||
Combo comboBox = comboViewer.getCombo();
|
||||
comboBox.setBounds(0, 0, 26, 22);
|
||||
comboBox.setText("Select");
|
||||
comboViewer.setContentProvider(new ArrayContentProvider());
|
||||
comboViewer.setInput(new RelationType[] {dummy});
|
||||
comboViewer.setSelection(new StructuredSelection(dummy));
|
||||
comboViewer.addSelectionChangedListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void partActivated(MPart part) {
|
||||
if(part.getObject() instanceof WaveformViewerPart){
|
||||
waveformViewerPart=(WaveformViewerPart) part.getObject();
|
||||
checkSelection(waveformViewerPart.getSelection());
|
||||
} else {
|
||||
waveformViewerPart=null;
|
||||
checkSelection(new StructuredSelection());
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection, EPartService partService){
|
||||
MPart part = partService.getActivePart();
|
||||
if(part!=null && part.getObject() instanceof WaveformViewerPart && comboViewer!=null){
|
||||
checkSelection(selection);
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkSelection(ISelection selection) {
|
||||
if( selection instanceof IStructuredSelection) {
|
||||
Object object= ((IStructuredSelection)selection).getFirstElement();
|
||||
if(object instanceof ITx && waveformViewerPart!=null){
|
||||
comboViewer.getCombo().setEnabled(true);
|
||||
comboViewer.setInput(waveformViewerPart.getSelectionRelationTypes());//getAllRelationTypes());
|
||||
comboViewer.setSelection(new StructuredSelection(waveformViewerPart.getRelationTypeFilter()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
comboViewer.getCombo().setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
MPart part = partService.getActivePart();
|
||||
if(part!=null && part.getObject() instanceof WaveformViewerPart && !event.getSelection().isEmpty()){
|
||||
WaveformViewerPart waveformViewerPart=(WaveformViewerPart) part.getObject();
|
||||
if(event.getSelection() instanceof IStructuredSelection){
|
||||
waveformViewerPart.setNavigationRelationType(
|
||||
(RelationType)((IStructuredSelection)event.getSelection()).getFirstElement());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -12,11 +12,14 @@ package com.minres.scviewer.e4.application.handlers;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import com.minres.scviewer.e4.application.parts.AboutDialog;
|
||||
|
||||
public class AboutHandler {
|
||||
@Execute
|
||||
public void execute(Shell shell) {
|
||||
MessageDialog.openInformation(shell, "About", "Eclipse 4 Application example.");
|
||||
AboutDialog.open(shell, SWT.NONE);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ package com.minres.scviewer.e4.application.handlers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.CanExecute;
|
||||
@ -24,44 +25,46 @@ import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.e4.application.parts.WaveformListPart;
|
||||
import com.minres.scviewer.e4.application.parts.DesignBrowser;
|
||||
|
||||
public class AddWaveformHandler {
|
||||
|
||||
public final static String PARAM_WHERE_ID="com.minres.scviewer.e4.application.command.addwaveform.where";
|
||||
public final static String PARAM_ALL_ID="com.minres.scviewer.e4.application.command.addwaveform.all";
|
||||
|
||||
|
||||
@Inject @Optional DesignBrowser designBrowser;
|
||||
|
||||
@CanExecute
|
||||
public boolean canExecute(@Named(PARAM_WHERE_ID) String where, @Named(PARAM_ALL_ID) String all,
|
||||
EPartService partService,
|
||||
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection) {
|
||||
WaveformListPart listPart = getListPart( partService);
|
||||
if(listPart==null || listPart.getActiveWaveformViewerPart()==null) return false;
|
||||
if(designBrowser==null) designBrowser = getListPart( partService);
|
||||
if(designBrowser==null || designBrowser.getActiveWaveformViewerPart()==null) return false;
|
||||
Boolean before = "before".equalsIgnoreCase(where);
|
||||
if("true".equalsIgnoreCase(all))
|
||||
return listPart.getFilteredChildren().length>0 &&
|
||||
(!before || ((IStructuredSelection)listPart.getActiveWaveformViewerPart().getSelection()).size()>0);
|
||||
return designBrowser.getFilteredChildren().length>0 &&
|
||||
(!before || ((IStructuredSelection)designBrowser.getActiveWaveformViewerPart().getSelection()).size()>0);
|
||||
else
|
||||
return selection.size()>0 &&
|
||||
(!before || ((IStructuredSelection)listPart.getActiveWaveformViewerPart().getSelection()).size()>0);
|
||||
(!before || ((IStructuredSelection)designBrowser.getActiveWaveformViewerPart().getSelection()).size()>0);
|
||||
}
|
||||
|
||||
@Execute
|
||||
public void execute(@Named(PARAM_WHERE_ID) String where, @Named(PARAM_ALL_ID) String all,
|
||||
EPartService partService,
|
||||
@Named(IServiceConstants.ACTIVE_SELECTION) @Optional IStructuredSelection selection) {
|
||||
WaveformListPart listPart = getListPart( partService);
|
||||
if(listPart!=null && selection.size()>0){
|
||||
if(designBrowser==null) designBrowser = getListPart( partService);
|
||||
if(designBrowser!=null && selection.size()>0){
|
||||
List<?> sel=selection.toList();
|
||||
listPart.getActiveWaveformViewerPart().addStreamsToList(sel.toArray(new IWaveform<?>[]{}),
|
||||
designBrowser.getActiveWaveformViewerPart().addStreamsToList(sel.toArray(new IWaveform<?>[]{}),
|
||||
"before".equalsIgnoreCase(where));
|
||||
}
|
||||
}
|
||||
|
||||
protected WaveformListPart getListPart(EPartService partService){
|
||||
protected DesignBrowser getListPart(EPartService partService){
|
||||
MPart part = partService.getActivePart();
|
||||
if(part.getObject() instanceof WaveformListPart)
|
||||
return (WaveformListPart) part.getObject();
|
||||
if(part.getObject() instanceof DesignBrowser)
|
||||
return (DesignBrowser) part.getObject();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
/*******************************************************************************
|
||||
* 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.handlers;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
||||
|
||||
import com.minres.scviewer.e4.application.parts.WaveformViewerPart;
|
||||
|
||||
public class SetRelationTypeHandler {
|
||||
final static String PARAMTER_ID="com.minres.scviewer.e4.application.commandparameter.relationName";
|
||||
|
||||
@Execute
|
||||
public void execute(@Named(PARAMTER_ID) String relationName, EPartService partService) {
|
||||
MPart part = partService.getActivePart();
|
||||
Object obj = part.getObject();
|
||||
if(obj instanceof WaveformViewerPart){
|
||||
WaveformViewerPart waveformViewerPart = (WaveformViewerPart) obj;
|
||||
waveformViewerPart.setNavigationRelationType(relationName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,183 @@
|
||||
/*******************************************************************************
|
||||
* 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.parts;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.StyleRange;
|
||||
import org.eclipse.swt.custom.StyledText;
|
||||
import org.eclipse.swt.events.PaintEvent;
|
||||
import org.eclipse.swt.events.PaintListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Canvas;
|
||||
import org.eclipse.swt.widgets.Dialog;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Link;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.wb.swt.ResourceManager;
|
||||
import org.eclipse.wb.swt.SWTResourceManager;
|
||||
|
||||
public class AboutDialog extends Dialog {
|
||||
|
||||
protected int result;
|
||||
protected Shell shell;
|
||||
private Color white;
|
||||
protected StyledText styledText;
|
||||
/*
|
||||
Eclipse IDE for Java Developers
|
||||
|
||||
Version: Mars.1 Release (4.5.1)
|
||||
Build id: 20150924-1200
|
||||
(c) Copyright Eclipse contributors and others 2000, 2015. All rights reserved. Eclipse and the Eclipse logo are trademarks of the Eclipse Foundation, Inc., https://www.eclipse.org/. The Eclipse logo cannot be altered without Eclipse's permission. Eclipse logos are provided for use under the Eclipse logo and trademark guidelines, https://www.eclipse.org/logotm/. Oracle and Java are trademarks or registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
|
||||
*/
|
||||
private String productTitle=
|
||||
"\nSCViewer - a SystemC waveform viewer\n\nVersion: 1.0\n";
|
||||
private String copyrightText="\nCopyright (c) 2015 MINRES Technologies GmbH and others.\n"+
|
||||
"\n"+
|
||||
"All rights reserved. MINRES and the MINRES logo are trademarks of MINRES Technologies GmbH, http://www.minres.com/ . "+
|
||||
"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\n";
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
* @param parent
|
||||
* @param style
|
||||
*/
|
||||
public AboutDialog(Shell parent, int style) {
|
||||
super(parent, style);
|
||||
setText("SWT Dialog");
|
||||
white=SWTResourceManager.getColor(SWT.COLOR_WHITE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the dialog.
|
||||
* @return the result
|
||||
*/
|
||||
public int open() {
|
||||
createContents();
|
||||
shell.open();
|
||||
shell.layout();
|
||||
Display display = getParent().getDisplay();
|
||||
while (!shell.isDisposed()) {
|
||||
if (!display.readAndDispatch()) {
|
||||
display.sleep();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create contents of the dialog.
|
||||
*/
|
||||
private void createContents() {
|
||||
shell = new Shell(getParent(), getStyle());
|
||||
shell.setSize(600, 300);
|
||||
shell.setText(getText());
|
||||
shell.setLayout(new GridLayout(2, false));
|
||||
final Image scviewerLogo=ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/SCViewer_logo.png");
|
||||
final Image minresLogo=ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/Minres_logo.png");
|
||||
|
||||
Canvas canvas = new Canvas(shell,SWT.NO_REDRAW_RESIZE);
|
||||
GridData gd_canvas = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
|
||||
gd_canvas.widthHint = 200;
|
||||
gd_canvas.heightHint =250;
|
||||
canvas.setLayoutData(gd_canvas);
|
||||
canvas.addPaintListener(new PaintListener() {
|
||||
public void paintControl(PaintEvent e) {
|
||||
e.gc.setBackground(white);
|
||||
e.gc.fillRectangle(e.x, e.y, e.width, e.height);
|
||||
e.gc.drawImage(scviewerLogo,4,0);
|
||||
e.gc.drawImage(minresLogo,0,200);
|
||||
}
|
||||
});
|
||||
|
||||
styledText = new StyledText(shell, SWT.BORDER);
|
||||
styledText.setEditable(false);
|
||||
GridData gd_styledText = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
|
||||
styledText.setLayoutData(gd_styledText);
|
||||
styledText.setText(productTitle+copyrightText);
|
||||
styledText.setBackground(white);
|
||||
styledText.setWordWrap(true);
|
||||
styledText.setLeftMargin(5);
|
||||
StyleRange styleRange = new StyleRange();
|
||||
styleRange.start = 0;
|
||||
styleRange.length = productTitle.length();
|
||||
styleRange.fontStyle = SWT.BOLD;
|
||||
styledText.setStyleRange(styleRange);
|
||||
///^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
|
||||
Pattern pattern = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w\\.-]*)*\\/?");
|
||||
// in case you would like to ignore case sensitivity,
|
||||
// you could use this statement:
|
||||
// Pattern pattern = Pattern.compile("\\s+", Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(productTitle+copyrightText);
|
||||
// check all occurance
|
||||
while (matcher.find()) {
|
||||
styleRange = new StyleRange();
|
||||
styleRange.underline=true;
|
||||
styleRange.underlineStyle = SWT.UNDERLINE_LINK;
|
||||
styleRange.data = matcher.group();
|
||||
styleRange.start = matcher.start();
|
||||
styleRange.length = matcher.end()-matcher.start();
|
||||
styledText.setStyleRange(styleRange);
|
||||
}
|
||||
styledText.addListener(SWT.MouseDown, new Listener() {
|
||||
@Override
|
||||
public void handleEvent(Event event) {
|
||||
// It is up to the application to determine when and how a link should be activated.
|
||||
// links are activated on mouse down when the control key is held down
|
||||
// if ((event.stateMask & SWT.MOD1) != 0) {
|
||||
try {
|
||||
int offset = styledText.getOffsetAtLocation(new Point (event.x, event.y));
|
||||
StyleRange style = styledText.getStyleRangeAtOffset(offset);
|
||||
if (style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) {
|
||||
Desktop.getDesktop().browse(new java.net.URI(style.data.toString()));
|
||||
}
|
||||
} catch (IOException | URISyntaxException | IllegalArgumentException e) {}
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
||||
styleRange.start = 0;
|
||||
new Label(shell, SWT.NONE);
|
||||
|
||||
Button okButton = new Button(shell, SWT.NONE);
|
||||
okButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
|
||||
okButton.setBounds(0, 0, 94, 28);
|
||||
okButton.setText("Close");
|
||||
okButton.setFocus();
|
||||
okButton.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
if(!shell.isDisposed()) shell.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean open(Shell parent, int style) {
|
||||
AboutDialog dialog = new AboutDialog(parent, style | SWT.SHEET);
|
||||
return dialog.open() == 0;
|
||||
}
|
||||
}
|
@ -12,39 +12,97 @@ package com.minres.scviewer.e4.application.parts;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.core.di.annotations.CanExecute;
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
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.di.UIEventTopic;
|
||||
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.DoubleClickEvent;
|
||||
import org.eclipse.jface.viewers.IDoubleClickListener;
|
||||
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.SelectionChangedEvent;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
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.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
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.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.handlers.AddWaveformHandler;
|
||||
import com.minres.scviewer.e4.application.provider.TxDbContentProvider;
|
||||
import com.minres.scviewer.e4.application.provider.TxDbLabelProvider;
|
||||
|
||||
public class DesignBrowser implements ISelectionChangedListener {
|
||||
public class DesignBrowser {
|
||||
|
||||
private static final String POPUP_ID="com.minres.scviewer.e4.application.parts.DesignBrowser.popupmenu";
|
||||
|
||||
@Inject IEventBroker eventBroker;
|
||||
|
||||
@Inject ESelectionService selectionService;
|
||||
|
||||
@Inject EMenuService menuService;
|
||||
|
||||
@Inject IEclipseContext eclipseCtx;
|
||||
|
||||
private SashForm sashForm;
|
||||
|
||||
Composite top;
|
||||
|
||||
private Composite bottom;
|
||||
|
||||
private TreeViewer treeViewer;
|
||||
|
||||
private Text nameFilter;
|
||||
|
||||
private PropertyChangeListener l = new PropertyChangeListener() {
|
||||
private TableViewer txTableViewer;
|
||||
|
||||
ToolItem appendItem, insertItem, insertAllItem, appendAllItem;
|
||||
|
||||
WaveformAttributeFilter attributeFilter;
|
||||
|
||||
int thisSelectionCount=0, otherSelectionCount=0;
|
||||
|
||||
private PropertyChangeListener treeViewerPCL = new PropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if("CHILDS".equals(evt.getPropertyName())){
|
||||
@ -58,46 +116,327 @@ public class DesignBrowser implements ISelectionChangedListener {
|
||||
}
|
||||
};
|
||||
|
||||
private WaveformViewerPart waveformViewerPart;
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void createTreeViewerComposite(Composite parent) {
|
||||
parent.setLayout(new GridLayout(1, false));
|
||||
treeViewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
treeViewer.addSelectionChangedListener(this);
|
||||
treeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
treeViewer.setContentProvider(new TxDbContentProvider());
|
||||
treeViewer.setLabelProvider(new TxDbLabelProvider());
|
||||
treeViewer.setUseHashlookup(true);
|
||||
treeViewer.setAutoExpandLevel(2);
|
||||
treeViewer.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){
|
||||
txTableViewer.setInput(object);
|
||||
updateButtons();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void createTableComposite(Composite parent) {
|
||||
parent.setLayout(new GridLayout(1, false));
|
||||
|
||||
nameFilter = new Text(parent, SWT.BORDER);
|
||||
nameFilter.setMessage("Enter text to filter waveforms");
|
||||
nameFilter.addModifyListener(new ModifyListener() {
|
||||
@Override
|
||||
public void modifyText(ModifyEvent e) {
|
||||
attributeFilter.setSearchText(((Text) e.widget).getText());
|
||||
updateButtons();
|
||||
txTableViewer.refresh();
|
||||
}
|
||||
});
|
||||
nameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
attributeFilter = new WaveformAttributeFilter();
|
||||
|
||||
txTableViewer = new TableViewer(parent);
|
||||
txTableViewer.setContentProvider(new TxDbContentProvider(true));
|
||||
txTableViewer.setLabelProvider(new TxDbLabelProvider());
|
||||
txTableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
txTableViewer.addFilter(attributeFilter);
|
||||
txTableViewer.addDoubleClickListener(new IDoubleClickListener() {
|
||||
@Override
|
||||
public void doubleClick(DoubleClickEvent event) {
|
||||
AddWaveformHandler myHandler = new AddWaveformHandler();
|
||||
Object result = runCommand(myHandler, CanExecute.class, "after", false);
|
||||
if(result!=null && (Boolean)result)
|
||||
ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx);
|
||||
}
|
||||
});
|
||||
txTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||
|
||||
@Override
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
selectionService.setSelection(event.getSelection());
|
||||
updateButtons();
|
||||
}
|
||||
});
|
||||
|
||||
menuService.registerContextMenu(txTableViewer.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("Append after");
|
||||
appendItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/append_wave.png"));
|
||||
appendItem.setEnabled(false);
|
||||
appendItem.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
AddWaveformHandler myHandler = new AddWaveformHandler();
|
||||
Object result = runCommand(myHandler, CanExecute.class, "after", false);
|
||||
if(result!=null && (Boolean)result)
|
||||
ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
insertItem = new ToolItem(toolBar, SWT.NONE);
|
||||
insertItem.setToolTipText("Insert before");
|
||||
insertItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/insert_wave.png"));
|
||||
insertItem.setEnabled(false);
|
||||
insertItem.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
AddWaveformHandler myHandler = new AddWaveformHandler();
|
||||
Object result = runCommand(myHandler, CanExecute.class, "before", false);
|
||||
if(result!=null && (Boolean)result)
|
||||
ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx);
|
||||
}
|
||||
});
|
||||
new ToolItem(toolBar, SWT.SEPARATOR);
|
||||
|
||||
appendAllItem = new ToolItem(toolBar, SWT.NONE);
|
||||
appendAllItem.setToolTipText("Append all after");
|
||||
appendAllItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/append_all_waves.png"));
|
||||
appendAllItem.setEnabled(false);
|
||||
|
||||
new ToolItem(toolBar, SWT.SEPARATOR);
|
||||
appendAllItem.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
Object[] all = getFilteredChildren(txTableViewer);
|
||||
if(all.length>0){
|
||||
Object oldSel=selectionService.getSelection();
|
||||
selectionService.setSelection(new StructuredSelection(all));
|
||||
AddWaveformHandler myHandler = new AddWaveformHandler();
|
||||
Object result = runCommand(myHandler, CanExecute.class, "after", false);
|
||||
if(result!=null && (Boolean)result)
|
||||
ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx);
|
||||
selectionService.setSelection(oldSel);
|
||||
}
|
||||
}
|
||||
});
|
||||
insertAllItem = new ToolItem(toolBar, SWT.NONE);
|
||||
insertAllItem.setToolTipText("Insert all before");
|
||||
insertAllItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/insert_all_waves.png"));
|
||||
insertAllItem.setEnabled(false);
|
||||
insertAllItem.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
Object[] all = getFilteredChildren(txTableViewer);
|
||||
if(all.length>0){
|
||||
Object oldSel=selectionService.getSelection();
|
||||
selectionService.setSelection(new StructuredSelection(all));
|
||||
AddWaveformHandler myHandler = new AddWaveformHandler();
|
||||
Object result = runCommand(myHandler, CanExecute.class, "before", false);
|
||||
if(result!=null && (Boolean)result)
|
||||
ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx);
|
||||
selectionService.setSelection(oldSel);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Focus
|
||||
public void setFocus() {
|
||||
treeViewer.getTree().setFocus();
|
||||
selectionService.setSelection(treeViewer.getSelection());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
selectionService.setSelection(event.getSelection());
|
||||
txTableViewer.getTable().setFocus();
|
||||
IStructuredSelection selection = (IStructuredSelection)txTableViewer.getSelection();
|
||||
if(selection.size()==0){
|
||||
appendItem.setEnabled(false);
|
||||
}
|
||||
selectionService.setSelection(selection);
|
||||
thisSelectionCount=selection.toList().size();
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Inject @Optional
|
||||
public void getStatusEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_WAVEFORMVIEW) WaveformViewerPart waveformViewerPart) {
|
||||
if(this.waveformViewerPart!=null)
|
||||
this.waveformViewerPart.storeDesignBrowerState(new DBState());
|
||||
this.waveformViewerPart=waveformViewerPart;
|
||||
IWaveformDb database = waveformViewerPart.getDatabase();
|
||||
Object input = treeViewer.getInput();
|
||||
if(input!=null && input instanceof List<?>)
|
||||
((List<IWaveformDb>)input).get(0).removePropertyChangeListener(l);
|
||||
if(input!=null && input instanceof List<?>){
|
||||
IWaveformDb db = ((List<IWaveformDb>)input).get(0);
|
||||
if(db==database) return; // do nothing if old and new daabase is the same
|
||||
((List<IWaveformDb>)input).get(0).removePropertyChangeListener(treeViewerPCL);
|
||||
}
|
||||
treeViewer.setInput(database.isLoaded()?Arrays.asList(new IWaveformDb[]{database}):null);
|
||||
Object state=this.waveformViewerPart.retrieveDesignBrowerState();
|
||||
if(state!=null && state instanceof DBState)
|
||||
((DBState)state).apply();
|
||||
else
|
||||
txTableViewer.setInput(null);
|
||||
// Set up the tree viewer
|
||||
database.addPropertyChangeListener(l);
|
||||
database.addPropertyChangeListener(treeViewerPCL);
|
||||
}
|
||||
/*
|
||||
* TODO: needs top be implemented
|
||||
@Inject @Optional
|
||||
public void getStatusEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_NODE_PATH) String path) {
|
||||
|
||||
|
||||
@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)
|
||||
txTableViewer.setInput(object);
|
||||
otherSelectionCount = (object instanceof IWaveform<?> || object instanceof ITx)?1:0;
|
||||
}
|
||||
}
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
private void updateButtons() {
|
||||
if(txTableViewer!=null && !insertItem.isDisposed() && !appendItem.isDisposed() &&
|
||||
!appendAllItem.isDisposed() && !insertAllItem.isDisposed()){
|
||||
AddWaveformHandler myHandler = new AddWaveformHandler();
|
||||
Object result = runCommand(myHandler, CanExecute.class, "after", false);
|
||||
appendItem.setEnabled(result instanceof Boolean && (Boolean)result);
|
||||
result = runCommand(myHandler, CanExecute.class, "after", true);
|
||||
appendAllItem.setEnabled(result instanceof Boolean && (Boolean)result);
|
||||
result = runCommand(myHandler, CanExecute.class, "before", false);
|
||||
insertItem.setEnabled(result instanceof Boolean && (Boolean)result);
|
||||
result = runCommand(myHandler, CanExecute.class, "before", true);
|
||||
insertAllItem.setEnabled(result instanceof Boolean && (Boolean)result);
|
||||
}
|
||||
}
|
||||
|
||||
public class WaveformAttributeFilter extends ViewerFilter {
|
||||
|
||||
private String searchString;
|
||||
|
||||
public void setSearchText(String s) {
|
||||
this.searchString = ".*" + s + ".*";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
if (searchString == null || searchString.length() == 0) {
|
||||
return true;
|
||||
}
|
||||
IWaveform<?> p = (IWaveform<?>) element;
|
||||
if (p.getName().matches(searchString)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
protected Object runCommand(AddWaveformHandler handler, Class<? extends Annotation> annotation, String where, Boolean all) {
|
||||
ContextInjectionFactory.inject(handler, eclipseCtx);
|
||||
eclipseCtx.set(AddWaveformHandler.PARAM_WHERE_ID, where);
|
||||
eclipseCtx.set(AddWaveformHandler.PARAM_ALL_ID, all.toString());
|
||||
eclipseCtx.set(DesignBrowser.class, this);
|
||||
eclipseCtx.set(WaveformViewerPart.class, waveformViewerPart);
|
||||
Object result = ContextInjectionFactory.invoke(handler, annotation, eclipseCtx);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Object[] getFilteredChildren() {
|
||||
return getFilteredChildren(txTableViewer);
|
||||
}
|
||||
|
||||
public WaveformViewerPart getActiveWaveformViewerPart() {
|
||||
return waveformViewerPart;
|
||||
}
|
||||
|
||||
class DBState {
|
||||
|
||||
public DBState() {
|
||||
this.expandedElements=treeViewer.getExpandedElements();
|
||||
this.treeSelection=treeViewer.getSelection();
|
||||
this.tableSelection=txTableViewer.getSelection();
|
||||
}
|
||||
|
||||
public void apply() {
|
||||
treeViewer.setExpandedElements(expandedElements);
|
||||
treeViewer.setSelection(treeSelection, true);
|
||||
txTableViewer.setSelection(tableSelection, true);
|
||||
|
||||
}
|
||||
|
||||
private Object[] expandedElements;
|
||||
private ISelection treeSelection;
|
||||
private ISelection tableSelection;
|
||||
}
|
||||
*/
|
||||
};
|
@ -1,327 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* 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.parts;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.core.di.annotations.CanExecute;
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
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.di.UIEventTopic;
|
||||
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.DoubleClickEvent;
|
||||
import org.eclipse.jface.viewers.IDoubleClickListener;
|
||||
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.SelectionChangedEvent;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.viewers.ViewerFilter;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
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 com.minres.scviewer.database.IHierNode;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.e4.application.handlers.AddWaveformHandler;
|
||||
import com.minres.scviewer.e4.application.provider.TxDbContentProvider;
|
||||
import com.minres.scviewer.e4.application.provider.TxDbLabelProvider;
|
||||
|
||||
public class WaveformListPart implements ISelectionChangedListener {
|
||||
|
||||
private static final String POPUP_ID="com.minres.scviewer.e4.application.parts.WaveformList.popupmenu";
|
||||
|
||||
@Inject IEventBroker eventBroker;
|
||||
|
||||
@Inject ESelectionService selectionService;
|
||||
|
||||
@Inject EMenuService menuService;
|
||||
|
||||
@Inject IEclipseContext eclipseCtx;
|
||||
|
||||
|
||||
private Text nameFilter;
|
||||
|
||||
private TableViewer txTableViewer;
|
||||
|
||||
ToolItem appendItem, insertItem, insertAllItem, appendAllItem;
|
||||
|
||||
WaveformAttributeFilter attributeFilter;
|
||||
|
||||
int thisSelectionCount=0, otherSelectionCount=0;
|
||||
|
||||
private WaveformViewerPart waveformViewerPart;
|
||||
|
||||
@PostConstruct
|
||||
public void createComposite(Composite parent) {
|
||||
parent.setLayout(new GridLayout(1, false));
|
||||
|
||||
nameFilter = new Text(parent, SWT.BORDER);
|
||||
nameFilter.setMessage("Enter text to filter waveforms");
|
||||
nameFilter.addModifyListener(new ModifyListener() {
|
||||
@Override
|
||||
public void modifyText(ModifyEvent e) {
|
||||
attributeFilter.setSearchText(((Text) e.widget).getText());
|
||||
updateButtons();
|
||||
txTableViewer.refresh();
|
||||
}
|
||||
});
|
||||
nameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
attributeFilter = new WaveformAttributeFilter();
|
||||
|
||||
txTableViewer = new TableViewer(parent);
|
||||
txTableViewer.setContentProvider(new TxDbContentProvider(true));
|
||||
txTableViewer.setLabelProvider(new TxDbLabelProvider());
|
||||
txTableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
txTableViewer.addSelectionChangedListener(this);
|
||||
txTableViewer.addFilter(attributeFilter);
|
||||
txTableViewer.addDoubleClickListener(new IDoubleClickListener() {
|
||||
@Override
|
||||
public void doubleClick(DoubleClickEvent event) {
|
||||
AddWaveformHandler myHandler = new AddWaveformHandler();
|
||||
Object result = runCommand(myHandler, CanExecute.class, "after", false);
|
||||
if(result!=null && (Boolean)result)
|
||||
ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx);
|
||||
}
|
||||
});
|
||||
menuService.registerContextMenu(txTableViewer.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("Append after");
|
||||
appendItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/append_wave.png"));
|
||||
appendItem.setEnabled(false);
|
||||
appendItem.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
/*
|
||||
eventBroker.post(WaveformViewerPart.ADD_WAVEFORM,
|
||||
((IStructuredSelection)txTableViewer.getSelection()).toList());
|
||||
ECommandService commandService = eclipseCtx.get(ECommandService.class);
|
||||
EHandlerService handlerService = eclipseCtx.get(EHandlerService.class);
|
||||
HashMap<String,Object> param=new HashMap<>();
|
||||
param.clear();
|
||||
//param.put("where", "after");
|
||||
ParameterizedCommand myCommand = commandService.createCommand(COMMAND_ID, param);
|
||||
if(myCommand!=null)handlerService.executeHandler(myCommand);
|
||||
*/
|
||||
AddWaveformHandler myHandler = new AddWaveformHandler();
|
||||
Object result = runCommand(myHandler, CanExecute.class, "after", false);
|
||||
if(result!=null && (Boolean)result)
|
||||
ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
insertItem = new ToolItem(toolBar, SWT.NONE);
|
||||
insertItem.setToolTipText("Insert before");
|
||||
insertItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/insert_wave.png"));
|
||||
insertItem.setEnabled(false);
|
||||
insertItem.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
AddWaveformHandler myHandler = new AddWaveformHandler();
|
||||
Object result = runCommand(myHandler, CanExecute.class, "before", false);
|
||||
if(result!=null && (Boolean)result)
|
||||
ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx);
|
||||
}
|
||||
});
|
||||
new ToolItem(toolBar, SWT.SEPARATOR);
|
||||
|
||||
appendAllItem = new ToolItem(toolBar, SWT.NONE);
|
||||
appendAllItem.setToolTipText("Append all after");
|
||||
appendAllItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/append_all_waves.png"));
|
||||
appendAllItem.setEnabled(false);
|
||||
|
||||
new ToolItem(toolBar, SWT.SEPARATOR);
|
||||
appendAllItem.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
Object[] all = getFilteredChildren(txTableViewer);
|
||||
if(all.length>0){
|
||||
Object oldSel=selectionService.getSelection();
|
||||
selectionService.setSelection(new StructuredSelection(all));
|
||||
AddWaveformHandler myHandler = new AddWaveformHandler();
|
||||
Object result = runCommand(myHandler, CanExecute.class, "after", false);
|
||||
if(result!=null && (Boolean)result)
|
||||
ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx);
|
||||
selectionService.setSelection(oldSel);
|
||||
}
|
||||
}
|
||||
});
|
||||
insertAllItem = new ToolItem(toolBar, SWT.NONE);
|
||||
insertAllItem.setToolTipText("Insert all before");
|
||||
insertAllItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/insert_all_waves.png"));
|
||||
insertAllItem.setEnabled(false);
|
||||
insertAllItem.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
Object[] all = getFilteredChildren(txTableViewer);
|
||||
if(all.length>0){
|
||||
Object oldSel=selectionService.getSelection();
|
||||
selectionService.setSelection(new StructuredSelection(all));
|
||||
AddWaveformHandler myHandler = new AddWaveformHandler();
|
||||
Object result = runCommand(myHandler, CanExecute.class, "before", false);
|
||||
if(result!=null && (Boolean)result)
|
||||
ContextInjectionFactory.invoke(myHandler, Execute.class, eclipseCtx);
|
||||
selectionService.setSelection(oldSel);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Focus
|
||||
public void setFocus() {
|
||||
txTableViewer.getTable().setFocus();
|
||||
setSelection(txTableViewer.getSelection());
|
||||
}
|
||||
|
||||
@Inject @Optional
|
||||
public void getStatusEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_WAVEFORMVIEW) WaveformViewerPart part) {
|
||||
this.waveformViewerPart=part;
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
setSelection(event.getSelection());
|
||||
}
|
||||
|
||||
protected void setSelection(ISelection iSelection) {
|
||||
IStructuredSelection selection = (IStructuredSelection)iSelection;
|
||||
if(selection.size()==0){
|
||||
appendItem.setEnabled(false);
|
||||
}
|
||||
selectionService.setSelection(selection);
|
||||
thisSelectionCount=selection.toList().size();
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
@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)
|
||||
txTableViewer.setInput(object);
|
||||
otherSelectionCount = (object instanceof IWaveform<?> || object instanceof ITx)?1:0;
|
||||
}
|
||||
}
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
private void updateButtons() {
|
||||
if(txTableViewer!=null && !insertItem.isDisposed() && !appendItem.isDisposed() &&
|
||||
!appendAllItem.isDisposed() && !insertAllItem.isDisposed()){
|
||||
AddWaveformHandler myHandler = new AddWaveformHandler();
|
||||
Object result = runCommand(myHandler, CanExecute.class, "after", false);
|
||||
appendItem.setEnabled(result instanceof Boolean && (Boolean)result);
|
||||
result = runCommand(myHandler, CanExecute.class, "after", true);
|
||||
appendAllItem.setEnabled(result instanceof Boolean && (Boolean)result);
|
||||
result = runCommand(myHandler, CanExecute.class, "before", false);
|
||||
insertItem.setEnabled(result instanceof Boolean && (Boolean)result);
|
||||
result = runCommand(myHandler, CanExecute.class, "before", true);
|
||||
insertAllItem.setEnabled(result instanceof Boolean && (Boolean)result);
|
||||
}
|
||||
}
|
||||
|
||||
public class WaveformAttributeFilter extends ViewerFilter {
|
||||
|
||||
private String searchString;
|
||||
|
||||
public void setSearchText(String s) {
|
||||
this.searchString = ".*" + s + ".*";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
if (searchString == null || searchString.length() == 0) {
|
||||
return true;
|
||||
}
|
||||
IWaveform<?> p = (IWaveform<?>) element;
|
||||
if (p.getName().matches(searchString)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Object[] getFilteredChildren(){
|
||||
return getFilteredChildren(txTableViewer);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public WaveformViewerPart getActiveWaveformViewerPart() {
|
||||
return waveformViewerPart;
|
||||
}
|
||||
|
||||
protected Object runCommand(AddWaveformHandler myHandler, Class<? extends Annotation> annotation, String where, Boolean all) {
|
||||
ContextInjectionFactory.inject(myHandler, eclipseCtx);
|
||||
eclipseCtx.set(AddWaveformHandler.PARAM_WHERE_ID, where);
|
||||
eclipseCtx.set(AddWaveformHandler.PARAM_ALL_ID, all.toString());
|
||||
Object result = ContextInjectionFactory.invoke(myHandler, annotation, eclipseCtx);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -57,10 +57,12 @@ import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.ITxRelation;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbFactory;
|
||||
import com.minres.scviewer.database.IWaveformEvent;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.swt.WaveformViewerFactory;
|
||||
import com.minres.scviewer.database.ui.GotoDirection;
|
||||
import com.minres.scviewer.database.ui.ICursor;
|
||||
@ -87,7 +89,7 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang
|
||||
protected static final String ZOOM_LEVEL = "ZOOM_LEVEL";
|
||||
|
||||
protected static final long FILE_CHECK_INTERVAL = 60000;
|
||||
|
||||
|
||||
private String[] zoomLevel;
|
||||
|
||||
public static final String ID = "com.minres.scviewer.ui.TxEditorPart"; //$NON-NLS-1$
|
||||
@ -126,6 +128,10 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang
|
||||
|
||||
Map<String, String> persistedState;
|
||||
|
||||
private Object browserState;
|
||||
|
||||
private RelationType navigationRelationType=IWaveformViewer.NEXT_PREV_IN_STREAM ;
|
||||
|
||||
FileMonitor fileMonitor = new FileMonitor();
|
||||
|
||||
IModificationChecker fileChecker;
|
||||
@ -487,11 +493,16 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang
|
||||
}
|
||||
|
||||
public void moveSelected(int i) {
|
||||
waveformPane.moveSelected(i);
|
||||
waveformPane.moveSelectedTrack(i);
|
||||
}
|
||||
|
||||
public void moveSelection(GotoDirection direction) {
|
||||
waveformPane.moveSelection(direction);
|
||||
|
||||
public void moveSelection(GotoDirection direction ) {
|
||||
moveSelection(direction, navigationRelationType);
|
||||
}
|
||||
|
||||
public void moveSelection(GotoDirection direction, RelationType relationType) {
|
||||
waveformPane.moveSelection(direction, relationType);
|
||||
}
|
||||
|
||||
public void moveCursor(GotoDirection direction) {
|
||||
@ -528,4 +539,53 @@ public class WaveformViewerPart implements IFileChangeListener, IPreferenceChang
|
||||
return waveformPane.getScaledTime(time);
|
||||
}
|
||||
|
||||
public void storeDesignBrowerState(Object browserState) {
|
||||
this.browserState=browserState;
|
||||
}
|
||||
|
||||
public Object retrieveDesignBrowerState() {
|
||||
return browserState;
|
||||
}
|
||||
|
||||
public List<RelationType> getAllRelationTypes() {
|
||||
List<RelationType> res =new ArrayList<>();
|
||||
res.add(IWaveformViewer.NEXT_PREV_IN_STREAM);
|
||||
res.addAll(database.getAllRelationTypes());
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<RelationType> getSelectionRelationTypes() {
|
||||
List<RelationType> res =new ArrayList<>();
|
||||
res.add(IWaveformViewer.NEXT_PREV_IN_STREAM);
|
||||
ISelection selection = waveformPane.getSelection();
|
||||
if(selection instanceof IStructuredSelection && !selection.isEmpty()){
|
||||
IStructuredSelection sel=(IStructuredSelection) selection;
|
||||
if(sel.getFirstElement() instanceof ITx){
|
||||
ITx tx = (ITx) sel.getFirstElement();
|
||||
for(ITxRelation rel:tx.getIncomingRelations()){
|
||||
if(!res.contains(rel.getRelationType()))
|
||||
res.add(rel.getRelationType());
|
||||
}
|
||||
for(ITxRelation rel:tx.getOutgoingRelations()){
|
||||
if(!res.contains(rel.getRelationType()))
|
||||
res.add(rel.getRelationType());
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public RelationType getRelationTypeFilter() {
|
||||
return navigationRelationType;
|
||||
}
|
||||
|
||||
public void setNavigationRelationType(String relationName) {
|
||||
setNavigationRelationType(RelationType.create(relationName));
|
||||
}
|
||||
|
||||
public void setNavigationRelationType(RelationType relationType) {
|
||||
if(navigationRelationType!=relationType) waveformPane.setHighliteRelation(relationType);
|
||||
navigationRelationType=relationType;
|
||||
}
|
||||
|
||||
}
|
@ -44,7 +44,8 @@ public class DefaultValuesInitializer extends AbstractPreferenceInitializer {
|
||||
colors[WaveformColors.CURSOR_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE);
|
||||
colors[WaveformColors.MARKER.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY);
|
||||
colors[WaveformColors.MARKER_TEXT.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_WHITE);
|
||||
colors[WaveformColors.REL_ARROW.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_YELLOW);
|
||||
colors[WaveformColors.REL_ARROW.ordinal()] = SWTResourceManager.getColor(SWT.COLOR_MAGENTA);
|
||||
colors[WaveformColors.REL_ARROW_HIGHLITE.ordinal()] = SWTResourceManager.getColor(255, 128, 255);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user