]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/console/SCLConsole.java
Replace System.err and System.out with SLF4J Logging
[simantics/platform.git] / bundles / org.simantics.scl.ui / src / org / simantics / scl / ui / console / SCLConsole.java
index 16a946fbebb86922ee99bd9ad481b5e547d37fd1..7221158c1bacfbfa8d91e27791ab84a49c8ee388 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,6 +35,13 @@ import gnu.trove.set.hash.THashSet;
  * @author Hannu Niemistö
  */
 public class SCLConsole extends AbstractCommandConsole {
+
+    /**
+     * 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";
        public static final long TERMINATE_GRACE_PERIOD = 1000L;
        
@@ -58,13 +67,24 @@ public class SCLConsole extends AbstractCommandConsole {
 
     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, 
@@ -76,15 +96,13 @@ public class SCLConsole extends AbstractCommandConsole {
         } 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())
@@ -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());
+    }
+
 }