Desktop: Add a button in dockbar to get the help about the component 92/5892/4
Calixte DENIZET [Thu, 12 Jan 2012 14:53:13 +0000 (15:53 +0100)]
Change-Id: I36d402477227591e695840ac9aa5e233318f0b76

18 files changed:
scilab/CHANGES_5.4.X
scilab/modules/core/src/java/org/scilab/modules/core/ConsoleTab.java
scilab/modules/gui/Makefile.am
scilab/modules/gui/Makefile.in
scilab/modules/gui/etc/flexdock-themes.xml
scilab/modules/gui/images/icons/dock_help_active.png [new file with mode: 0644]
scilab/modules/gui/images/icons/dock_help_default.png [new file with mode: 0644]
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/CallScilabBridge.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/helpbrowser/SwingScilabHelpBrowser.java
scilab/modules/gui/src/java/org/scilab/modules/gui/bridge/tab/SwingScilabTab.java
scilab/modules/gui/src/java/org/scilab/modules/gui/helpbrowser/ScilabHelpBrowser.java
scilab/modules/gui/src/java/org/scilab/modules/gui/utils/SciHelpOnComponentAction.java [new file with mode: 0644]
scilab/modules/history_browser/src/java/org/scilab/modules/history_browser/CommandHistory.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/SciNotes.java
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/filebrowser/SwingScilabFileBrowser.java
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/variablebrowser/SwingScilabVariableBrowser.java
scilab/modules/ui_data/src/java/org/scilab/modules/ui_data/variableeditor/SwingScilabVariableEditor.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/XcosTab.java

index 2e373fb..c4cbfa7 100644 (file)
@@ -2,6 +2,12 @@
             =================================================================
 
 
+Scilab Desktop
+==============
+
+* Add a button in dockbar to get the help about the component.
+
+
 XML
 ===
 
index ae1af1f..fe72a51 100644 (file)
@@ -65,6 +65,7 @@ public class ConsoleTab {
             JTextArea textarea = new JTextArea(NOCONSOLE);
             textarea.setEditable(false);
             ((SwingScilabTab) tab.getAsSimpleTab()).setContentPane(textarea);
+            ((SwingScilabTab) tab.getAsSimpleTab()).setAssociatedXMLIDForHelp("console");
 
             ClosingOperationsManager.registerClosingOperation(tab, new ClosingOperationsManager.ClosingOperation() {
 
@@ -80,7 +81,7 @@ public class ConsoleTab {
 
                     @Override
                     public void updateDependencies(List<SwingScilabTab> list,
-                            ListIterator<SwingScilabTab> it) {
+                                                   ListIterator<SwingScilabTab> it) {
                     }
                 });
 
@@ -125,7 +126,7 @@ public class ConsoleTab {
 
                     @Override
                     public void updateDependencies(List<SwingScilabTab> list,
-                            ListIterator<SwingScilabTab> it) {
+                                                   ListIterator<SwingScilabTab> it) {
                     }
                 });
 
@@ -148,6 +149,7 @@ public class ConsoleTab {
         ScilabConsole.getConsole().addInfoBar(infoBar);
         ScilabConsole.getConsole().setMaxOutputSize(ConfigManager.getMaxOutputSize());
         consoleTab.addMember(ScilabConsole.getConsole());
+        ((SwingScilabTab) consoleTab.getAsSimpleTab()).setAssociatedXMLIDForHelp("console");
         WindowsConfigurationManager.restorationFinished((SwingScilabTab) consoleTab.getAsSimpleTab());
 
         return consoleTab;
index 6c47462..7bd9cc9 100644 (file)
@@ -408,7 +408,9 @@ images/icons/rotate.png \
 images/icons/scilab_close_active.png \
 images/icons/scilab_close_default.png \
 images/icons/undock_active.png \
-images/icons/undock_default.png
+images/icons/undock_default.png \
+images/icons/dock_help_active.png \
+images/icons/dock_help_default.png
 
 if GUI
 USEANT=1
index 9dc0ef3..bd1d269 100644 (file)
@@ -973,7 +973,9 @@ images/icons/rotate.png \
 images/icons/scilab_close_active.png \
 images/icons/scilab_close_default.png \
 images/icons/undock_active.png \
-images/icons/undock_default.png
+images/icons/undock_default.png \
+images/icons/dock_help_active.png \
+images/icons/dock_help_default.png
 
 @GUI_TRUE@USEANT = 1
 all: $(BUILT_SOURCES)
index 5f9f2eb..050da86 100644 (file)
                <property name="tooltip" value="Undock" handler="string" />
        </icon-resource>
 
+        <icon-resource name="scilab.help">
+               <property name="default" value="dock_help_default.png" />
+               <property name="active" value="dock_help_active.png" />
+               <property name="tooltip" value="Help on component" handler="string" />
+       </icon-resource>
+
        <icon-resource name="scilab.close" extends="win32.close">
                <property name="default" value="scilab_close_default.png" />
                <property name="active" value="scilab_close_active.png" />
@@ -35,6 +41,7 @@
             <property name="close" value="scilab.close" />
             <property name="pin" value="win32.pin" />
             <property name="undock" value="scilab.undock" />
+            <property name="help" value="scilab.help" />
         </icon-map>
     </theme>
     <!-- End Scilab -->
diff --git a/scilab/modules/gui/images/icons/dock_help_active.png b/scilab/modules/gui/images/icons/dock_help_active.png
new file mode 100644 (file)
index 0000000..fcaf8a3
Binary files /dev/null and b/scilab/modules/gui/images/icons/dock_help_active.png differ
diff --git a/scilab/modules/gui/images/icons/dock_help_default.png b/scilab/modules/gui/images/icons/dock_help_default.png
new file mode 100644 (file)
index 0000000..eae0aad
Binary files /dev/null and b/scilab/modules/gui/images/icons/dock_help_default.png differ
index d9e2a4b..0a4f0fc 100644 (file)
@@ -46,6 +46,7 @@ import javax.swing.JTextPane;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.Document;
 
+import org.scilab.modules.commons.ScilabCommons;
 import org.scilab.modules.console.SciConsole;
 import org.scilab.modules.graphic_export.ExportRenderer;
 import org.scilab.modules.graphic_export.FileExporter;
@@ -2125,6 +2126,17 @@ public class CallScilabBridge {
     }
 
     /**
+     * Open HelpBrowser on the page with the given xmlID
+     * @param xmlID the xml id
+     */
+    public static void openHelp(String xmlID) {
+       HelpBrowser helpBrowser = ScilabHelpBrowser.createHelpBrowser(null, ScilabCommons.getlanguage());
+       if (helpBrowser != null) {
+           helpBrowser.searchKeywork(xmlID);
+       }
+    }
+
+    /**
      * Close Scilab Help Browser
      */
     public static void closeHelpBrowser() {
index df1e824..bc90629 100644 (file)
@@ -358,6 +358,11 @@ public class SwingScilabHelpBrowser extends JPanel implements SimpleHelpBrowser,
      * @param keyword the keyword
      */
     public void searchKeywork(String keyword) {
+       if (keyword == null) {
+            displayHomePage();
+           return;
+        }
+
         if (keyword.length() > 0 && keyword.charAt(0) == '%') {
             keyword = keyword.replace("%", "percent");
         }
index a0636d1..332ce1f 100644 (file)
@@ -73,6 +73,7 @@ import org.scilab.modules.gui.tree.Tree;
 import org.scilab.modules.gui.utils.BarUpdater;
 import org.scilab.modules.gui.utils.Position;
 import org.scilab.modules.gui.utils.SciClosingAction;
+import org.scilab.modules.gui.utils.SciHelpOnComponentAction;
 import org.scilab.modules.gui.utils.SciUndockingAction;
 import org.scilab.modules.gui.utils.ScilabSwingUtilities;
 import org.scilab.modules.gui.utils.Size;
@@ -94,16 +95,17 @@ public class SwingScilabTab extends View implements SimpleTab, FocusListener {
     private static final int VIEWPORT_SIZE = 4;
 
     private static final String UNDOCK = "undock";
+    private static final String HELP = "help";
 
     static {
         PropertyChangeListenerFactory.addFactory(new BarUpdater.UpdateBarFactory());
     }
 
     private int parentWindowId;
-    private String appNameOnClose;
     private MenuBar menuBar;
     private ToolBar toolBar;
     private TextBox infoBar;
+    private String helpID;
 
     /** Contains the canvas and widgets */
     private SwingScilabAxes contentPane;
@@ -175,6 +177,22 @@ public class SwingScilabTab extends View implements SimpleTab, FocusListener {
         this(name, name);
     }
 
+    /**
+     * Set the associated help page
+     * @param helpID the xml id of the associated help page
+     */
+    public void setAssociatedXMLIDForHelp(String helpID) {
+        this.helpID = helpID;
+    }
+
+    /**
+     * Get the associated help page
+     * @return the xml id of the associated help page
+     */
+    public String getAssociatedXMLIDForHelp() {
+        return helpID;
+    }
+
     public static void removeActions(SwingScilabTab tab) {
         tab.setActionBlocked(DockingConstants.CLOSE_ACTION, true);
         tab.setActionBlocked(UNDOCK, true);
@@ -976,6 +994,12 @@ public class SwingScilabTab extends View implements SimpleTab, FocusListener {
         undockAction.putValue(Action.NAME, UNDOCK);
         ((Titlebar) getTitlePane()).removeAction(UNDOCK);
         addAction(undockAction);
+
+        /* Help button */
+        SciHelpOnComponentAction helpAction = new SciHelpOnComponentAction(this);
+        helpAction.putValue(Action.NAME, HELP);
+        ((Titlebar) getTitlePane()).removeAction(HELP);
+        addAction(helpAction);
     }
 
     /**
index 6233b37..1656e8e 100644 (file)
@@ -132,6 +132,7 @@ public class ScilabHelpBrowser extends ScilabDockable implements HelpBrowser {
 
         SwingScilabHelpBrowser browser = (SwingScilabHelpBrowser) ((ScilabHelpBrowser) instance).component;
         browser.setCurrentID(lastID);
+        ((SwingScilabTab) helpTab.getAsSimpleTab()).setAssociatedXMLIDForHelp("helpbrowser");
         WindowsConfigurationManager.restorationFinished((SwingScilabTab) helpTab.getAsSimpleTab());
 
         return (SwingScilabTab) helpTab.getAsSimpleTab();
diff --git a/scilab/modules/gui/src/java/org/scilab/modules/gui/utils/SciHelpOnComponentAction.java b/scilab/modules/gui/src/java/org/scilab/modules/gui/utils/SciHelpOnComponentAction.java
new file mode 100644 (file)
index 0000000..8ec4ac8
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2010 - Calixte DENIZET
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+
+package org.scilab.modules.gui.utils;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+
+import org.scilab.modules.gui.bridge.CallScilabBridge;
+import org.scilab.modules.gui.bridge.tab.SwingScilabTab;
+
+/**
+ * Action executed when the user clicks on the "Help button"
+ * @author Calixte DENIZET
+ */
+public class SciHelpOnComponentAction extends AbstractAction {
+
+    private static final long serialVersionUID = 1L;
+
+    private SwingScilabTab associatedTab;
+
+    /**
+     * Constructor
+     * @param tab the associated tab
+     */
+    public SciHelpOnComponentAction(SwingScilabTab tab) {
+        associatedTab = tab;
+    }
+
+    /**
+     * What do I have to do when the event accurs
+     * @param arg0 the event
+     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
+     */
+    public void actionPerformed(ActionEvent arg0) {
+        String id = associatedTab.getAssociatedXMLIDForHelp();
+        CallScilabBridge.openHelp(id);
+    }
+}
index 66d8cc7..7cf29d8 100644 (file)
@@ -105,6 +105,7 @@ public final class CommandHistory extends SwingScilabTab implements Tab {
      */
     private CommandHistory() {
         super(CommandHistoryMessages.TITLE, COMMANDHISTORYUUID);
+        setAssociatedXMLIDForHelp("historybrowser");
         initialize();
         addMenuBar(createMenuBar());
         addToolBar(createToolBar());
index de6e319..145a376 100644 (file)
@@ -170,6 +170,7 @@ public class SciNotes extends SwingScilabTab implements Tab {
      */
     public SciNotes(String uuid) {
         super(SCINOTES, uuid);
+       setAssociatedXMLIDForHelp("scinotes");
         this.uuid = UUID.fromString(uuid);
         editor = this;
         scinotesList.add(this);
index e14c836..af2d897 100644 (file)
@@ -52,6 +52,7 @@ public final class SwingScilabFileBrowser extends SwingScilabTab implements Tab
      */
     public SwingScilabFileBrowser() {
         super(UiDataMessages.FILE_BROWSER, FILEBROWSERUUID);
+        setAssociatedXMLIDForHelp("filebrowser");
         addMenuBar(createMenuBar());
         filebrowser = new ScilabFileBrowserComponent();
 
index 0d6050b..a345ae5 100644 (file)
@@ -134,8 +134,9 @@ public final class SwingScilabVariableBrowser extends SwingScilabTab implements
     public SwingScilabVariableBrowser(String[] columnsName) {
         super(UiDataMessages.VARIABLE_BROWSER, VARBROWSERUUID);
 
-        buildMenuBar();
+        setAssociatedXMLIDForHelp("browsevar");
 
+        buildMenuBar();
         addMenuBar(menuBar);
 
         ToolBar toolBar = ScilabToolBar.createToolBar();
index 268690c..b0400af 100644 (file)
@@ -98,6 +98,7 @@ public class SwingScilabVariableEditor extends SwingScilabTab implements Tab, Si
      */
     public SwingScilabVariableEditor(String name, String type, Object[][] data) {
         super(UiDataMessages.VARIABLE_EDITOR);
+       setAssociatedXMLIDForHelp("editvar");
         setWindowIcon("rrze_table");
         refreshButton = RefreshAction.createButton(this, UiDataMessages.REFRESH);
         undoButton = UndoAction.createButton(this, UiDataMessages.UNDO);
index 5b61bb3..f34ca5b 100644 (file)
@@ -235,6 +235,8 @@ public class XcosTab extends SwingScilabTab implements Tab {
      */
     private XcosTab(XcosDiagram graph, String uuid) {
         super(XcosMessages.XCOS, uuid);
+       
+       setAssociatedXMLIDForHelp("xcos");
 
         /** tab association */
         graph.setDiagramTab(uuid);