incubator-kalumet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject svn commit: r1205585 [19/23] - in /incubator/kalumet/trunk: ./ console/ console/src/main/java/org/apache/kalumet/console/app/ console/src/main/resources/org/apache/kalumet/console/app/templates/
Date Wed, 23 Nov 2011 20:52:25 GMT
Added: incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/SharedLibrariesPane.java
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/SharedLibrariesPane.java?rev=1205585&view=auto
==============================================================================
--- incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/SharedLibrariesPane.java (added)
+++ incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/SharedLibrariesPane.java Wed Nov 23 20:52:16 2011
@@ -0,0 +1,718 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.kalumet.console.app;
+
+import java.util.Iterator;
+
+import nextapp.echo2.app.Button;
+import nextapp.echo2.app.Column;
+import nextapp.echo2.app.ContentPane;
+import nextapp.echo2.app.Extent;
+import nextapp.echo2.app.Grid;
+import nextapp.echo2.app.Insets;
+import nextapp.echo2.app.Label;
+import nextapp.echo2.app.Row;
+import nextapp.echo2.app.SelectField;
+import nextapp.echo2.app.TextField;
+import nextapp.echo2.app.event.ActionEvent;
+import nextapp.echo2.app.event.ActionListener;
+import nextapp.echo2.app.list.DefaultListModel;
+import org.apache.kalumet.console.configuration.ConfigurationManager;
+import org.apache.kalumet.model.Agent;
+import org.apache.kalumet.model.J2EEApplicationServer;
+import org.apache.kalumet.model.Kalumet;
+import org.apache.kalumet.model.SharedLibrary;
+import org.apache.kalumet.ws.client.SharedLibraryClient;
+
+/**
+ * Environment shared libraries pane.
+ */
+public class SharedLibrariesPane extends ContentPane {
+
+    private EnvironmentWindow parent;
+    private SelectField scopeField;
+    private Grid grid;
+    private boolean newIsActive = true;
+    private boolean newIsBlocker = false;
+    private TextField newNameField;
+    private TextField newClasspathField;
+
+    // status thread
+    class StatusThread extends Thread {
+
+        public String serverName;
+        public String sharedLibraryName;
+        public boolean ended = false;
+        public boolean failure = false;
+        public String message;
+
+        public void run() {
+            try {
+                // load Kalumet configuration
+                Kalumet kalumet = ConfigurationManager.loadStore();
+                // looking for the agent
+                Agent agent = kalumet.getAgent(parent.getEnvironment().getAgent());
+                if (agent == null) {
+                    throw new IllegalArgumentException("agent not found.");
+                }
+                // call the webservice stub
+                SharedLibraryClient client = new SharedLibraryClient(agent.getHostname(), agent.getPort());
+                boolean uptodate = client.check(parent.getEnvironmentName(), serverName, sharedLibraryName);
+                if (uptodate) {
+                    message = "Shared library " + sharedLibraryName + " is up to date.";
+                } else {
+                    failure = true;
+                    message = "Shared library " + sharedLibraryName + " is not up to date";
+                }
+            } catch (Exception e) {
+                failure = true;
+                message = "Shared library " + sharedLibraryName + " status check failed: " + e.getMessage();
+            } finally {
+                ended = true;
+            }
+        }
+    }
+
+    // update thread
+    class UpdateThread extends Thread {
+
+        public String serverName;
+        public String sharedLibraryName;
+        public boolean ended = false;
+        public boolean failure = false;
+        public String message;
+
+        public void run() {
+            try {
+                // load Kalumet configuration
+                Kalumet kalumet = ConfigurationManager.loadStore();
+                // looking for the agent
+                Agent agent = kalumet.getAgent(parent.getEnvironment().getAgent());
+                if (agent == null) {
+                    throw new IllegalArgumentException("agent not found.");
+                }
+                // call the webservice stub
+                SharedLibraryClient client = new SharedLibraryClient(agent.getHostname(), agent.getPort());
+                client.update(parent.getEnvironmentName(), serverName, sharedLibraryName);
+            } catch (Exception e) {
+                failure = true;
+                message = "Shared library " + sharedLibraryName + " update failed: " + e.getMessage();
+            } finally {
+                ended = true;
+            }
+        }
+    }
+
+    // scope select
+    private ActionListener scopeSelect = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            update();
+        }
+    };
+    // toggle active
+    private ActionListener toggleActive = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // check if the user has the environment lock
+            if (!getEnvironmentWindow().getEnvironment().getLock().equals(KalumetConsoleApplication.getApplication().getUserid())) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.locked"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // check if the user can do it
+            if (!getEnvironmentWindow().adminPermission && !getEnvironmentWindow().jeeResourcesPermission) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("action.restricted"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // looking for the shared library object
+            SharedLibrary sharedLibrary = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeField.getSelectedItem()).getSharedLibrary(event.getActionCommand());
+            if (sharedLibrary == null) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("sharedlibrary.notfound"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // update the state
+            if (sharedLibrary.isActive()) {
+                sharedLibrary.setActive(false);
+                // add a change event
+                parent.getChangeEvents().add("Disable shared library " + sharedLibrary.getName());
+            } else {
+                sharedLibrary.setActive(true);
+                parent.getChangeEvents().add("Enable shared library " + sharedLibrary.getName());
+            }
+            // change the updated flag
+            parent.setUpdated(true);
+            // update the journal log tab pane
+            parent.updateJournalPane();
+            // update the pane
+            update();
+        }
+    };
+    // toggle blocker
+    private ActionListener toggleBlocker = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // check if the user has the environment lock
+            if (!getEnvironmentWindow().getEnvironment().getLock().equals(KalumetConsoleApplication.getApplication().getUserid())) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.locked"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // check if the user can do it
+            if (!getEnvironmentWindow().adminPermission && !getEnvironmentWindow().jeeResourcesPermission) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("action.restricted"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // looking for the shared library object
+            SharedLibrary sharedLibrary = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeField.getSelectedItem()).getSharedLibrary(event.getActionCommand());
+            if (sharedLibrary == null) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("sharedlibrary.notfound"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // update the blocker state and add a change event
+            if (sharedLibrary.isBlocker()) {
+                sharedLibrary.setBlocker(false);
+                parent.getChangeEvents().add("Set not blocker for shared library " + sharedLibrary.getName());
+            } else {
+                sharedLibrary.setBlocker(true);
+                parent.getChangeEvents().add("Set blocker for shared library " + sharedLibrary.getName());
+            }
+            // change the updated flag
+            parent.setUpdated(true);
+            // update the journal log tab pane
+            parent.updateJournalPane();
+            // update the pane
+            update();
+        }
+    };
+    // new toggle active
+    private ActionListener newToggleActive = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // toggle the state
+            if (newIsActive) {
+                newIsActive = false;
+            } else {
+                newIsActive = true;
+            }
+            // update the pane
+            update();
+        }
+    };
+    // new toggle blocker
+    private ActionListener newToggleBlocker = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // toggle the blocker state
+            if (newIsBlocker) {
+                newIsBlocker = false;
+            } else {
+                newIsBlocker = true;
+            }
+            // update the pane
+            update();
+        }
+    };
+    // delete
+    private ActionListener delete = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // check if the user has the environment lock
+            if (!getEnvironmentWindow().getEnvironment().getLock().equals(KalumetConsoleApplication.getApplication().getUserid())) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.locked"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // check if the user can do it
+            if (!getEnvironmentWindow().adminPermission && !getEnvironmentWindow().jeeResourcesPermission) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("action.restricted"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // looking for the shared library
+            final SharedLibrary sharedLibrary = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeField.getSelectedItem()).getSharedLibrary(event.getActionCommand());
+            if (sharedLibrary == null) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("sharedlibrary.notfound"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // display confirm window
+            KalumetConsoleApplication.getApplication().getDefaultWindow().getContent().add(new ConfirmWindow(new ActionListener() {
+                public void actionPerformed(ActionEvent event) {
+                    // remove the shared library
+                    parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeField.getSelectedItem()).getSharedLibraries().remove(sharedLibrary);
+                    // add a change event
+                    parent.getChangeEvents().add("Delete shared library " + sharedLibrary.getName());
+                    // change the updated flag
+                    parent.setUpdated(true);
+                    // update the journal log tab pane
+                    parent.updateJournalPane();
+                    // update only the pane
+                    update();
+                }
+            }));
+        }
+    };
+    // edit
+    private ActionListener edit = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // check if the user has the environment lock
+            if (!getEnvironmentWindow().getEnvironment().getLock().equals(KalumetConsoleApplication.getApplication().getUserid())) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.locked"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // check if the user can do it
+            if (!getEnvironmentWindow().adminPermission && !getEnvironmentWindow().jeeResourcesPermission) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("action.restricted"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // get the shared library name
+            String name = event.getActionCommand();
+            // get the fields
+            TextField nameField = (TextField) SharedLibrariesPane.this.getComponent("slname_" + parent.getEnvironmentName() + "_" + (String) scopeField.getSelectedItem() + "_" + name);
+            TextField classpathField = (TextField) SharedLibrariesPane.this.getComponent("slclasspath_" + parent.getEnvironmentName() + "_" + (String) scopeField.getSelectedItem() + "_" + name);
+            // get values
+            String nameFieldValue = nameField.getText();
+            String classpathFieldValue = classpathField.getText();
+            // check values
+            if (nameFieldValue == null || nameFieldValue.trim().length() < 1 || classpathFieldValue == null || classpathFieldValue.trim().length() < 1) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("sharedlibrary.mandatory"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // if the user change the shared library name, check if the shared
+            // library name is not already in use
+            if (!name.equals(nameFieldValue)) {
+                if (parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeField.getSelectedItem()).getSharedLibrary(nameFieldValue) != null) {
+                    KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("sharedlibrary.exists"), getEnvironmentWindow().getEnvironmentName());
+                    return;
+                }
+            }
+            // looking for the shared library object
+            SharedLibrary sharedLibrary = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeField.getSelectedItem()).getSharedLibrary(name);
+            if (sharedLibrary == null) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("sharedlibrary.notfound"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // add a change event
+            parent.getChangeEvents().add("Change shared library " + sharedLibrary.getName() + " / " + sharedLibrary.getClasspath());
+            // change the shared library object
+            sharedLibrary.setName(nameFieldValue);
+            sharedLibrary.setClasspath(classpathFieldValue);
+            // change the updated flag
+            parent.setUpdated(true);
+            // update the journal log tab pane
+            parent.updateJournalPane();
+            // update the pane
+            update();
+        }
+    };
+    // create
+    private ActionListener create = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // check if the user has the environment lock
+            if (!getEnvironmentWindow().getEnvironment().getLock().equals(KalumetConsoleApplication.getApplication().getUserid())) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.locked"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // check if the user can do it
+            if (!getEnvironmentWindow().adminPermission && !getEnvironmentWindow().jeeResourcesPermission) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("action.restricted"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // get values
+            String newNameFieldValue = newNameField.getText();
+            String newClasspathFieldValue = newClasspathField.getText();
+            // mandatory field
+            if (newNameFieldValue == null || newNameFieldValue.trim().length() < 1 || newClasspathFieldValue == null || newClasspathFieldValue.trim().length() < 1) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("sharedlibrary.mandatory"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // create the new shared library object
+            SharedLibrary sharedLibrary = new SharedLibrary();
+            sharedLibrary.setName(newNameFieldValue);
+            sharedLibrary.setClasspath(newClasspathFieldValue);
+            sharedLibrary.setActive(newIsActive);
+            // add the shared library
+            try {
+                parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeField.getSelectedItem()).addSharedLibrary(sharedLibrary);
+            } catch (Exception e) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("sharedlibrary.exists"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // add a change event
+            parent.getChangeEvents().add("Create shared library " + sharedLibrary.getName() + " / " + sharedLibrary.getClasspath());
+            // change the updated flag
+            parent.setUpdated(true);
+            // update the journal log tab pane
+            parent.updateJournalPane();
+            // update the pane
+            update();
+        }
+    };
+    // copy
+    private ActionListener copy = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // looking for the shared library object
+            SharedLibrary sharedLibrary = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeField.getSelectedItem()).getSharedLibrary(event.getActionCommand());
+            if (sharedLibrary == null) {
+                return;
+            }
+            try {
+                KalumetConsoleApplication.getApplication().setCopyComponent(sharedLibrary);
+            } catch (Exception e) {
+                return;
+            }
+        }
+    };
+    // paste
+    private ActionListener paste = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            Object copy = KalumetConsoleApplication.getApplication().getCopyComponent();
+            // check if the copy object is correct
+            if (copy == null || !(copy instanceof SharedLibrary)) {
+                return;
+            }
+            // update the new fields
+            newNameField.setText(((SharedLibrary) copy).getName());
+            newClasspathField.setText(((SharedLibrary) copy).getClasspath());
+        }
+    };
+    // status
+    private ActionListener status = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // check if some change has not yet been saved
+            if (getEnvironmentWindow().isUpdated()) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.notsaved"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // get the server and shared library name
+            String serverName = (String) scopeField.getSelectedItem();
+            String sharedLibraryName = event.getActionCommand();
+            // add a message in the log pane and the journal
+            KalumetConsoleApplication.getApplication().getLogPane().addInfo("Shared library " + sharedLibraryName + " status check in progress...", parent.getEnvironmentName());
+            parent.getChangeEvents().add("Shared library " + sharedLibraryName + " status check requested.");
+            // start the status thread
+            final StatusThread statusThread = new StatusThread();
+            statusThread.serverName = serverName;
+            statusThread.sharedLibraryName = sharedLibraryName;
+            statusThread.start();
+            // sync with the client
+            KalumetConsoleApplication.getApplication().enqueueTask(KalumetConsoleApplication.getApplication().getTaskQueue(), new Runnable() {
+                public void run() {
+                    if (statusThread.ended) {
+                        if (statusThread.failure) {
+                            KalumetConsoleApplication.getApplication().getLogPane().addWarning(statusThread.message, parent.getEnvironmentName());
+                        } else {
+                            KalumetConsoleApplication.getApplication().getLogPane().addInfo(statusThread.message, parent.getEnvironmentName());
+                        }
+                        parent.getChangeEvents().add(statusThread.message);
+                    } else {
+                        KalumetConsoleApplication.getApplication().enqueueTask(KalumetConsoleApplication.getApplication().getTaskQueue(), this);
+                    }
+                }
+            });
+        }
+    };
+    // update
+    private ActionListener update = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // check if the user has the lock
+            if (!getEnvironmentWindow().getEnvironment().getLock().equals(KalumetConsoleApplication.getApplication().getUserid())) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.locked"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // check if the user can do it
+            if (!getEnvironmentWindow().adminPermission && !getEnvironmentWindow().jeeResourcesUpdatePermission) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("action.restricted"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // check if some change has not been saved
+            if (getEnvironmentWindow().isUpdated()) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.notsaved"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // get the JEE server and shared library name
+            final String serverName = (String) scopeField.getSelectedItem();
+            final String sharedLibraryName = event.getActionCommand();
+            // display confirm window
+            KalumetConsoleApplication.getApplication().getDefaultWindow().getContent().add(new ConfirmWindow(new ActionListener() {
+                public void actionPerformed(ActionEvent event) {
+                    // add a message in the log pane and in the journal
+                    KalumetConsoleApplication.getApplication().getLogPane().addInfo("Shared library " + sharedLibraryName + " update in progress ...", parent.getEnvironmentName());
+                    parent.getChangeEvents().add("Shared library " + sharedLibraryName + " update requested.");
+                    // start the update thread
+                    final UpdateThread updateThread = new UpdateThread();
+                    updateThread.serverName = serverName;
+                    updateThread.sharedLibraryName = sharedLibraryName;
+                    updateThread.start();
+                    // sync with the client
+                    KalumetConsoleApplication.getApplication().enqueueTask(KalumetConsoleApplication.getApplication().getTaskQueue(), new Runnable() {
+                        public void run() {
+                            if (updateThread.ended) {
+                                if (updateThread.failure) {
+                                    KalumetConsoleApplication.getApplication().getLogPane().addError(updateThread.message, parent.getEnvironmentName());
+                                    parent.getChangeEvents().add(updateThread.message);
+                                } else {
+                                    KalumetConsoleApplication.getApplication().getLogPane().addConfirm("Shared library " + sharedLibraryName + " updated.", parent.getEnvironmentName());
+                                    parent.getChangeEvents().add("Shared library " + sharedLibraryName + " updated.");
+                                }
+                            } else {
+                                KalumetConsoleApplication.getApplication().enqueueTask(KalumetConsoleApplication.getApplication().getTaskQueue(), this);
+                            }
+                        }
+                    });
+                }
+            }));
+        }
+    };
+
+    /**
+     * Create a new <code>SharedLibrariesPane</code>.
+     *
+     * @param parent the parent <code>EnvironmentWindow</code>.
+     */
+    public SharedLibrariesPane(EnvironmentWindow parent) {
+        super();
+        setStyleName("tab.content");
+
+        // update parent
+        this.parent = parent;
+
+        // column layout
+        Column content = new Column();
+        content.setCellSpacing(new Extent(2));
+        add(content);
+
+        // add the scope select field
+        Grid layoutGrid = new Grid(2);
+        layoutGrid.setStyleName("default");
+        layoutGrid.setColumnWidth(0, new Extent(20, Extent.PERCENT));
+        layoutGrid.setColumnWidth(1, new Extent(80, Extent.PERCENT));
+        content.add(layoutGrid);
+        Label scopeLabel = new Label(Messages.getString("scope"));
+        scopeLabel.setStyleName("default");
+        layoutGrid.add(scopeLabel);
+        scopeField = new SelectField();
+        scopeField.addActionListener(scopeSelect);
+        scopeField.setStyleName("default");
+        layoutGrid.add(scopeField);
+        DefaultListModel scopeListModel = (DefaultListModel) scopeField.getModel();
+        scopeListModel.removeAll();
+        // add application servers in the scope select field
+        for (Iterator applicationServerIterator = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServers().iterator(); applicationServerIterator.hasNext(); ) {
+            J2EEApplicationServer applicationServer = (J2EEApplicationServer) applicationServerIterator.next();
+            scopeListModel.add(applicationServer.getName());
+        }
+        if (scopeListModel.size() > 0) {
+            scopeField.setSelectedIndex(0);
+        }
+
+        // add shared libraries grid
+        grid = new Grid(3);
+        grid.setStyleName("border.grid");
+        grid.setColumnWidth(0, new Extent(50, Extent.PX));
+        grid.setColumnWidth(1, new Extent(50, Extent.PERCENT));
+        grid.setColumnWidth(2, new Extent(50, Extent.PERCENT));
+        content.add(grid);
+
+        // update the pane
+        update();
+    }
+
+    /**
+     * Update the pane.
+     */
+    public void update() {
+        String applicationServerName = null;
+        // update the scope select field
+        DefaultListModel scopeListModel = (DefaultListModel) scopeField.getModel();
+        if (scopeListModel.size() > 0) {
+            applicationServerName = (String) scopeField.getSelectedItem();
+        }
+        scopeListModel.removeAll();
+        int scopeIndex = 0;
+        int found = -1;
+        for (Iterator applicationServerIterator = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServers().iterator(); applicationServerIterator.hasNext(); ) {
+            J2EEApplicationServer applicationServer = (J2EEApplicationServer) applicationServerIterator.next();
+            scopeListModel.add(applicationServer.getName());
+            if (applicationServer.getName().equals(applicationServerName)) {
+                found = scopeIndex;
+            }
+            scopeIndex++;
+        }
+
+        // remove all shared libraries grid children
+        grid.removeAll();
+
+        // check if at least one application server is present
+        if (scopeListModel.size() < 1) {
+            return;
+        }
+        // update the scope select field selected index
+        if (found == -1) {
+            scopeField.setSelectedIndex(0);
+        } else {
+            scopeField.setSelectedIndex(found);
+        }
+        // update the application server name from the scope (in case of
+        // application server deletion)
+        applicationServerName = (String) scopeField.getSelectedItem();
+
+        // add shared libraries grid header
+        Label actionHeader = new Label(" ");
+        actionHeader.setStyleName("grid.header");
+        grid.add(actionHeader);
+        Label nameHeader = new Label(Messages.getString("name"));
+        nameHeader.setStyleName("grid.header");
+        grid.add(nameHeader);
+        Label classpathHeader = new Label(Messages.getString("classpath"));
+        classpathHeader.setStyleName("grid.header");
+        grid.add(classpathHeader);
+        // add the shared libraries
+        for (Iterator sharedLibraryIterator = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer(applicationServerName).getSharedLibraries().iterator(); sharedLibraryIterator.hasNext(); ) {
+            SharedLibrary sharedLibrary = (SharedLibrary) sharedLibraryIterator.next();
+            // row
+            Row row = new Row();
+            row.setInsets(new Insets(2));
+            row.setCellSpacing(new Extent(2));
+            grid.add(row);
+            // copy
+            Button copyButton = new Button(Styles.PAGE_COPY);
+            copyButton.setToolTipText(Messages.getString("copy"));
+            copyButton.setActionCommand(sharedLibrary.getName());
+            copyButton.addActionListener(copy);
+            row.add(copyButton);
+            // active
+            Button activeButton;
+            if (sharedLibrary.isActive()) {
+                activeButton = new Button(Styles.LIGHTBULB);
+                activeButton.setToolTipText(Messages.getString("switch.disable"));
+            } else {
+                activeButton = new Button(Styles.LIGHTBULB_OFF);
+                activeButton.setToolTipText(Messages.getString("switch.enable"));
+            }
+            if (getEnvironmentWindow().adminPermission || getEnvironmentWindow().jeeResourcesPermission) {
+                activeButton.setActionCommand(sharedLibrary.getName());
+                activeButton.addActionListener(toggleActive);
+            }
+            row.add(activeButton);
+            // blocker
+            Button blockerButton;
+            if (sharedLibrary.isBlocker()) {
+                blockerButton = new Button(Styles.PLUGIN);
+                blockerButton.setToolTipText(Messages.getString("switch.notblocker"));
+            } else {
+                blockerButton = new Button(Styles.PLUGIN_DISABLED);
+                blockerButton.setToolTipText(Messages.getString("switch.blocker"));
+            }
+            if (getEnvironmentWindow().adminPermission || getEnvironmentWindow().jeeResourcesPermission) {
+                blockerButton.setActionCommand(sharedLibrary.getName());
+                blockerButton.addActionListener(toggleBlocker);
+            }
+            row.add(blockerButton);
+            // status
+            Button statusButton = new Button(Styles.INFORMATION);
+            statusButton.setToolTipText(Messages.getString("status"));
+            statusButton.setActionCommand(sharedLibrary.getName());
+            statusButton.addActionListener(status);
+            row.add(statusButton);
+            if (getEnvironmentWindow().adminPermission || getEnvironmentWindow().jeeResourcesUpdatePermission) {
+                // update
+                Button updateButton = new Button(Styles.COG);
+                updateButton.setToolTipText(Messages.getString("update"));
+                updateButton.setActionCommand(sharedLibrary.getName());
+                updateButton.addActionListener(update);
+                row.add(updateButton);
+            }
+            if (getEnvironmentWindow().adminPermission || getEnvironmentWindow().jeeResourcesPermission) {
+                // edit
+                Button editButton = new Button(Styles.ACCEPT);
+                editButton.setToolTipText(Messages.getString("apply"));
+                editButton.setActionCommand(sharedLibrary.getName());
+                editButton.addActionListener(edit);
+                row.add(editButton);
+                // delete
+                Button deleteButton = new Button(Styles.DELETE);
+                deleteButton.setToolTipText(Messages.getString("delete"));
+                deleteButton.setActionCommand(sharedLibrary.getName());
+                deleteButton.addActionListener(delete);
+                row.add(deleteButton);
+            }
+            // name
+            TextField nameField = new TextField();
+            nameField.setStyleName("default");
+            nameField.setWidth(new Extent(100, Extent.PERCENT));
+            nameField.setId("slname_" + parent.getEnvironmentName() + "_" + applicationServerName + "_" + sharedLibrary.getName());
+            nameField.setText(sharedLibrary.getName());
+            grid.add(nameField);
+            // classpath
+            TextField classpathField = new TextField();
+            classpathField.setStyleName("default");
+            classpathField.setWidth(new Extent(100, Extent.PERCENT));
+            classpathField.setId("slclasspath_" + parent.getEnvironmentName() + "_" + applicationServerName + "_" + sharedLibrary.getName());
+            classpathField.setText(sharedLibrary.getClasspath());
+            grid.add(classpathField);
+        }
+
+        // add create shared library row in the shared libraries grid
+        if (getEnvironmentWindow().adminPermission || getEnvironmentWindow().jeeResourcesPermission) {
+            // row
+            Row row = new Row();
+            row.setInsets(new Insets(2));
+            row.setCellSpacing(new Extent(2));
+            grid.add(row);
+            // active
+            Button activeButton;
+            if (newIsActive) {
+                activeButton = new Button(Styles.LIGHTBULB);
+                activeButton.setToolTipText(Messages.getString("switch.disable"));
+            } else {
+                activeButton = new Button(Styles.LIGHTBULB_OFF);
+                activeButton.setToolTipText(Messages.getString("switch.enable"));
+            }
+            activeButton.addActionListener(newToggleActive);
+            row.add(activeButton);
+            // blocker
+            Button blockerButton;
+            if (newIsBlocker) {
+                blockerButton = new Button(Styles.PLUGIN);
+                blockerButton.setToolTipText(Messages.getString("switch.notblocker"));
+            } else {
+                blockerButton = new Button(Styles.PLUGIN_DISABLED);
+                blockerButton.setToolTipText(Messages.getString("switch.blocker"));
+            }
+            blockerButton.addActionListener(newToggleBlocker);
+            row.add(blockerButton);
+            // paste
+            Button pasteButton = new Button(Styles.PAGE_PASTE);
+            pasteButton.setToolTipText(Messages.getString("paste"));
+            pasteButton.addActionListener(paste);
+            row.add(pasteButton);
+            // add
+            Button addButton = new Button(Styles.ADD);
+            addButton.setToolTipText(Messages.getString("add"));
+            addButton.addActionListener(create);
+            row.add(addButton);
+            // name
+            newNameField = new TextField();
+            newNameField.setStyleName("default");
+            newNameField.setWidth(new Extent(100, Extent.PERCENT));
+            grid.add(newNameField);
+            // classpath
+            newClasspathField = new TextField();
+            newClasspathField.setStyleName("default");
+            newClasspathField.setWidth(new Extent(100, Extent.PERCENT));
+            grid.add(newClasspathField);
+        }
+    }
+
+    public EnvironmentWindow getEnvironmentWindow() {
+        return parent;
+    }
+
+}

Added: incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/ShellPane.java
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/ShellPane.java?rev=1205585&view=auto
==============================================================================
--- incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/ShellPane.java (added)
+++ incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/ShellPane.java Wed Nov 23 20:52:16 2011
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.kalumet.console.app;
+
+import nextapp.echo2.app.Button;
+import nextapp.echo2.app.ContentPane;
+import nextapp.echo2.app.Extent;
+import nextapp.echo2.app.Insets;
+import nextapp.echo2.app.Row;
+import nextapp.echo2.app.SplitPane;
+import nextapp.echo2.app.TextArea;
+import nextapp.echo2.app.TextField;
+import nextapp.echo2.app.event.ActionEvent;
+import nextapp.echo2.app.event.ActionListener;
+import nextapp.echo2.app.layout.SplitPaneLayoutData;
+import org.apache.kalumet.console.configuration.ConfigurationManager;
+import org.apache.kalumet.model.Agent;
+import org.apache.kalumet.model.Kalumet;
+import org.apache.kalumet.ws.client.CommandClient;
+
+public class ShellPane extends ContentPane {
+
+    private EnvironmentWindow parent;
+    private TextArea echoArea;
+    private TextField commandField;
+
+    // action listeners
+    // launch
+    private ActionListener launch = new ActionListener() {
+
+        // system command execution timeout
+        private static final int EXECUTION_TIMEOUT_SECONDS = 120;
+
+        public void actionPerformed(ActionEvent event) {
+            // check if the user has the lock
+            if (!parent.getEnvironment().getLock().equals(KalumetConsoleApplication.getApplication().getUserid())) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.locked"));
+                return;
+            }
+            String command = commandField.getText();
+            if (command == null || command.trim().length() < 1) {
+                return;
+            }
+            try {
+                // load Kalumet configuration
+                Kalumet kalumet = ConfigurationManager.loadStore();
+                // looking for the Kalumet agent
+                Agent agent = kalumet.getAgent(parent.getEnvironment().getAgent());
+                // check if the agent exist
+                if (agent == null) {
+                    KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.shell.noagent"));
+                    return;
+                }
+                // call the webservice
+                CommandClient client = new CommandClient(agent.getHostname(), agent.getPort());
+                String result = client.execute(command);
+                // echo the command
+                StringBuffer buffer = new StringBuffer();
+                buffer.append(echoArea.getText());
+                buffer.append("$> ");
+                buffer.append(command);
+                buffer.append("\n");
+                buffer.append(result);
+                buffer.append("\n");
+                // update the main area
+                echoArea.setText(buffer.toString());
+                // update the scroll
+                echoArea.setVerticalScroll(new Extent(buffer.length() + 10));
+                // erase the main command field
+                commandField.setText("");
+            } catch (Exception exception) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("shell.warn.command") + ": " + exception.getMessage());
+                return;
+            }
+        }
+
+    };
+
+    /**
+     * Create a new <code>ShellPane</code>
+     *
+     * @param parent the parent <code>EnvironmentWindow</code>.
+     */
+    public ShellPane(EnvironmentWindow parent) {
+        super();
+        setStyleName("tab.content");
+
+        // update parent
+        this.parent = parent;
+
+        // split pane content
+        SplitPane content = new SplitPane(SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP, new Extent(25));
+        this.add(content);
+
+        // add the main command field and launch button
+        // command row container
+        Row commandRow = new Row();
+        SplitPaneLayoutData layoutData = new SplitPaneLayoutData();
+        layoutData.setInsets(new Insets(4));
+        commandRow.setLayoutData(layoutData);
+        commandRow.setCellSpacing(new Extent(2));
+        commandRow.setInsets(new Insets(2));
+        content.add(commandRow);
+        commandField = new TextField();
+        commandField.setStyleName("default");
+        commandField.addActionListener(launch);
+        commandRow.add(commandField);
+        Button launcherButton = new Button(Messages.getString("execute"), Styles.ACCEPT);
+        launcherButton.addActionListener(launch);
+        commandRow.add(launcherButton);
+
+        // add the main text area
+        echoArea = new TextArea();
+        echoArea.setStyleName("default");
+        echoArea.setLayoutData(layoutData);
+        echoArea.setEnabled(false);
+        echoArea.setWidth(new Extent(100, Extent.PERCENT));
+        echoArea.setHeight(new Extent(98, Extent.PERCENT));
+        content.add(echoArea);
+    }
+
+}

Added: incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/SoftwareCommandWindow.java
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/SoftwareCommandWindow.java?rev=1205585&view=auto
==============================================================================
--- incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/SoftwareCommandWindow.java (added)
+++ incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/SoftwareCommandWindow.java Wed Nov 23 20:52:16 2011
@@ -0,0 +1,433 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.kalumet.console.app;
+
+import java.util.Iterator;
+
+import nextapp.echo2.app.Button;
+import nextapp.echo2.app.Extent;
+import nextapp.echo2.app.Grid;
+import nextapp.echo2.app.Label;
+import nextapp.echo2.app.Row;
+import nextapp.echo2.app.SelectField;
+import nextapp.echo2.app.SplitPane;
+import nextapp.echo2.app.TextArea;
+import nextapp.echo2.app.TextField;
+import nextapp.echo2.app.WindowPane;
+import nextapp.echo2.app.event.ActionEvent;
+import nextapp.echo2.app.event.ActionListener;
+import nextapp.echo2.app.list.DefaultListModel;
+import org.apache.kalumet.console.configuration.ConfigurationManager;
+import org.apache.kalumet.model.Agent;
+import org.apache.kalumet.model.Command;
+import org.apache.kalumet.model.Kalumet;
+import org.apache.kalumet.ws.client.SoftwareClient;
+
+/**
+ * Software command window.
+ */
+public class SoftwareCommandWindow extends WindowPane {
+
+    private String name;
+    private SoftwareWindow parent;
+    private Command command;
+
+    private TextField nameField;
+    private SelectField activeField;
+    private SelectField blockerField;
+    private TextArea commandArea;
+    private SelectField agentField;
+
+    // execute thread
+    class ExecuteThread extends Thread {
+
+        public boolean ended = false;
+        public boolean failure = false;
+        public String message;
+
+        public void run() {
+            try {
+                // load Kalumet configuration
+                Kalumet kalumet = ConfigurationManager.loadStore();
+                // looking for the agent
+                Agent agent = kalumet.getAgent(parent.getParentPane().getEnvironmentWindow().getEnvironment().getAgent());
+                if (agent == null) {
+                    throw new IllegalArgumentException("agent not found.");
+                }
+                // call the WebService
+                SoftwareClient client = new SoftwareClient(agent.getHostname(), agent.getPort());
+                client.executeCommand(parent.getParentPane().getEnvironmentWindow().getEnvironmentName(), parent.getName(), name, false);
+            } catch (Exception e) {
+                failure = true;
+                message = "Software " + parent.getName() + " command " + name + " execution failed: " + e.getMessage();
+            } finally {
+                ended = true;
+            }
+        }
+    }
+
+    // refresh
+    private ActionListener refresh = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // looking for the location in the parent
+            command = parent.getSoftware().getCommand(name);
+            if (command == null) {
+                command = new Command();
+            }
+            // update the window
+            update();
+        }
+    };
+    // copy
+    private ActionListener copy = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            try {
+                KalumetConsoleApplication.getApplication().setCopyComponent(command.clone());
+            } catch (Exception e) {
+                return;
+            }
+        }
+    };
+    // paste
+    private ActionListener paste = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            Object copy = KalumetConsoleApplication.getApplication().getCopyComponent();
+            if (copy == null || !(copy instanceof Command)) {
+                return;
+            }
+            command = (Command) copy;
+            name = null;
+            parent.update();
+            update();
+        }
+    };
+    // apply
+    private ActionListener apply = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // check if the user has the lock
+            if (!getEnvironmentWindow().getEnvironment().getLock().equals(KalumetConsoleApplication.getApplication().getUserid())) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.locked"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // check if the user can do it
+            if (!getEnvironmentWindow().adminPermission && !getEnvironmentWindow().softwaresPermission) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("action.restricted"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // get the fields value
+            String nameFieldValue = nameField.getText();
+            int activeFieldIndex = activeField.getSelectedIndex();
+            int blockerFieldIndex = blockerField.getSelectedIndex();
+            String commandAreaValue = commandArea.getText();
+            String agentFieldValue = (String) agentField.getSelectedItem();
+            // check fields
+            if (nameFieldValue == null || nameFieldValue.trim().length() < 1
+                    || commandAreaValue == null || commandAreaValue.trim().length() < 1) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("command.mandatory"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            command.setName(nameFieldValue);
+            if (activeFieldIndex == 0) {
+                command.setActive(true);
+            } else {
+                command.setActive(false);
+            }
+            if (blockerFieldIndex == 0) {
+                command.setBlocker(true);
+            } else {
+                command.setBlocker(false);
+            }
+            command.setCommand(commandAreaValue);
+            command.setAgent(agentFieldValue);
+            if (name == null) {
+                try {
+                    parent.getSoftware().addCommand(command);
+                    parent.getParentPane().getEnvironmentWindow().getChangeEvents().add("Add software " + parent.getName() + " command " + name);
+                } catch (Exception e) {
+                    KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("software.component.exists"), getEnvironmentWindow().getEnvironmentName());
+                    return;
+                }
+            }
+            // update window definition
+            setTitle(Messages.getString("location") + " " + command.getName());
+            setId("softwarecommandwindow_" + parent.getParentPane().getEnvironmentWindow().getEnvironmentName() + "_" + parent.getName() + "_" + name);
+            name = command.getName();
+            // change the update flag
+            parent.getParentPane().getEnvironmentWindow().setUpdated(true);
+            // update parent and window
+            parent.update();
+            update();
+        }
+    };
+    // delete
+    private ActionListener delete = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // check if the user has the lock
+            if (!getEnvironmentWindow().getEnvironment().getLock().equals(KalumetConsoleApplication.getApplication().getUserid())) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.locked"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // check if the user can do it
+            if (!getEnvironmentWindow().adminPermission && !getEnvironmentWindow().softwaresPermission) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("action.restricted"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // display confirm window
+            KalumetConsoleApplication.getApplication().getDefaultWindow().getContent().add(new ConfirmWindow(new ActionListener() {
+                public void actionPerformed(ActionEvent event) {
+                    // delete the location
+                    parent.getSoftware().getUpdatePlan().remove(command);
+                    parent.getParentPane().getEnvironmentWindow().getChangeEvents().add("Delete software " + parent.getName() + " command " + name);
+                    parent.getParentPane().getEnvironmentWindow().setUpdated(true);
+                    parent.getParentPane().getEnvironmentWindow().updateJournalPane();
+                    parent.update();
+                    SoftwareCommandWindow.this.userClose();
+                }
+            }));
+        }
+    };
+    // close
+    private ActionListener close = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            SoftwareCommandWindow.this.userClose();
+        }
+    };
+    // execute
+    private ActionListener execute = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // check if the user has the lock
+            if (!getEnvironmentWindow().getEnvironment().getLock().equals(KalumetConsoleApplication.getApplication().getUserid())) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.locked"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // check if the user can do it
+            if (!getEnvironmentWindow().adminPermission && !getEnvironmentWindow().softwaresUpdatePermission) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("action.restricted"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // check if some change has not yet been saved
+            if (getEnvironmentWindow().isUpdated()) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.notsaved"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // display confirm window
+            KalumetConsoleApplication.getApplication().getDefaultWindow().getContent().add(new ConfirmWindow(new ActionListener() {
+                public void actionPerformed(ActionEvent event) {
+                    // add a message into the log pane and the journal
+                    KalumetConsoleApplication.getApplication().getLogPane().addInfo("Software " + parent.getName() + " command " + name + " execution in progress ...", parent.getParentPane().getEnvironmentWindow().getEnvironmentName());
+                    parent.getParentPane().getEnvironmentWindow().getChangeEvents().add("Software " + parent.getName() + " command " + name + " execution requested.");
+                    // start the execute thread
+                    final ExecuteThread executeThread = new ExecuteThread();
+                    executeThread.start();
+                    // sync with the client
+                    KalumetConsoleApplication.getApplication().enqueueTask(KalumetConsoleApplication.getApplication().getTaskQueue(), new Runnable() {
+                        public void run() {
+                            if (executeThread.ended) {
+                                if (executeThread.failure) {
+                                    KalumetConsoleApplication.getApplication().getLogPane().addError(executeThread.message, parent.getParentPane().getEnvironmentWindow().getEnvironmentName());
+                                    parent.getParentPane().getEnvironmentWindow().getChangeEvents().add(executeThread.message);
+                                } else {
+                                    KalumetConsoleApplication.getApplication().getLogPane().addConfirm("Software " + parent.getName() + " command " + name + " executed.", parent.getParentPane().getEnvironmentWindow().getEnvironmentName());
+                                    parent.getParentPane().getEnvironmentWindow().getChangeEvents().add("Software " + parent.getName() + " command " + name + " executed.");
+                                }
+                            } else {
+                                KalumetConsoleApplication.getApplication().enqueueTask(KalumetConsoleApplication.getApplication().getTaskQueue(), this);
+                            }
+                        }
+                    });
+                }
+            }));
+        }
+    };
+
+    /**
+     * Create a software command window.
+     */
+    public SoftwareCommandWindow(SoftwareWindow parent, String name) {
+        super();
+
+        // update parent and command name
+        this.parent = parent;
+        this.name = name;
+
+        // update the command from the parent
+        this.command = parent.getSoftware().getCommand(name);
+        if (this.command == null) {
+            this.command = new Command();
+        }
+
+        if (name == null) {
+            setTitle(Messages.getString("command"));
+        } else {
+            setTitle(Messages.getString("command") + " " + name);
+        }
+        setId("softwarecommandwindow_" + parent.getParentPane().getEnvironmentWindow().getEnvironmentName() + "_" + parent.getName() + "_" + name);
+        setStyleName("default");
+        setWidth(new Extent(500, Extent.PX));
+        setHeight(new Extent(400, Extent.PX));
+        setModal(false);
+        setDefaultCloseOperation(WindowPane.DISPOSE_ON_CLOSE);
+
+        // create the split pane
+        SplitPane splitPane = new SplitPane(SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP, new Extent(32));
+        add(splitPane);
+
+        // add the control row
+        Row controlRow = new Row();
+        controlRow.setStyleName("control");
+        splitPane.add(controlRow);
+        // reload
+        Button reloadButton = new Button(Messages.getString("reload"), Styles.DATABASE_REFRESH);
+        reloadButton.setStyleName("control");
+        reloadButton.addActionListener(refresh);
+        controlRow.add(reloadButton);
+        // copy
+        Button copyButton = new Button(Messages.getString("copy"), Styles.PAGE_COPY);
+        copyButton.setStyleName("control");
+        copyButton.addActionListener(copy);
+        controlRow.add(copyButton);
+        if (getEnvironmentWindow().adminPermission || getEnvironmentWindow().softwaresPermission) {
+            // paste
+            Button pasteButton = new Button(Messages.getString("paste"), Styles.PAGE_PASTE);
+            pasteButton.setStyleName("control");
+            pasteButton.addActionListener(paste);
+            controlRow.add(pasteButton);
+        }
+        if (getEnvironmentWindow().adminPermission || getEnvironmentWindow().softwaresUpdatePermission) {
+            // execute
+            Button executeButton = new Button(Messages.getString("execute"), Styles.COG);
+            executeButton.setStyleName("control");
+            executeButton.addActionListener(execute);
+            controlRow.add(executeButton);
+        }
+        if (getEnvironmentWindow().adminPermission || getEnvironmentWindow().softwaresPermission) {
+            // apply
+            Button applyButton = new Button(Messages.getString("apply"), Styles.ACCEPT);
+            applyButton.setStyleName("control");
+            applyButton.addActionListener(apply);
+            controlRow.add(applyButton);
+            // delete
+            Button deleteButton = new Button(Messages.getString("delete"), Styles.DELETE);
+            deleteButton.setStyleName("control");
+            deleteButton.addActionListener(delete);
+            controlRow.add(deleteButton);
+        }
+        // close
+        Button closeButton = new Button(Messages.getString("close"), Styles.CROSS);
+        closeButton.setStyleName("control");
+        closeButton.addActionListener(close);
+        controlRow.add(closeButton);
+
+        // add the main grid
+        Grid layout = new Grid(2);
+        layout.setStyleName("default");
+        layout.setColumnWidth(0, new Extent(20, Extent.PERCENT));
+        layout.setColumnWidth(1, new Extent(80, Extent.PERCENT));
+        splitPane.add(layout);
+
+        // name
+        Label nameLabel = new Label(Messages.getString("name"));
+        nameLabel.setStyleName("grid.cell");
+        layout.add(nameLabel);
+        nameField = new TextField();
+        nameField.setStyleName("default");
+        nameField.setWidth(new Extent(100, Extent.PERCENT));
+        layout.add(nameField);
+
+        // active
+        Label activeLabel = new Label(Messages.getString("active"));
+        activeLabel.setStyleName("grid.cell");
+        layout.add(activeLabel);
+        activeField = new SelectField(MainScreen.LABELS);
+        activeField.setStyleName("default");
+        activeField.setWidth(new Extent(10, Extent.EX));
+        layout.add(activeField);
+
+        // blocker
+        Label blockerLabel = new Label(Messages.getString("blocker"));
+        blockerLabel.setStyleName("grid.cell");
+        layout.add(blockerLabel);
+        blockerField = new SelectField(MainScreen.LABELS);
+        blockerField.setStyleName("default");
+        blockerField.setWidth(new Extent(10, Extent.EX));
+        layout.add(blockerField);
+
+        // command
+        Label commandLabel = new Label(Messages.getString("command"));
+        commandLabel.setStyleName("grid.cell");
+        layout.add(commandLabel);
+        commandArea = new TextArea();
+        commandArea.setStyleName("default");
+        commandArea.setWidth(new Extent(100, Extent.PERCENT));
+        commandArea.setHeight(new Extent(10, Extent.EX));
+        layout.add(commandArea);
+
+        // agent
+        Label agentLabel = new Label(Messages.getString("agent"));
+        agentLabel.setStyleName("grid.cell");
+        layout.add(agentLabel);
+        agentField = new SelectField();
+        agentField.setStyleName("default");
+        agentField.setWidth(new Extent(50, Extent.EX));
+        layout.add(agentField);
+
+        // update
+        update();
+    }
+
+    /**
+     * Update the window.
+     */
+    public void update() {
+        nameField.setText(command.getName());
+        if (command.isActive()) {
+            activeField.setSelectedIndex(0);
+        } else {
+            activeField.setSelectedIndex(1);
+        }
+        if (command.isBlocker()) {
+            blockerField.setSelectedIndex(0);
+        } else {
+            blockerField.setSelectedIndex(1);
+        }
+        commandArea.setText(command.getCommand());
+        // agent field update
+        Kalumet kalumet;
+        try {
+            kalumet = ConfigurationManager.loadStore();
+
+        } catch (Exception e) {
+            KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("db.read") + ": " + e.getMessage(), parent.getParentPane().getEnvironmentWindow().getEnvironmentName());
+            return;
+        }
+        // update agent list model
+        DefaultListModel agentListModel = (DefaultListModel) agentField.getModel();
+        agentListModel.removeAll();
+        for (Iterator agentIterator = kalumet.getAgents().iterator(); agentIterator.hasNext(); ) {
+            Agent agent = (Agent) agentIterator.next();
+            agentListModel.add(agent.getId());
+        }
+        agentField.setSelectedItem(command.getAgent());
+    }
+
+    public EnvironmentWindow getEnvironmentWindow() {
+        return parent.getParentPane().getEnvironmentWindow();
+    }
+
+}



Mime
View raw message