]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/console/SCLConsole.java
Externalize strings in org.simantics.scl.ui
[simantics/platform.git] / bundles / org.simantics.scl.ui / src / org / simantics / scl / ui / console / SCLConsole.java
index 16a946fbebb86922ee99bd9ad481b5e547d37fd1..9df117f7e1288ef63869002bfde0952f8a42249e 100644 (file)
@@ -24,6 +24,8 @@ import org.simantics.scl.runtime.reporting.SCLReportingHandler;
 import org.simantics.scl.ui.Activator;
 import org.simantics.scl.ui.assist.SCLContentProposalProvider;
 import org.simantics.scl.ui.assist.StyledTextContentAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import gnu.trove.set.hash.THashSet;
 
@@ -33,7 +35,14 @@ import gnu.trove.set.hash.THashSet;
  * @author Hannu Niemistö
  */
 public class SCLConsole extends AbstractCommandConsole {
-       public static final String JOB_NAME = "org.simantics.scl.console.job";
+
+    /**
+     * Use this option mask to exclude {@link SCLConsoleListener}s contributed as
+     * OSGi services from listening to this console.
+     */
+    public static final int EXCLUDE_CONTRIBUTED_LISTENERS = 1 << 10;
+
+       public static final String JOB_NAME = "org.simantics.scl.console.job"; //$NON-NLS-1$
        public static final long TERMINATE_GRACE_PERIOD = 1000L;
        
        private THashSet<Job> currentJobs = new THashSet<Job>();
@@ -44,47 +53,56 @@ public class SCLConsole extends AbstractCommandConsole {
        SCLReportingHandler handler = new AbstractSCLReportingHandler() {
         @Override
         public void print(String text) {
-            appendOutput(text + "\n", null, null);
+            appendOutput(text + "\n", null, null); //$NON-NLS-1$
         }
         @Override
         public void printError(String error) {
-            appendOutput(error + "\n", redColor, null);
+            appendOutput(error + "\n", redColor, null); //$NON-NLS-1$
         }
         @Override
         public void printCommand(String command) {
-            appendOutput("> " + command.replace("\n", "\n  ") + "\n", greenColor, null);
+            appendOutput("> " + command.replace("\n", "\n  ") + "\n", greenColor, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
         }
     };
 
     CommandSession session = new CommandSession(SCLOsgi.MODULE_REPOSITORY, handler);
     ContentProposalAdapter contentProposalAdapter;
-    
+
     public SCLConsole(Composite parent, int style) {
-        super(parent, style);
-        
+        this(parent, style, 0);
+    }
+
+    public SCLConsole(Composite parent, int style, int options) {
+        super(parent, style, options);
+        createContentProposalAdapter();
+        if (!hasOption(EXCLUDE_CONTRIBUTED_LISTENERS))
+            addContributedListeners();
+    }
+
+    protected void createContentProposalAdapter() {
+        if (input == null)
+            return;
+
         StyledTextContentAdapter styledTextContentAdapter = new StyledTextContentAdapter();
         SCLContentProposalProvider contentProvider = new SCLContentProposalProvider(session);
-        
         try {
             contentProposalAdapter = new ContentProposalAdapter(
                     input, 
                     styledTextContentAdapter, 
                     contentProvider, 
-                    KeyStroke.getInstance("Ctrl+Space"), 
+                    KeyStroke.getInstance("Ctrl+Space"),  //$NON-NLS-1$
                     null);
             contentProposalAdapter.setAutoActivationDelay(200);
         } catch (ParseException e) {
             // No content assist then.
         }
-        
-        addContributedListeners();
     }
 
     @Override
     protected boolean canExecuteCommand() {
-        return !contentProposalAdapter.isProposalPopupOpen();
+        return contentProposalAdapter == null || !contentProposalAdapter.isProposalPopupOpen();
     }
-    
+
     @Override
     public ErrorAnnotation[] validate(String command) {
         if(command.isEmpty())
@@ -117,7 +135,7 @@ public class SCLConsole extends AbstractCommandConsole {
     }
     
     private String jobNameFromCommand(String command) {
-        return command.split("\n")[0];
+        return command.split("\n")[0]; //$NON-NLS-1$
     }
 
     @Override
@@ -216,7 +234,7 @@ public class SCLConsole extends AbstractCommandConsole {
         consoleIsEmpty = true;
     }
 
-    private void addContributedListeners() {
+    protected void addContributedListeners() {
         final BundleContext context = Activator.getInstance().getBundle().getBundleContext();
         new ServiceTracker<SCLConsoleListener, SCLConsoleListener>(context,
                 SCLConsoleListener.class, null) {
@@ -242,4 +260,10 @@ public class SCLConsole extends AbstractCommandConsole {
                     }
                 }.open();
     }
+
+    @Override
+    public Logger getLogger() {
+        return LoggerFactory.getLogger(getClass());
+    }
+
 }