X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.debug.ui%2Fsrc%2Forg%2Fsimantics%2Fdebug%2Fui%2FVariableDebugger.java;h=996efb19626617aed12596a868762fd1dca91690;hb=6384361f0f481de89b39ff542311807f72bcc019;hp=9c02bbe2a70806dfb8833e9b7a23a12310e7a015;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/VariableDebugger.java b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/VariableDebugger.java index 9c02bbe2a..996efb196 100644 --- a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/VariableDebugger.java +++ b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/VariableDebugger.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * Copyright (c) 2007, 2020 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -17,10 +17,10 @@ import java.io.IOException; import java.lang.reflect.Array; import java.net.URL; import java.nio.charset.Charset; -import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.TreeMap; +import java.util.TreeSet; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicReference; @@ -65,7 +65,6 @@ import org.simantics.db.Session; import org.simantics.db.common.ResourceArray; import org.simantics.db.common.procedure.adapter.DisposableListener; import org.simantics.db.common.request.UnaryRead; -import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.SelectionHints; import org.simantics.db.layer0.request.PossibleURI; @@ -90,6 +89,8 @@ import org.simantics.utils.bytes.Base64; import org.simantics.utils.ui.ErrorLogger; import org.simantics.utils.ui.ISelectionUtils; import org.simantics.utils.ui.PathUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** @@ -98,16 +99,18 @@ import org.simantics.utils.ui.PathUtils; */ public class VariableDebugger extends Composite { + private static final Logger LOGGER = LoggerFactory.getLogger(VariableDebugger.class); + public interface HistoryListener { void historyChanged(); } - private final static String DEFAULT_DEBUGGER_CSS_FILE = "debugger.css"; - private final static String DEFAULT_DEBUGGER_CSS_PATH = "css/" + DEFAULT_DEBUGGER_CSS_FILE; + private final static String DEFAULT_DEBUGGER_CSS_FILE = "debugger.css"; //$NON-NLS-1$ + private final static String DEFAULT_DEBUGGER_CSS_PATH = "css/" + DEFAULT_DEBUGGER_CSS_FILE; //$NON-NLS-1$ private static int RESOURCE_NAME_MAX_LENGTH = 1000; - private final Charset utf8 = Charset.forName("UTF-8"); + private final Charset utf8 = Charset.forName("UTF-8"); //$NON-NLS-1$ private final LocalResourceManager resourceManager; @@ -157,7 +160,7 @@ public class VariableDebugger extends Composite { if (!browser.isDisposed()) browser.setText(content); if (!updateTriggerCounter.isDisposed()) - updateTriggerCounter.setText(updateCount + "/" + triggerCounter); + updateTriggerCounter.setText(updateCount + "/" + triggerCounter); //$NON-NLS-1$ } }); } @@ -166,7 +169,7 @@ public class VariableDebugger extends Composite { @Override public void exception(Throwable t) { - Logger.defaultLogError(t); + LOGGER.error("Page content listener failed unexpectedly", t); } } @@ -181,7 +184,7 @@ public class VariableDebugger extends Composite { */ public VariableDebugger(Composite parent, int style, final Session session, String initialURI) { super(parent, style); - Assert.isNotNull(session, "session is null"); + Assert.isNotNull(session, "session is null"); //$NON-NLS-1$ this.session = session; this.currentElement = initialURI; this.resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent); @@ -222,7 +225,7 @@ public class VariableDebugger extends Composite { if (!css.exists()) { URL url = FileLocator.find(Activator.getDefault().getBundle(), new Path(DEFAULT_DEBUGGER_CSS_PATH), null); if (url == null) - throw new FileNotFoundException("Could not find '" + DEFAULT_DEBUGGER_CSS_PATH + "' in bundle '" + Activator.PLUGIN_ID + "'"); + throw new FileNotFoundException("Could not find '" + DEFAULT_DEBUGGER_CSS_PATH + "' in bundle '" + Activator.PLUGIN_ID + "'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ cssPath = FileUtils.copyResource(url, css, true).toURI().toString(); } else { cssPath = css.toURI().toString(); @@ -238,7 +241,7 @@ public class VariableDebugger extends Composite { public Label createDropLabel(Composite parent) { final Label label = new Label(parent, SWT.BORDER | SWT.FLAT); label.setAlignment(SWT.CENTER); - label.setText(" Drag a resource or a variable here to examine it in this debugger! "); + label.setText(Messages.VariableDebugger_DragResourceToDebugger); label.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY)); GridData data = new GridData(SWT.LEFT, SWT.FILL, false, false); label.setLayoutData(data); @@ -261,15 +264,16 @@ public class VariableDebugger extends Composite { @Override public void drop(DropTargetEvent event) { label.setBackground(null); + String uri = null; try { - String uri = parseUri(event); + uri = parseUri(event); if (uri == null) { event.detail = DND.DROP_NONE; return; } changeLocation(uri); } catch (DatabaseException e) { - Logger.defaultLogError(e); + LOGGER.error("Changing location to URI {} failed", uri, e); } } @@ -316,7 +320,7 @@ public class VariableDebugger extends Composite { text.setLayoutData(data); Button button = new Button(parent, SWT.NONE); - button.setText("Lookup"); + button.setText(Messages.VariableDebugger_Lookup); GridData data2 = new GridData(SWT.FILL, SWT.FILL, false, false); button.setLayoutData(data2); @@ -330,13 +334,14 @@ public class VariableDebugger extends Composite { @Override public void widgetSelected(SelectionEvent e) { + String uri = null; try { - String uri = text.getText(); + uri = text.getText(); // Make sure that URI is resolvable to Variable session.sync(new ResourceURIToVariable(uri)); changeLocation(uri); } catch (DatabaseException e1) { - Logger.defaultLogError(e1); + LOGGER.error("Lookup failed for URI {}", uri, e1); } } @@ -347,7 +352,7 @@ public class VariableDebugger extends Composite { protected Text createUpdateTriggerCounter(Composite parent) { Text label = new Text(parent, SWT.BORDER | SWT.FLAT); label.setEditable(false); - label.setToolTipText("Amount of Screen/Listener Updates Received for Shown Variable"); + label.setToolTipText(Messages.VariableDebugger_TextToolTip); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL) .grab(false, false).hint(32, SWT.DEFAULT).applyTo(label); updateTriggerCounter = label; @@ -356,7 +361,7 @@ public class VariableDebugger extends Composite { public Browser createBrowser(Composite parent) { try { - browser = new Browser(parent, SWT.MOZILLA); + browser = new Browser(parent, SWT.NONE); } catch (SWTError e) { //System.out.println("Could not instantiate Browser: " + e.getMessage()); browser = new Browser(parent, SWT.NONE); @@ -385,21 +390,21 @@ public class VariableDebugger extends Composite { @Override public void changing(LocationEvent event) { String location = event.location; - if (location.startsWith("simantics:browser")) - location = "about:" + location.substring(17); + if (location.startsWith("simantics:browser")) //$NON-NLS-1$ + location = "about:" + location.substring(17); //$NON-NLS-1$ //System.out.println("changing: location=" + location); // Do not follow links that are meant as actions that are // handled below. event.doit = false; - if ("about:blank".equals(location)) { + if ("about:blank".equals(location)) { //$NON-NLS-1$ // Just changing to the same old blank url is ok since it // allows the browser to refresh itself. event.doit = true; } - if (location.startsWith("about:-link")) { - String target = location.replace("about:-link", ""); + if (location.startsWith("about:-link")) { //$NON-NLS-1$ + String target = location.replace("about:-link", ""); //$NON-NLS-1$ //$NON-NLS-2$ try { byte[] bytes = Base64.decode(target); String url = new String(bytes, utf8); @@ -411,8 +416,8 @@ public class VariableDebugger extends Composite { } catch (IOException e) { ErrorLogger.defaultLogError(e); } - } else if (location.startsWith("about:-remove")) { - } else if (location.startsWith("about:-edit-value")) { + } else if (location.startsWith("about:-remove")) { //$NON-NLS-1$ + } else if (location.startsWith("about:-edit-value")) { //$NON-NLS-1$ } } }); @@ -508,43 +513,43 @@ public class VariableDebugger extends Composite { if (o instanceof byte[]) { byte[] arr = (byte[]) o; byte[] arr2 = Arrays.copyOf(arr, RESOURCE_NAME_MAX_LENGTH); - return truncated("byte", Arrays.toString(arr2), arr.length); + return truncated("byte", Arrays.toString(arr2), arr.length); //$NON-NLS-1$ } else if (o instanceof int[]) { int[] arr = (int[]) o; int[] arr2 = Arrays.copyOf(arr, RESOURCE_NAME_MAX_LENGTH); - return truncated("int", Arrays.toString(arr2), arr.length); + return truncated("int", Arrays.toString(arr2), arr.length); //$NON-NLS-1$ } else if (o instanceof long[]) { long[] arr = (long[]) o; long[] arr2 = Arrays.copyOf(arr, RESOURCE_NAME_MAX_LENGTH); - return truncated("long", Arrays.toString(arr2), arr.length); + return truncated("long", Arrays.toString(arr2), arr.length); //$NON-NLS-1$ } else if (o instanceof float[]) { float[] arr = (float[]) o; float[] arr2 = Arrays.copyOf(arr, RESOURCE_NAME_MAX_LENGTH); - return truncated("float", Arrays.toString(arr2), arr.length); + return truncated("float", Arrays.toString(arr2), arr.length); //$NON-NLS-1$ } else if (o instanceof double[]) { double[] arr = (double[]) o; double[] arr2 = Arrays.copyOf(arr, RESOURCE_NAME_MAX_LENGTH); - return truncated("double", Arrays.toString(arr2), arr.length); + return truncated("double", Arrays.toString(arr2), arr.length); //$NON-NLS-1$ } else if (o instanceof boolean[]) { boolean[] arr = (boolean[]) o; boolean[] arr2 = Arrays.copyOf(arr, RESOURCE_NAME_MAX_LENGTH); - return truncated("boolean", Arrays.toString(arr2), arr.length); + return truncated("boolean", Arrays.toString(arr2), arr.length); //$NON-NLS-1$ } else if (o instanceof Object[]) { Object[] arr = (Object[]) o; Object[] arr2 = Arrays.copyOf(arr, RESOURCE_NAME_MAX_LENGTH); - return truncated("Object", Arrays.toString(arr2), arr.length); + return truncated("Object", Arrays.toString(arr2), arr.length); //$NON-NLS-1$ } else { - return "Unknown big array " + o.getClass(); + return "Unknown big array " + o.getClass(); //$NON-NLS-1$ } } else { - return o.getClass().getComponentType() + "[" + length + "] = " + ObjectUtils.toString(o); + return o.getClass().getComponentType() + "[" + length + "] = " + ObjectUtils.toString(o); //$NON-NLS-1$ //$NON-NLS-2$ } } return null; } protected String truncated(String type, String string, int originalLength) { - return type + "[" + RESOURCE_NAME_MAX_LENGTH + "/" + originalLength + "] = " + string; + return type + "[" + RESOURCE_NAME_MAX_LENGTH + "/" + originalLength + "] = " + string; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } protected String getVariableName(ReadGraph graph, Variable r) { @@ -559,11 +564,11 @@ public class VariableDebugger extends Composite { Class clazz = o.getClass(); if(o instanceof Connection) { Connection c = (Connection)o; - ArrayList result = new ArrayList(); + TreeSet rvis = new TreeSet<>(); for(VariableConnectionPointDescriptor v : c.getConnectionPointDescriptors(graph, null)) { - result.add(v.getRelativeRVI(graph, base)); + rvis.add(v.getRelativeRVI(graph, base)); } - return "c " + result.toString(); + return "c " + rvis.toString(); //$NON-NLS-1$ } else if (clazz.isArray()) { if(int[].class == clazz) { return Arrays.toString((int[])o); @@ -591,12 +596,12 @@ public class VariableDebugger extends Composite { Object value = r.getValue(graph); if(value instanceof Resource) return getResourceRef(graph, (Resource)value); else if (value instanceof Variable) return getVariableRef(graph, (Variable)value); - else return value != null ? getValue(graph, r, value) : "null"; + else return value != null ? getValue(graph, r, value) : "null"; //$NON-NLS-1$ } catch (Throwable e) { try { - Logger.defaultLogError("getValue " + r.getURI(graph), e); + LOGGER.error("getValue({})", r.getURI(graph), e); //$NON-NLS-1$ } catch (DatabaseException e1) { - Logger.defaultLogError(e1); + LOGGER.error("Failed to get URI for problematic value variable", e1); } return e.getMessage(); } @@ -605,7 +610,7 @@ public class VariableDebugger extends Composite { protected String getDatatype(ReadGraph graph, Variable r) { try { Datatype dt = r.getPossibleDatatype(graph); - return dt != null ? dt.toSingleLineString() : "undefined"; + return dt != null ? dt.toSingleLineString() : "undefined"; //$NON-NLS-1$ } catch (Exception e) { return e.getMessage(); } @@ -616,9 +621,9 @@ public class VariableDebugger extends Composite { } private String getVariableRef(ReadGraph graph, Variable r) throws DatabaseException { - String ret = "" + String ret = "" //$NON-NLS-1$ //$NON-NLS-2$ + getVariableName(graph, r) - + ""; + + ""; //$NON-NLS-1$ // if (graph.isInstanceOf(r, L0.Literal)) { // ret += " " // + "(edit value)" @@ -634,7 +639,7 @@ public class VariableDebugger extends Composite { String encoded = Base64.encode(uri.getBytes(utf8)); return encoded; } catch (Exception e) { - Logger.defaultLogError(e); + LOGGER.error("Failed to construct link string for variable", e); //$NON-NLS-1$ return e.getMessage(); } } @@ -645,11 +650,11 @@ public class VariableDebugger extends Composite { // } catch (Exception e) { // e.printStackTrace(); // } - content.append(""); - content.append("").append(getVariableRef(graph, property)).append(""); - content.append("").append(getValue(graph, property)).append(""); - content.append("").append(getDatatype(graph, property)).append(""); - content.append(""); + content.append(""); //$NON-NLS-1$ + content.append("").append(getVariableRef(graph, property)).append(""); //$NON-NLS-1$ //$NON-NLS-2$ + content.append("").append(getValue(graph, property)).append(""); //$NON-NLS-1$ //$NON-NLS-2$ + content.append("").append(getDatatype(graph, property)).append(""); //$NON-NLS-1$ //$NON-NLS-2$ + content.append(""); //$NON-NLS-1$ } protected String getRVIString(ReadGraph graph, Variable var) throws DatabaseException { @@ -657,7 +662,7 @@ public class VariableDebugger extends Composite { try { return var.getRVI(graph).toString(graph); } catch (Throwable e) { - return "No RVI"; + return "No RVI"; //$NON-NLS-1$ } } @@ -669,9 +674,9 @@ public class VariableDebugger extends Composite { StringBuilder content = new StringBuilder(); // Generate HTML -page - content.append("").append(getHead()).append("\n"); - content.append("\n"); - content.append("
\n"); + content.append("").append(getHead()).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ + content.append("\n"); //$NON-NLS-1$ + content.append("
\n"); //$NON-NLS-1$ for (String uri : uris) { //System.out.println("URI: " + uri); Variable var = Variables.getPossibleVariable(graph, uri); @@ -681,23 +686,23 @@ public class VariableDebugger extends Composite { String rviString = getRVIString(graph, var); Object node = null; if(var instanceof AbstractChildVariable) { - VariableNode vn = ((AbstractChildVariable)var).node; + VariableNode vn = ((AbstractChildVariable)var).node; if(vn != null) node = vn.node; } if(var instanceof AbstractPropertyVariable) { - VariableNode vn = ((AbstractPropertyVariable)var).node; + VariableNode vn = ((AbstractPropertyVariable)var).node; if(vn != null) node = vn.node; } // Begin #top DIV - content.append("
\n"); - content.append("\n"); - content.append("\n"); - content.append("\n"); - content.append("\n"); - content.append("\n"); - content.append("
URI").append(uri).append("
RVI").append(rviString).append("
Class").append(var.getClass().getCanonicalName()).append("
Solver node").append(node).append("
\n"); - content.append("
\n"); + content.append("
\n"); //$NON-NLS-1$ + content.append("\n"); //$NON-NLS-1$ + content.append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ + content.append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ + content.append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ + content.append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ + content.append("
URI").append(uri).append("
RVI").append(rviString).append("
Class").append(var.getClass().getCanonicalName()).append("
Solver node").append(node).append("
\n"); //$NON-NLS-1$ + content.append("
\n"); //$NON-NLS-1$ // Close #top DIV // Content @@ -709,7 +714,7 @@ public class VariableDebugger extends Composite { } } catch (DatabaseException e) { // This may happen if the Variable implementation is broken - ErrorLogger.defaultLogError("Broken variable child retrieval implementation or serious modelling error encountered. See exception for details.", e); + ErrorLogger.defaultLogError("Broken variable child retrieval implementation or serious modelling error encountered. See exception for details.", e); //$NON-NLS-1$ } TreeMap map2 = new TreeMap(); @@ -720,37 +725,37 @@ public class VariableDebugger extends Composite { } } catch (DatabaseException e) { // This may happen if the Variable implementation is broken - ErrorLogger.defaultLogError("Broken variable property retrieval implementation or serious modelling error encountered. See exception for details.", e); + ErrorLogger.defaultLogError("Broken variable property retrieval implementation or serious modelling error encountered. See exception for details.", e); //$NON-NLS-1$ } - content.append("\n
\n"); - content.append("\n"); + content.append("\n
\n"); //$NON-NLS-1$ + content.append("
\n"); //$NON-NLS-1$ - content.append(""); + content.append(""); //$NON-NLS-1$ for (Variable child : map.values()) { - content.append(""); + content.append(""); //$NON-NLS-1$ //$NON-NLS-2$ } - content.append(""); + content.append(""); //$NON-NLS-1$ for (Variable property : map2.values()) { updateProperty(content, graph, property); } // Close #data - content.append("\n\n"); + content.append("\n\n"); //$NON-NLS-1$ } // Close #mainContent - content.append("\n"); - content.append("\n"); + content.append("\n"); //$NON-NLS-1$ + content.append("\n"); //$NON-NLS-1$ // Update content return content.toString(); } private String getHead() { - String result = ""; + String result = ""; //$NON-NLS-1$ if (cssPath != null) { - result = ""; + result = ""; //$NON-NLS-1$ //$NON-NLS-2$ } return result; }
Child
Child
").append(getVariableRef(graph, child)).append("
").append(getVariableRef(graph, child)).append("
PropertyValueDatatype
PropertyValueDatatype