Merge branch 'release/2.5'

This commit is contained in:
Eyck Jentzsch 2020-03-30 11:36:06 +02:00
commit 47b58ed770
13 changed files with 500 additions and 22 deletions

View File

@ -81,6 +81,7 @@ public class SQLiteDbLoader implements IWaveformDbLoader {
@Override
public boolean load(IWaveformDb db, File file) throws Exception {
if(file.isDirectory() || !file.exists()) return false;
this.db=db;
try {
FileInputStream fis = new FileInputStream(file);

View File

@ -64,6 +64,7 @@ public class TextDbLoader implements IWaveformDbLoader{
@Override
boolean load(IWaveformDb db, File file) throws Exception {
if(file.isDirectory() || !file.exists()) return false;
this.db=db
this.streams=[]
try {

View File

@ -79,6 +79,7 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
@SuppressWarnings("unchecked")
@Override
public boolean load(IWaveformDb db, File file) throws Exception {
if(file.isDirectory() || !file.exists()) return false;
this.db=db;
this.maxTime=0;
String name = file.getCanonicalFile().getName();

View File

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: com.minres.scviewer.e4.application;singleton:=true
Bundle-Version: 2.4.2.qualifier
Bundle-Version: 2.5.0.qualifier
Bundle-Vendor: %Bundle-Vendor
Require-Bundle: javax.inject;bundle-version="1.0.0",
org.eclipse.core.runtime;bundle-version="3.11.1",

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

View File

@ -1,7 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>com.minres.scviewer.e4.application</artifactId>
<version>2.4.2-SNAPSHOT</version>
<version>2.5.0-SNAPSHOT</version>
<parent>
<groupId>com.minres.scviewer</groupId>
<artifactId>com.minres.scviewer.parent</artifactId>

View File

@ -11,7 +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;
import org.eclipse.e4.core.di.annotations.Execute;
@ -21,27 +21,20 @@ import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import com.minres.scviewer.e4.application.Messages;
import com.minres.scviewer.e4.application.parts.FileBrowserDialog;
public class OpenHandler {
@Execute
public void execute(Shell shell, MApplication app, EModelService modelService, EPartService partService){
FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
dialog.setFilterExtensions (new String []{Messages.OpenHandler_0});
String ret = dialog.open();
if(ret==null)
return;
String path = dialog.getFilterPath();
ArrayList<File> files = new ArrayList<File>();
for(String fileName: dialog.getFileNames()){
File file = new File(path+File.separator+fileName);
if(file.exists())
files.add(file);
}
FileBrowserDialog dlg = new FileBrowserDialog(shell);
//dlg.create();
dlg.setFilterExtensions (new String []{Messages.OpenHandler_0, "*"});
if (dlg.open() != Window.OK) return;
List<File> files = dlg.getSelectedFiles();
MPart part = partService .createPart("com.minres.scviewer.e4.application.partdescriptor.waveformviewer"); //$NON-NLS-1$
part.setLabel(files.get(0).getName());
MPartStack partStack = (MPartStack)modelService.find("org.eclipse.editorss", app); //$NON-NLS-1$

View File

@ -9,7 +9,7 @@ DesignBrowser_8=Insert before
LoadingWaveformDb_0=Database loading...
LoadStoreSettingsHandler_2=*.scview
LoadStoreSettingsHandler_3=SCViewer.scview
OpenHandler_0=*.vcd;*.txdb;*.txlog;CURRENT
OpenHandler_0=*.vcd;*.txdb;*.txlog;*.fbrdb
QuitHandler_0=Confirmation
QuitHandler_1=Do you want to exit?
RelationTypeToolControl_0=------------
@ -45,7 +45,7 @@ WaveformViewer_18=Would you like to reload the database?
WaveformViewer_19=vcd
WaveformViewer_20=txdb
WaveformViewer_21=txlog
WaveformViewer_22=txldb
WaveformViewer_22=fbrdb
WaveformViewer_37=Database open
WaveformViewer_38=Would you like to open the adjacent database
WaveformViewer_39=\ as well?

View File

@ -0,0 +1,482 @@
package com.minres.scviewer.e4.application.parts;
import java.io.File;
import java.nio.file.FileSystems;
import java.nio.file.PathMatcher;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TrayDialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
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.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.wb.swt.ResourceManager;
public class FileBrowserDialog extends TrayDialog {
private Image folderImage;
private Image fileImage;
private Image dbImage;
File currentDirFile;
TreeViewer dirTreeViewer;
TableViewer tableViewer;
Text fileNameEntry;
Combo filterCombo;
FileTableComparator fileTableComparator;
private FileGlobber globber = new FileGlobber();
private FileGlobber imageGlobber = new FileGlobber();
private File selectedDir;
private List<File> selectedFiles;
String[] filterStrings = new String[] {"*"};
public FileBrowserDialog(Shell parentShell) {
super(parentShell);
folderImage=ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/folder.png"); //$NON-NLS-1$ //$NON-NLS-2$
dbImage=ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/database.png"); //$NON-NLS-1$ //$NON-NLS-2$
fileImage=ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/page_white.png"); //$NON-NLS-1$ //$NON-NLS-2$
currentDirFile = new File(".");
}
public void setFilterExtensions(String[] filterStrings) {
if(filterStrings.length==0){
globber = new FileGlobber();
} else {
globber= new FileGlobber(filterStrings[0]);
imageGlobber = new FileGlobber(filterStrings[0]);
if(filterCombo!=null) {
filterCombo.setItems(filterStrings);
filterCombo.select(0);
filterCombo.computeSize(SWT.DEFAULT, SWT.DEFAULT);
}
}
this.filterStrings=filterStrings;
}
public List<File> getSelectedFiles(){
return selectedFiles;
}
@Override
protected Control createContents(Composite parent) {
Control ret = super.createContents(parent);
setDirSelection(currentDirFile.getAbsoluteFile().getParentFile());
getButton(IDialogConstants.OK_ID).setEnabled(!tableViewer.getSelection().isEmpty());
if(parent instanceof Shell) {
Point size = ((Shell)parent).computeSize(SWT.DEFAULT, SWT.DEFAULT);
((Shell)parent).setSize(size.x, 400);
((Shell)parent).setText("Select database");
}
return ret;
}
@Override
protected Control createDialogArea(Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
final SashForm sashForm = new SashForm(area, SWT.HORIZONTAL);
sashForm.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
dirTreeViewer = new TreeViewer(sashForm);
dirTreeViewer.setContentProvider(new FileTreeContentProvider());
dirTreeViewer.setLabelProvider(new FileTreeLabelProvider());
dirTreeViewer.addSelectionChangedListener(event -> {
IStructuredSelection sel = event.getStructuredSelection();
File entry = (File) sel.getFirstElement();
if(entry!=null && entry.isDirectory()) {
selectedDir = entry;
tableViewer.setInput(selectedDir.listFiles());
}
});
dirTreeViewer.setInput("root");
final Composite tableViewerParent = new Composite(sashForm, SWT.NONE);
GridLayout gridLayout = new GridLayout(1, true);
gridLayout.horizontalSpacing=0;
gridLayout.verticalSpacing=5;
gridLayout.marginHeight=0;
gridLayout.marginHeight=0;
tableViewerParent.setLayout(gridLayout);
final ToolBar toolBar = new ToolBar(tableViewerParent, SWT.HORIZONTAL |SWT.SHADOW_OUT);
toolBar.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
final ToolItem toolbarItemUp = new ToolItem(toolBar, SWT.PUSH);
toolbarItemUp.setToolTipText("up one level");
toolbarItemUp.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/arrow_up.png")); //$NON-NLS-1$ //$NON-NLS-2$);
toolbarItemUp.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if(selectedDir.getParentFile()!=null) {
selectedDir=selectedDir.getParentFile();
tableViewer.setInput(selectedDir.listFiles());
}
}
});
tableViewer = new TableViewer(tableViewerParent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI);
tableViewer.getTable().setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL));
tableViewer.addSelectionChangedListener(event -> {
IStructuredSelection sel = event.getStructuredSelection();
getButton(IDialogConstants.OK_ID).setEnabled(!sel.isEmpty());
@SuppressWarnings("unchecked")
Object text = sel.toList().stream().map(e -> ((File)e).getName()).collect(Collectors.joining(";"));
fileNameEntry.setText(text.toString());
});
tableViewer.addDoubleClickListener(event -> {
IStructuredSelection sel = tableViewer.getStructuredSelection();
if(sel.isEmpty()) return;
if(sel.size()==1) {
File elem = (File) sel.getFirstElement();
if(globber.matches(elem))
buttonPressed(IDialogConstants.OK_ID);
else if(elem.isDirectory())
setDirSelection(elem);
} else
buttonPressed(IDialogConstants.OK_ID);
});
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
tableViewer.getTable().setHeaderVisible(true);
tableViewer.getTable().setLinesVisible(true);
tableViewer.getTable().addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) { mouseUp(e); }
@Override
public void mouseUp(MouseEvent e) {
TableItem element = (TableItem)tableViewer.getTable().getItem(new Point(e.x, e.y));
final Table table = tableViewer.getTable();
if (element == null )//&& (e.stateMask&SWT.MODIFIER_MASK)!=0)
table.deselectAll();
else {
int[] indices = table.getSelectionIndices();
if(indices.length==1) {
TableItem ti = table.getItem(indices[0]);
if(!globber.matches(ti.getData()) && !((File)ti.getData()).isDirectory())
table.deselect(indices[0]);
} else {
for (int idx : indices) {
TableItem ti = table.getItem(idx);
if(!globber.matches(ti.getData()))
table.deselect(idx);
}
}
}
}
});
TableViewerColumn colName = new TableViewerColumn(tableViewer, SWT.NONE);
colName.setLabelProvider(new FileTableLabelProvider() {
@Override public String getText(Object element) { return ((File) element).getName(); }
@Override public Image getImage(Object element){
if(imageGlobber.matches(element)) return dbImage;
return ((File) element).isDirectory()?folderImage:fileImage;
}
});
colName.getColumn().setWidth(300);
colName.getColumn().setText("Name");
colName.getColumn().addSelectionListener(getSelectionAdapter(colName.getColumn(), 0));
TableViewerColumn colSize = new TableViewerColumn(tableViewer, SWT.RIGHT);
colSize.setLabelProvider(new FileTableLabelProvider() {
@Override public String getText(Object element) { return String.format("%d", ((File) element).length()); }
});
colSize.getColumn().setWidth(100);
colSize.getColumn().setText("Size");
colSize.getColumn().addSelectionListener(getSelectionAdapter(colSize.getColumn(), 1));
TableViewerColumn colEmpty = new TableViewerColumn(tableViewer, SWT.CENTER);
colEmpty.setLabelProvider(new FileTableLabelProvider() {
@Override public String getText(Object element) { return ""; }
});
//colEmpty.getColumn().setWidth(200);
colEmpty.getColumn().setText("");
fileTableComparator = new FileTableComparator();
tableViewer.setComparator(fileTableComparator);
tableViewer.addFilter(new FileTableFilter());
Composite bottomBar = new Composite(tableViewerParent, SWT.NONE);
bottomBar.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
GridLayout gridLayoutBottom = new GridLayout(2, false);
gridLayoutBottom.horizontalSpacing=0;
gridLayoutBottom.verticalSpacing=0;
gridLayoutBottom.marginHeight=0;
gridLayoutBottom.marginWidth=0;
bottomBar.setLayout(gridLayoutBottom);
fileNameEntry = new Text(bottomBar, SWT.BORDER);
fileNameEntry.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
fileNameEntry.setEditable(false); //TODO: temporary disabled
fileNameEntry.setEnabled(false);
filterCombo = new Combo(bottomBar, SWT.DROP_DOWN | SWT.BORDER | SWT.READ_ONLY);
filterCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
filterCombo.setItems(filterStrings);
filterCombo.select(0);
filterCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
globber= new FileGlobber(filterCombo.getText());
tableViewer.setInput(selectedDir.listFiles());
}
});
sashForm.setWeights(new int[]{3, 3});
return area;
}
private SelectionAdapter getSelectionAdapter(final TableColumn column, final int index) {
SelectionAdapter selectionAdapter = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
fileTableComparator.setColumn(index);
int dir = fileTableComparator.getDirection();
tableViewer.getTable().setSortDirection(dir);
tableViewer.getTable().setSortColumn(column);
tableViewer.refresh();
}
};
return selectionAdapter;
}
private void setDirSelection(File f) {
ArrayList<File> fileTree = getParentDirList(f);
TreeSelection selection = new TreeSelection(new TreePath(fileTree.toArray()));
dirTreeViewer.setSelection(selection, true);
}
private ArrayList<File> getParentDirList(File actual){
if(actual==null)
return new ArrayList<>();
else {
ArrayList<File> l = getParentDirList(actual.getParentFile());
l.add(actual);
return l;
}
}
@Override
protected boolean isResizable() {
return true;
}
// save content of the Text fields because they get disposed
// as soon as the Dialog closes
@SuppressWarnings("unchecked")
private void saveInput() {
selectedFiles= tableViewer.getStructuredSelection().toList();
}
@Override
protected void okPressed() {
saveInput();
super.okPressed();
}
class FileGlobber {
List<PathMatcher> matchers;
public FileGlobber() {
matchers = new ArrayList<>(); }
public FileGlobber(String expr) {
ArrayList<PathMatcher> m = new ArrayList<>();
if(expr.length()>0) {
String[] tok = expr.split(";");
for (String string : tok) {
m.add(FileSystems.getDefault().getPathMatcher("glob:**/"+string));
}
}
matchers = m;
}
public boolean matches(Object f) {
assert(f instanceof File);
if(matchers.size()==0) return true;
for (PathMatcher m : matchers) {
if(m.matches(((File)f).toPath())) return true;
}
return false;
}
}
class FileTreeContentProvider implements ITreeContentProvider {
public Object[] getChildren(Object arg0) {
File[] entries = ((File) arg0).listFiles();
if(entries != null) {
List<File> res = Arrays.stream(entries)
.filter(file -> !(file.isFile()||file.getName().startsWith(".") ||globber.matches(file)))
.sorted(new Comparator<File>(){
public int compare(File f1, File f2){return f1.getName().compareTo(f2.getName());}
})
.collect(Collectors.toList()); ;
return res.toArray();
} else
return new Object[0];
}
public Object getParent(Object arg0) {
return ((File) arg0).getParentFile();
}
public boolean hasChildren(Object arg0) {
Object[] obj = getChildren(arg0);
return obj == null ? false : obj.length > 0;
}
public Object[] getElements(Object arg0) {
return File.listRoots();
}
public void dispose() {
}
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
}
}
class FileTreeLabelProvider implements ILabelProvider {
private List<ILabelProviderListener> listeners;
private Image file;
private Image dir;
public FileTreeLabelProvider() {
listeners = new ArrayList<ILabelProviderListener>();
}
public Image getImage(Object arg0) {
return ((File) arg0).isDirectory() ? folderImage : file;
}
public String getText(Object arg0) {
File f = (File)arg0;
return f.getName().length() == 0? f.getPath() : f.getName();
}
public void addListener(ILabelProviderListener arg0) {
listeners.add(arg0);
}
public void dispose() {
// Dispose the images
if (dir != null)
dir.dispose();
if (file != null)
file.dispose();
}
public boolean isLabelProperty(Object arg0, String arg1) {
return false;
}
public void removeListener(ILabelProviderListener arg0) {
listeners.remove(arg0);
}
}
public class FileTableFilter extends ViewerFilter {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
File p = (File) element;
return !p.getName().startsWith(".");
}
}
public class FileTableComparator extends ViewerComparator {
private int propertyIndex = 0;
private boolean descending = false;
public FileTableComparator() {
}
public int getDirection() {
return descending ? SWT.DOWN : SWT.UP;
}
public void setColumn(int column) {
descending = column == this.propertyIndex?!descending : false;
this.propertyIndex = column;
}
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
File p1 = (File) e1;
File p2 = (File) e2;
int rc = 0;
switch (propertyIndex) {
case 0:
rc = p1.getName().compareTo(p2.getName());
break;
case 1:
rc = Long.valueOf(p1.length()).compareTo(p2.length());
break;
default:
rc = 0;
}
// If descending order, flip the direction
return descending? -rc : rc;
}
}
public class FileTableLabelProvider extends ColumnLabelProvider {
@Override
public Color getBackground(Object element) {
return null;
}
@Override
public Color getForeground(Object element) {
return globber.matches(element) || ((File)element).isDirectory()? null: ResourceManager.getColor(SWT.COLOR_GRAY);
}
}
}

View File

@ -669,7 +669,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
}
if (filesToLoad.size() > 0)
loadDatabase(persistedState);
if(partConfig instanceof String) {
if(partConfig instanceof String && ((String)partConfig).length()>0) {
loadState((String) partConfig);
}
}

View File

@ -10,7 +10,7 @@
<relativePath>../com.minres.scviewer.parent</relativePath>
</parent>
<artifactId>com.minres.scviewer.e4.product</artifactId>
<version>2.4.2-SNAPSHOT</version>
<version>2.5.0-SNAPSHOT</version>
<packaging>eclipse-repository</packaging>
<groupId>com.minres.scviewer</groupId>
<build>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?>
<product name="SCViewer" uid="scviewer" id="com.minres.scviewer.e4.application.product" application="org.eclipse.e4.ui.workbench.swt.E4Application" version="2.4.2.qualifier" useFeatures="false" includeLaunchers="true">
<product name="SCViewer" uid="scviewer" id="com.minres.scviewer.e4.application.product" application="org.eclipse.e4.ui.workbench.swt.E4Application" version="2.5.0.qualifier" useFeatures="false" includeLaunchers="true">
<configIni use="default">
</configIni>