X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.document.ui%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fui%2Ffunction%2FAll.java;h=a500aa12c93a040fb867ab74fab7bd9677ddb395;hb=5e340942bc7de041b75c6ba281617eb0c800f30a;hp=76b5abe95c48559e3a384506b4ad5e3b2582e2a6;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.document.ui/src/org/simantics/document/ui/function/All.java b/bundles/org.simantics.document.ui/src/org/simantics/document/ui/function/All.java index 76b5abe95..a500aa12c 100644 --- a/bundles/org.simantics.document.ui/src/org/simantics/document/ui/function/All.java +++ b/bundles/org.simantics.document.ui/src/org/simantics/document/ui/function/All.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Association for Decentralized Information Management in + * Copyright (c) 2012, 2017 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 @@ -8,6 +8,7 @@ * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation + * Semantum Oy - (#7066) introducing logger & refactoring *******************************************************************************/ package org.simantics.document.ui.function; @@ -38,7 +39,6 @@ import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.request.UnaryRead; import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.common.utils.Logger; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.common.utils.RequestUtil; import org.simantics.db.exception.DatabaseException; @@ -68,10 +68,14 @@ import org.simantics.ui.workbench.ResourceEditorInput2; import org.simantics.ui.workbench.action.DefaultActions; import org.simantics.utils.threads.SWTThread; import org.simantics.utils.ui.workbench.WorkbenchUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class All { + private static final Logger LOGGER = LoggerFactory.getLogger(All.class); + private static boolean createDocument(WriteGraph graph, Resource resource, Resource model) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); @@ -97,13 +101,13 @@ public class All { Resource documentType = graph.getSingleObject(binding, DOC.DocumentTypeBinding_HasDocumentType); Resource document = graph.newResource(); graph.claim(document, L0.InstanceOf, null, DOC.ScenegraphDocument); - graph.claimLiteral(document, L0.HasName, "Documentation"); + graph.claimLiteral(document, L0.HasName, "Documentation"); //$NON-NLS-1$ graph.claim(resource, DOC.HasDocumentation, document); graph.claim(document, L0.PartOf, resource); Resource scenegraph = graph.newResource(); graph.claim(scenegraph, L0.InstanceOf, null, documentType); - graph.claimLiteral(scenegraph, L0.HasName, "Scenegraph"); + graph.claimLiteral(scenegraph, L0.HasName, "Scenegraph"); //$NON-NLS-1$ graph.claim(scenegraph, L0.PartOf, document); graph.claim(document, DOC.ScenegraphDocument_scenegraph, scenegraph); @@ -187,6 +191,7 @@ public class All { if(document == null) return; RemoverUtil.remove(graph, document); + graph.markUndoPoint(); } @@ -281,7 +286,7 @@ public class All { Variable result = ScenegraphLoaderProcess.getVariable(graph, null, scenegraph, ScenegraphLoaderUtils.getRuntime(graph, context), root); if(result != null) { - Variable userDoc = result.getPossibleProperty(graph, "UserDocumentation"); + Variable userDoc = result.getPossibleProperty(graph, "UserDocumentation"); //$NON-NLS-1$ if(userDoc != null) return userDoc; } @@ -304,7 +309,7 @@ public class All { @SCLValue(type = "ReadGraph -> Resource -> Variable -> a") public static Object wikitextModifier(ReadGraph graph, final Resource resource, final Variable context) throws DatabaseException { - final ScenegraphPropertyReference textReference = ScenegraphLoaderUtils.getRelativePropertyReference(SWTThread.getThreadAccess(), graph, context, ".../TextContainer/Text#text"); + final ScenegraphPropertyReference textReference = ScenegraphLoaderUtils.getRelativePropertyReference(SWTThread.getThreadAccess(), graph, context, ".../TextContainer/Text#text"); //$NON-NLS-1$ return new FunctionImpl1() { @@ -318,12 +323,12 @@ public class All { @Override public void perform(WriteGraph graph) throws DatabaseException { - - Variable selection = resolveEditSelection(graph, context, "..../Scroll/Browser#edited"); - if (selection != null) + Variable selection = resolveEditSelection(graph, context, "..../Scroll/Browser#edited"); //$NON-NLS-1$ + if (selection != null) { selection.setValue(graph, (String)value, Bindings.STRING); - else { - System.err.println("no selection for resource : " + resource + ", Variable context : " + context + ", value : " + value); + graph.markUndoPoint(); + } else { + LOGGER.error("No selection for resource : " + resource + ", Variable context : " + context + ", value : " + value); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } @@ -346,7 +351,7 @@ public class All { @SCLValue(type = "ReadGraph -> Resource -> Variable -> String") public static String selectedDocumentPart(ReadGraph graph, Resource resource, Variable context) throws DatabaseException { - Variable selection = resolveEditSelection(graph, context, ".../Scroll/Browser#edited"); + Variable selection = resolveEditSelection(graph, context, ".../Scroll/Browser#edited"); //$NON-NLS-1$ if(selection == null) return null; return selection.getValue(graph); @@ -384,8 +389,8 @@ public class All { final ScenegraphPropertyReference selectionReference; public WikiButtonModifier(ReadGraph graph, Variable context) throws DatabaseException { - textReference = ScenegraphLoaderUtils.getRelativePropertyReference(SWTThread.getThreadAccess(), graph, context, ".../TextContainer/Text#text"); - selectionReference = ScenegraphLoaderUtils.getRelativePropertyReference(SWTThread.getThreadAccess(), graph, context, ".../TextContainer/Text#selection"); + textReference = ScenegraphLoaderUtils.getRelativePropertyReference(SWTThread.getThreadAccess(), graph, context, ".../TextContainer/Text#text"); //$NON-NLS-1$ + selectionReference = ScenegraphLoaderUtils.getRelativePropertyReference(SWTThread.getThreadAccess(), graph, context, ".../TextContainer/Text#selection"); //$NON-NLS-1$ } abstract void perform(String before, String selected, String after, Point selection); @@ -412,9 +417,9 @@ public class All { void perform(String before, String selected, String after, Point selection) { if(selected.isEmpty()) { - textReference.setValue(before + "'''bold text'''" + after); + textReference.setValue(before + "'''bold text'''" + after); //$NON-NLS-1$ } else { - textReference.setValue(before + "'''" + selected + "'''" + after); + textReference.setValue(before + "'''" + selected + "'''" + after); //$NON-NLS-1$ //$NON-NLS-2$ } } @@ -432,9 +437,9 @@ public class All { void perform(String before, String selected, String after, Point selection) { if(selected.isEmpty()) { - textReference.setValue(before + "''italic text''" + after); + textReference.setValue(before + "''italic text''" + after); //$NON-NLS-1$ } else { - textReference.setValue(before + "''" + selected + "''" + after); + textReference.setValue(before + "''" + selected + "''" + after); //$NON-NLS-1$ //$NON-NLS-2$ } } @@ -452,9 +457,9 @@ public class All { void perform(String before, String selected, String after, Point selection) { if(selected.isEmpty()) { - textReference.setValue(before + "strikethrough text" + after); + textReference.setValue(before + "strikethrough text" + after); //$NON-NLS-1$ } else { - textReference.setValue(before + "" + selected + "" + after); + textReference.setValue(before + "" + selected + "" + after); //$NON-NLS-1$ //$NON-NLS-2$ } } @@ -472,9 +477,9 @@ public class All { void perform(String before, String selected, String after, Point selection) { if(selected.isEmpty()) { - textReference.setValue(before + "strikethrough text" + after); + textReference.setValue(before + "strikethrough text" + after); //$NON-NLS-1$ } else { - textReference.setValue(before + "" + selected + "" + after); + textReference.setValue(before + "" + selected + "" + after); //$NON-NLS-1$ //$NON-NLS-2$ } } @@ -491,7 +496,7 @@ public class All { @Override void perform(String before, String selected, String after, Point selection) { - textReference.setValue(before + "\r\n
\r\n" + selected + after); + textReference.setValue(before + "\r\n
\r\n" + selected + after); //$NON-NLS-1$ } @@ -507,7 +512,7 @@ public class All { @Override void perform(String before, String selected, String after, Point selection) { - textReference.setValue(before + ":" + selected + after); + textReference.setValue(before + ":" + selected + after); //$NON-NLS-1$ } @@ -522,7 +527,7 @@ public class All { private String hex2(int value) { String result = Integer.toHexString(value); - if(result.length() == 1) result = "0" + result; + if(result.length() == 1) result = "0" + result; //$NON-NLS-1$ return result; } @@ -540,9 +545,9 @@ public class All { String hex = hex2(rgb.red) + hex2(rgb.green) + hex2(rgb.blue); if(selected.isEmpty()) { - textReference.setValue(before + "formatted text" + selected + after); + textReference.setValue(before + "formatted text" + selected + after); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } else { - textReference.setValue(before + "" + selected + "" + after); + textReference.setValue(before + "" + selected + "" + after); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ } } @@ -559,7 +564,7 @@ public class All { @Override void perform(String before, String selected, String after, Point selection) { - textReference.setValue(before + "[[Image:root://Library/image.png|100px]]" + "\r\n" + selected + after); + textReference.setValue(before + "[[Image:root://Library/image.png|100px]]" + "\r\n" + selected + after); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -575,7 +580,7 @@ public class All { @Override void perform(String before, String selected, String after, Point selection) { - textReference.setValue(before + "\r\n= Header 1 =\r\n" + selected + after); + textReference.setValue(before + "\r\n= Header 1 =\r\n" + selected + after); //$NON-NLS-1$ } @@ -591,7 +596,7 @@ public class All { @Override void perform(String before, String selected, String after, Point selection) { - textReference.setValue(before + "\r\n== Header 2 ==\r\n" + selected + after); + textReference.setValue(before + "\r\n== Header 2 ==\r\n" + selected + after); //$NON-NLS-1$ } @@ -607,7 +612,7 @@ public class All { @Override void perform(String before, String selected, String after, Point selection) { - textReference.setValue(before + "\r\n=== Header 3 ===\r\n" + selected + after); + textReference.setValue(before + "\r\n=== Header 3 ===\r\n" + selected + after); //$NON-NLS-1$ } @@ -623,7 +628,7 @@ public class All { @Override void perform(String before, String selected, String after, Point selection) { - textReference.setValue(before + "\r\n==== Header 4 ====\r\n" + selected + after); + textReference.setValue(before + "\r\n==== Header 4 ====\r\n" + selected + after); //$NON-NLS-1$ } @@ -639,11 +644,11 @@ public class All { @Override void perform(String before, String selected, String after, Point selection) { - textReference.setValue(before + "\r\n" + - "# Item1\r\n" + - "# Item2\r\n" + - "## Item2.1\r\n" + - "# Item3\r\n" + selected + after); + textReference.setValue(before + "\r\n" + //$NON-NLS-1$ + "# Item1\r\n" + //$NON-NLS-1$ + "# Item2\r\n" + //$NON-NLS-1$ + "## Item2.1\r\n" + //$NON-NLS-1$ + "# Item3\r\n" + selected + after); //$NON-NLS-1$ } @@ -659,11 +664,11 @@ public class All { @Override void perform(String before, String selected, String after, Point selection) { - textReference.setValue(before + "\r\n" + - "* Item1\r\n" + - "* Item2\r\n" + - "** Item2.1\r\n" + - "* Item3\r\n" + selected + after); + textReference.setValue(before + "\r\n" + //$NON-NLS-1$ + "* Item1\r\n" + //$NON-NLS-1$ + "* Item2\r\n" + //$NON-NLS-1$ + "** Item2.1\r\n" + //$NON-NLS-1$ + "* Item3\r\n" + selected + after); //$NON-NLS-1$ } @@ -679,16 +684,16 @@ public class All { @Override void perform(String before, String selected, String after, Point selection) { - textReference.setValue(before + "\r\n" + - "{| border=\"1\"\r\n" + - "! header\r\n" + - "! header2 \r\n" + - "|-\r\n" + - "| cell || cell2\r\n" + - "|-\r\n" + - "| cell3\r\n" + - "| cell4\r\n" + - "|}\r\n" + selected + after); + textReference.setValue(before + "\r\n" + //$NON-NLS-1$ + "{| border=\"1\"\r\n" + //$NON-NLS-1$ + "! header\r\n" + //$NON-NLS-1$ + "! header2 \r\n" + //$NON-NLS-1$ + "|-\r\n" + //$NON-NLS-1$ + "| cell || cell2\r\n" + //$NON-NLS-1$ + "|-\r\n" + //$NON-NLS-1$ + "| cell3\r\n" + //$NON-NLS-1$ + "| cell4\r\n" + //$NON-NLS-1$ + "|}\r\n" + selected + after); //$NON-NLS-1$ } @@ -702,7 +707,7 @@ public class All { @Override void perform(String before, String selected, String after, Point selection) { textReference.setValue(before + - "[[Media:root://Documents/Document.pdf|Link to a file within the model]]\r\n" + selected + after); + "[[Media:root://Documents/Document.pdf|Link to a file within the model]]\r\n" + selected + after); //$NON-NLS-1$ } }; @@ -717,7 +722,7 @@ public class All { void perform(String before, String selected, String after, Point selection) { textReference.setValue(before + - "[http://www.simantics.org External Website Link]\r\n" + selected + after); + "[http://www.simantics.org External Website Link]\r\n" + selected + after); //$NON-NLS-1$ } @@ -743,19 +748,12 @@ public class All { String editorId = CSSEditor.EDITOR_ID; RVI rvi = null; - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - - @Override - public void run() { - - try { - WorkbenchUtils.openEditor(editorId, new ResourceEditorInput2(editorId, root, root, rvi)); - } catch (PartInitException e) { - Logger.defaultLogError(e); - } - + PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { + try { + WorkbenchUtils.openEditor(editorId, new ResourceEditorInput2(editorId, root, root, rvi)); + } catch (PartInitException e) { + LOGGER.error("Failed to open CSS editor for root " + root, e); //$NON-NLS-1$ } - }); } @@ -814,17 +812,17 @@ public class All { public static String noDocumentText(ReadGraph graph, final Resource resource, final Variable context) throws DatabaseException { Variable selection = ScenegraphLoaderUtils.getPossibleVariableSelection(graph, context); - if(selection == null) return ""; + if(selection == null) return ""; //$NON-NLS-1$ Resource input = selection.getRepresents(graph); - if(input == null) return ""; + if(input == null) return ""; //$NON-NLS-1$ String path = DocumentUtils.indexRootPath(graph, selection); if(!path.isEmpty()) { - return "for " + path + selection.getName(graph); + return "for " + path + selection.getName(graph); //$NON-NLS-1$ } - return "for " + NameUtils.getSafeLabel(graph, input); + return "for " + NameUtils.getSafeLabel(graph, input); //$NON-NLS-1$ } @@ -875,7 +873,7 @@ public class All { DefaultActions.asyncPerformDefaultAction(s, input, false, false, false); } } catch (DatabaseException | InterruptedException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to resolve URI to a database resource or variable: " + uri, e)); + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to resolve URI to a database resource or variable: " + uri, e)); //$NON-NLS-1$ } } return true;