From 6b4a9c1e1451dc4f9bc7fccc54bf8638f9759d4f Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Fri, 15 Mar 2019 07:31:13 +0000 Subject: [PATCH 1/2] Fixed handling of TransactionDetails view state --- .../application/parts/TransactionDetails.java | 77 ++++++++++++++++--- 1 file changed, 67 insertions(+), 10 deletions(-) diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java index 627593d..db0aa1e 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/TransactionDetails.java @@ -10,6 +10,7 @@ *******************************************************************************/ package com.minres.scviewer.e4.application.parts; +import java.util.ArrayList; import java.util.Vector; import javax.annotation.PostConstruct; @@ -37,8 +38,8 @@ import org.eclipse.jface.viewers.TreeExpansionEvent; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.TreeViewerColumn; import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ControlAdapter; import org.eclipse.swt.events.ControlEvent; @@ -55,10 +56,10 @@ import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; +import com.minres.scviewer.database.DataType; import com.minres.scviewer.database.ITx; import com.minres.scviewer.database.ITxAttribute; import com.minres.scviewer.database.ITxRelation; -import com.minres.scviewer.database.DataType; import com.minres.scviewer.e4.application.Messages; import com.minres.scviewer.e4.application.provider.TxPropertiesLabelProvider; @@ -203,7 +204,7 @@ public class TransactionDetails { Object[] selectedArray = (Object[]) selected; if(selectedArray.length==3 && selectedArray[2] instanceof ITx){ waveformViewerPart.setSelection(new StructuredSelection(selectedArray[2])); - treeViewer.setInput(selectedArray[2]); + setInput(selectedArray[2]); } } } @@ -265,19 +266,75 @@ public class TransactionDetails { public void setInput(Object object) { if(object instanceof ITx){ - TreeItem obj = treeViewer.getTree().getTopItem(); - Rectangle bounds = null; - if(obj!=null) bounds=obj.getBounds(); + ArrayList names = new ArrayList<>(); + int indexInParent=getTopItemHier(names); + ArrayList states = getExpandedState(treeViewer.getTree().getItems()); treeViewer.setInput(object); - if(bounds!=null) { - TreeItem ti = treeViewer.getTree().getItem (new Point(bounds.x, bounds.y)); - if(ti!=null) treeViewer.getTree().setTopItem(ti); - } + setExpandedState(treeViewer.getTree().getItems(), states); + setTopItemFromHier(names, indexInParent); } else { treeViewer.setInput(null); } } + + private void setExpandedState(TreeItem[] treeItems, ArrayList states) { + for (int i = 0; i < treeItems.length; i++) { + treeItems[i].setExpanded(states.size()>i?states.get(i):true); + } + } + + private ArrayList getExpandedState(TreeItem[] items){ + ArrayList ret = new ArrayList<>(); + for (TreeItem treeItem : items) + ret.add(treeItem.getItemCount()>0?treeItem.getExpanded():true); + return ret; + } + + private int getTopItemHier(ArrayList names){ + int indexInParent=-1; + TreeItem obj = treeViewer.getTree().getTopItem(); + if(obj!=null) { + names.add(0, obj.getText(0)); + if(obj.getParentItem()!=null) { + TreeItem pobj=obj.getParentItem(); + names.add(0, pobj.getText(0)); + TreeItem[] items = pobj.getItems(); + for (int i = 0; i < items.length; i++) { + if(items[i]==obj) { + indexInParent=i; + break; + } + } + } + } + return indexInParent; + } + + private void setTopItemFromHier(ArrayList names, int indexInParent) { + if(indexInParent<0 || names.size()==0 ) return; + TreeItem selItem=null; + for (TreeItem item : treeViewer.getTree().getItems()) { // find item from category + if(item.getText(0).equals(names.get(0))) { + if(names.size()>1) { // if we had an attribute as top item + TreeItem[] subItems=item.getItems(); + for(TreeItem it : subItems) { // try to align by name + if(it.getText(0).equals(names.get(1))) { + selItem=it; + break; + } + } + if(selItem==null && indexInParent>=0 && subItems.length>0) // name based match failed so try to use position + selItem=subItems[subItems.length>indexInParent?indexInParent:subItems.length-1]; + } + if(selItem==null) // no match in attributes so set the category as top item + selItem=item; + break; + } + } + if(selItem!=null) + treeViewer.getTree().setTopItem(selItem); + } /** * Sets the selection. * From 701733e69d05ade7b4efd64f1358b4f9313353c0 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Fri, 15 Mar 2019 08:50:12 +0100 Subject: [PATCH 2/2] Updated version numbers and display in about dialog --- com.minres.scviewer.e4.application/META-INF/MANIFEST.MF | 2 +- com.minres.scviewer.e4.application/pom.xml | 2 +- .../minres/scviewer/e4/application/messages.properties | 4 ++-- .../minres/scviewer/e4/application/parts/AboutDialog.java | 8 +++++++- com.minres.scviewer.e4.product/pom.xml | 2 +- com.minres.scviewer.e4.product/scviewer.product | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF b/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF index 0d9c4c9..0e1400a 100644 --- a/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF +++ b/com.minres.scviewer.e4.application/META-INF/MANIFEST.MF @@ -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.0.2.qualifier +Bundle-Version: 2.0.4.qualifier Bundle-Vendor: %Bundle-Vendor Require-Bundle: javax.inject;bundle-version="1.0.0", org.eclipse.core.runtime;bundle-version="3.11.1", diff --git a/com.minres.scviewer.e4.application/pom.xml b/com.minres.scviewer.e4.application/pom.xml index 58c79e5..cd58a3e 100644 --- a/com.minres.scviewer.e4.application/pom.xml +++ b/com.minres.scviewer.e4.application/pom.xml @@ -1,7 +1,7 @@ 4.0.0 com.minres.scviewer.e4.application - 2.0.2-SNAPSHOT + 2.0.4-SNAPSHOT com.minres.scviewer com.minres.scviewer.parent diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/messages.properties b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/messages.properties index 5485315..c5e0081 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/messages.properties +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/messages.properties @@ -1,5 +1,5 @@ -AboutDialog_0=\nSCViewer - a SystemC waveform viewer\n\nVersion: 2.0\n -AboutDialog_1=\nCopyright (c) 2015, 2018 MINRES Technologies GmbH and others.\n\nAll 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\nParts of the software are governed by the Apache License Version 2.0 available at http://www.apache.org/licenses/. These are namely org.mapdb and org.sqlite JDBC driver\n\nSource code is hosted at https://git.minres.com/VP/SCViewer and the master branch is mirrored to GitHub: https://git.com/minres/SCViewer\n +AboutDialog_0=\nSCViewer - a SystemC waveform viewer\n\nVersion: {0}\n +AboutDialog_1=\nCopyright (c) 2015, 2019 MINRES Technologies GmbH and others.\n\nAll 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\nParts of the software are governed by the Apache License Version 2.0 available at http://www.apache.org/licenses/. These are namely org.mapdb and org.sqlite JDBC driver\n\nSource code is hosted at https://git.minres.com/VP/SCViewer and the master branch is mirrored to GitHub: https://git.com/minres/SCViewer\n DesignBrowser_12=Append all after DesignBrowser_16=Insert all before DesignBrowser_2=Enter text to filter waveforms diff --git a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/AboutDialog.java b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/AboutDialog.java index 691e378..b832f0b 100644 --- a/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/AboutDialog.java +++ b/com.minres.scviewer.e4.application/src/com/minres/scviewer/e4/application/parts/AboutDialog.java @@ -19,8 +19,10 @@ import java.util.regex.Pattern; import javax.annotation.PostConstruct; import javax.inject.Inject; +import org.eclipse.core.runtime.Platform; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.custom.StyledText; @@ -39,6 +41,7 @@ import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.wb.swt.ResourceManager; import org.eclipse.wb.swt.SWTResourceManager; +import org.osgi.framework.Version; import com.minres.scviewer.e4.application.Messages; @@ -101,7 +104,10 @@ public class AboutDialog extends Dialog { styledText.setEditable(false); GridData gd_styledText = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); styledText.setLayoutData(gd_styledText); - styledText.setText(productTitle+copyrightText); + Version version = Platform.getProduct().getDefiningBundle().getVersion(); + String versionString = String.format("%d.%d.%d", version.getMajor(), version.getMinor(), version.getMicro()); + String pt = NLS.bind(Messages.AboutDialog_0, versionString); + styledText.setText(pt+copyrightText); styledText.setBackground(white); styledText.setWordWrap(true); styledText.setLeftMargin(5); diff --git a/com.minres.scviewer.e4.product/pom.xml b/com.minres.scviewer.e4.product/pom.xml index a3cc935..e196163 100644 --- a/com.minres.scviewer.e4.product/pom.xml +++ b/com.minres.scviewer.e4.product/pom.xml @@ -10,7 +10,7 @@ ../com.minres.scviewer.parent com.minres.scviewer.e4.product - 2.0.2-SNAPSHOT + 2.0.4-SNAPSHOT eclipse-repository com.minres.scviewer diff --git a/com.minres.scviewer.e4.product/scviewer.product b/com.minres.scviewer.e4.product/scviewer.product index fe82252..bd763f1 100644 --- a/com.minres.scviewer.e4.product/scviewer.product +++ b/com.minres.scviewer.e4.product/scviewer.product @@ -1,7 +1,7 @@ - +