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 [12/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/EnvironmentWindow.java
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/EnvironmentWindow.java?rev=1205585&view=auto
==============================================================================
--- incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/EnvironmentWindow.java (added)
+++ incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/EnvironmentWindow.java Wed Nov 23 20:52:16 2011
@@ -0,0 +1,948 @@
+/*
+ * 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.Date;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import nextapp.echo2.app.Button;
+import nextapp.echo2.app.Extent;
+import nextapp.echo2.app.Row;
+import nextapp.echo2.app.SplitPane;
+import nextapp.echo2.app.WindowPane;
+import nextapp.echo2.app.event.ActionEvent;
+import nextapp.echo2.app.event.ActionListener;
+import nextapp.echo2.extras.app.TabPane;
+import nextapp.echo2.extras.app.layout.TabPaneLayoutData;
+
+import org.apache.commons.lang.time.DateFormatUtils;
+import org.apache.commons.lang.time.FastDateFormat;
+import org.apache.kalumet.console.configuration.ConfigurationManager;
+import org.apache.kalumet.model.Agent;
+import org.apache.kalumet.model.Environment;
+import org.apache.kalumet.model.Kalumet;
+import org.apache.kalumet.model.log.Event;
+import org.apache.kalumet.model.log.Journal;
+import org.apache.kalumet.ws.client.EnvironmentClient;
+
+/**
+ * Environment window.
+ */
+public class EnvironmentWindow extends WindowPane {
+
+    private String environmentName;
+    private Environment environment;
+    private LinkedList changeEvents;
+    private boolean updated = false;
+    private Button lockButton;
+
+    public boolean adminPermission = false;
+    public boolean updatePermission = false;
+    public boolean jeeServersPermission = false;
+    public boolean jeeServersUpdatePermission = false;
+    public boolean jeeServersControlPermission = false;
+    public boolean jeeResourcesPermission = false;
+    public boolean jeeResourcesUpdatePermission = false;
+    public boolean jeeApplicationsPermission = false;
+    public boolean jeeApplicationsUpdatePermission = false;
+    public boolean softwaresPermission = false;
+    public boolean softwaresUpdatePermission = false;
+    public boolean releasePermission = false;
+    public boolean shellPermission = false;
+    public boolean browserPermission = false;
+    public boolean homepagePermission = false;
+
+    private GeneralPane generalPane;
+    private SecurityPane securityPane;
+    private ApplicationServersPane applicationServersPane;
+    private ConnectionPoolsPane connectionPoolsPane;
+    private DataSourcesPane dataSourcesPane;
+    private ConnectionFactoriesPane connectionFactoriesPane;
+    private JmsServersPane jmsServersPane;
+    private NameSpaceBindingsPane nameSpaceBindingsPane;
+    private SharedLibrariesPane sharedLibrariesPane;
+    private ApplicationsPane applicationsPane;
+    private SoftwaresPane softwaresPane;
+    private JournalPane journalPane;
+    private NotifiersPane notifiersPane;
+    private PublishersPane publishersPane;
+    private ActionPane actionPane;
+    private CheckerPane checkerPane;
+    private ShellPane shellPane;
+    private LogViewerPane logViewerPane;
+    private FileBrowserPane fileBrowserane;
+    private StatisticsPane statisticsPane;
+
+    // update thread
+    class UpdateThread 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(environment.getAgent());
+                if (agent == null) {
+                    throw new IllegalArgumentException("agent not found.");
+                }
+                // call the webservice
+                EnvironmentClient client = new EnvironmentClient(agent.getHostname(), agent.getPort());
+                client.update(environmentName);
+            } catch (Exception e) {
+                failure = true;
+                message = "Environment " + environmentName + " update failed: " + e.getMessage();
+            } finally {
+                ended = true;
+            }
+        }
+    }
+
+    // close
+    private ActionListener close = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // if the user is only read-only
+            if (environmentName == null ||
+                    (!adminPermission
+                            && !updatePermission
+                            && !jeeServersPermission
+                            && !jeeServersUpdatePermission
+                            && !jeeServersControlPermission
+                            && !jeeResourcesPermission
+                            && !jeeResourcesUpdatePermission
+                            && !jeeApplicationsPermission
+                            && !jeeApplicationsUpdatePermission
+                            && !softwaresPermission
+                            && !softwaresUpdatePermission
+                            && !releasePermission
+                            && !homepagePermission)) {
+                // only close the window
+                EnvironmentWindow.this.userClose();
+                return;
+            }
+            // check if some changes has been made
+            if (isUpdated()) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.notsaved"), environmentName);
+                return;
+            }
+            // load Kalumet configuration
+            Kalumet kalumet = null;
+            try {
+                kalumet = ConfigurationManager.loadStore();
+            } catch (Exception e) {
+                KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("db.read") + ": " + e.getMessage(), environmentName);
+                return;
+            }
+            // looking for the environment object (updated)
+            Environment current = kalumet.getEnvironment(environmentName);
+            // raise an error if the environment is not found
+            if (current == null) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.notsaved"), environmentName);
+                return;
+            }
+            // check if the user has the lock
+            if (current.getLock().equals(KalumetConsoleApplication.getApplication().getUserid())) {
+                current.setLock("");
+                try {
+                    ConfigurationManager.writeStore(kalumet);
+                } catch (Exception e) {
+                    KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("db.write") + ": " + e.getMessage(), environmentName);
+                    return;
+                }
+            }
+            // close the window
+            EnvironmentWindow.this.userClose();
+        }
+    };
+    // toggle lock
+    private ActionListener toggleLock = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // check if some change has been made
+            if (isUpdated()) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.notsaved"), environmentName);
+                return;
+            }
+            // load Kalumet configuration
+            Kalumet kalumet;
+            try {
+                kalumet = ConfigurationManager.loadStore();
+            } catch (Exception e) {
+                KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("db.read") + ": " + e.getMessage(), environmentName);
+                return;
+            }
+            // get the environment object (updated)
+            Environment current = kalumet.getEnvironment(environmentName);
+            // raise an error if the environment is not found
+            if (current == null) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.notsaved"), environmentName);
+                return;
+            }
+            // if the lock is free, take it if I can
+            if ((adminPermission
+                    || updatePermission
+                    || jeeServersPermission
+                    || jeeServersUpdatePermission
+                    || jeeServersControlPermission
+                    || jeeResourcesPermission
+                    || jeeResourcesUpdatePermission
+                    || jeeApplicationsPermission
+                    || jeeApplicationsUpdatePermission
+                    || softwaresPermission
+                    || softwaresUpdatePermission
+                    || releasePermission
+                    || homepagePermission) && (current.getLock() == null || current.getLock().trim().length() < 1)) {
+                current.setLock(KalumetConsoleApplication.getApplication().getUserid());
+                environment = current;
+                EnvironmentWindow.this.setTitle(Messages.getString("environment") + " " + environmentName + " (" + Messages.getString("locked.by") + " " + environment.getLock() + ")");
+                try {
+                    ConfigurationManager.writeStore(kalumet);
+                } catch (Exception e) {
+                    KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("db.write") + ": " + e.getMessage(), environmentName);
+                    return;
+                }
+                // update the view
+                update();
+                return;
+            }
+            // if the user has the lock, toggle to unlock
+            if (KalumetConsoleApplication.getApplication().getUserid().equals("admin") || current.getLock().equals(KalumetConsoleApplication.getApplication().getUserid())) {
+                current.setLock("");
+                environment = current;
+                EnvironmentWindow.this.setTitle(Messages.getString("environment") + " " + environmentName);
+                try {
+                    ConfigurationManager.writeStore(kalumet);
+                } catch (Exception e) {
+                    KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("db.write") + ": " + e.getMessage(), environmentName);
+                    return;
+                }
+                // update the view
+                update();
+                return;
+            }
+        }
+    };
+    // refresh
+    private ActionListener refresh = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // load Kalumet configuration
+            Kalumet kalumet = null;
+            try {
+                kalumet = ConfigurationManager.loadStore();
+            } catch (Exception e) {
+                KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("db.read") + ": " + e.getMessage(), environmentName);
+                return;
+            }
+            // looking for the environment in Kalumet
+            environment = kalumet.getEnvironment(environmentName);
+            if (environment == null) {
+                environment = new Environment();
+                environment.setLock(KalumetConsoleApplication.getApplication().getUserid());
+            }
+            // change the updated flag
+            setUpdated(false);
+            // reinit the change events
+            changeEvents = new LinkedList();
+            // update the window
+            update();
+        }
+    };
+    // save
+    private ActionListener save = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // check if the user has the environment lock
+            if (!environment.getLock().equals(KalumetConsoleApplication.getApplication().getUserid())) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.locked"), environmentName);
+                return;
+            }
+            // get fields value
+            String nameFieldValue = generalPane.getNameField().getText();
+            String groupFieldValue = generalPane.getGroupField().getText();
+            String tagFieldValue = (String) generalPane.getTagField().getSelectedItem();
+            String agentFieldValue = (String) generalPane.getAgentField().getSelectedItem();
+            int autoUpdateFieldIndex = generalPane.getAutoUpdateField().getSelectedIndex();
+            String notesAreaValue = generalPane.getNotesArea().getText();
+            String weblinksAreaValue = generalPane.getWeblinksArea().getText();
+            int applicationServersTopologyFieldIndex = applicationServersPane.getTopologyField().getSelectedIndex();
+            String notifierCountDownFieldValue = notifiersPane.getCountDownField().getText();
+            // check fields
+            if (nameFieldValue == null || nameFieldValue.trim().length() < 1 || groupFieldValue == null || groupFieldValue.trim().length() < 1) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.mandatory"), environmentName);
+                return;
+            }
+            // check if the count down is a integer
+            int notifierCountDownInt;
+            try {
+                notifierCountDownInt = new Integer(notifierCountDownFieldValue).intValue();
+            } catch (Exception e) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("notifier.warn.countdown"), environmentName);
+                notifierCountDownInt = 0;
+            }
+            // load the journal
+            Journal journal = null;
+            try {
+                journal = ConfigurationManager.loadEnvironmentJournal(environmentName);
+            } catch (Exception e) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("journal.warn.read") + ": " + e.getMessage(), environmentName);
+                return;
+            }
+            // load Kalumet configuration
+            Kalumet kalumet = null;
+            try {
+                kalumet = ConfigurationManager.loadStore();
+            } catch (Exception e) {
+                KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("db.read") + ": " + e.getMessage(), environmentName);
+                return;
+            }
+            // if the user change the environment name, check if the name is not
+            // already in used
+            if (environmentName == null || (environmentName != null && !environmentName.equals(nameFieldValue))) {
+                if (kalumet.getEnvironment(nameFieldValue) != null) {
+                    KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("environment.exists"), environmentName);
+                    return;
+                }
+            }
+            // add a change event
+            if (environmentName != null && !environmentName.equals(nameFieldValue)) {
+                getChangeEvents().add("Change environment name.");
+            }
+            // update the environment
+            environment.setName(nameFieldValue);
+            environment.setGroup(groupFieldValue);
+            environment.setTag(tagFieldValue);
+            environment.setAgent(agentFieldValue);
+            if (autoUpdateFieldIndex == 0) {
+                environment.setAutoupdate(true);
+            } else {
+                environment.setAutoupdate(false);
+            }
+            environment.setNotes(notesAreaValue);
+            environment.setWeblinks(weblinksAreaValue);
+            if (applicationServersTopologyFieldIndex == 0) {
+                environment.getJ2EEApplicationServers().setCluster(false);
+            } else {
+                environment.getJ2EEApplicationServers().setCluster(true);
+            }
+            environment.getNotifiers().setCountdown(notifierCountDownInt);
+            // looking for the environment
+            Environment toupdate = kalumet.getEnvironment(environmentName);
+            if (toupdate == null || environmentName == null) {
+                // add the environment object if needed
+                try {
+                    kalumet.addEnvironment(environment);
+                } catch (Exception e) {
+                    KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.exists"), environmentName);
+                    return;
+                }
+            } else {
+                // update the environment
+                int index = kalumet.getEnvironments().indexOf(toupdate);
+                kalumet.getEnvironments().set(index, environment);
+            }
+            // save the configuration
+            try {
+                ConfigurationManager.writeStore(kalumet);
+            } catch (Exception e) {
+                KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("db.write") + ": " + e.getMessage(), environmentName);
+                return;
+            }
+            // update the window definition
+            if (environment.getLock() == null || environment.getLock().trim().length() < 1) {
+                setTitle(Messages.getString("environment") + " " + environment.getName());
+            } else {
+                setTitle(Messages.getString("environment") + " " + environment.getName() + " (" + Messages.getString("locked.by") + " " + environment.getLock() + ")");
+            }
+            setId("environmentwindow_" + environment.getName());
+            environmentName = environment.getName();
+            // add change events in the journal
+            for (Iterator eventIterator = getChangeEvents().iterator(); eventIterator.hasNext(); ) {
+                String eventMessage = (String) eventIterator.next();
+                Event journalEvent = new Event();
+                journalEvent.setDate(((FastDateFormat) DateFormatUtils.ISO_DATETIME_FORMAT).format(new Date()));
+                journalEvent.setSeverity("INFO");
+                journalEvent.setAuthor(KalumetConsoleApplication.getApplication().getUserid());
+                journalEvent.setContent(eventMessage);
+                journal.addEvent(journalEvent);
+            }
+            // save the journal
+            try {
+                journal.writeXMLFile(ConfigurationManager.getEnvironmentJournalFile(environmentName));
+            } catch (Exception e) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("journal.warn.save") + ": " + e.getMessage(), environmentName);
+                return;
+            }
+            // update the updated flag
+            setUpdated(false);
+            // update the change events
+            changeEvents = new LinkedList();
+            // update the environments pane
+            KalumetConsoleApplication.getApplication().getEnvironmentsPane().update();
+            // update the window
+            update();
+            // add a confirm
+            KalumetConsoleApplication.getApplication().getLogPane().addConfirm(Messages.getString("environment.saved"), environmentName);
+        }
+    };
+    // copy
+    private ActionListener copy = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            try {
+                KalumetConsoleApplication.getApplication().setCopyComponent(environment.clone());
+            } catch (Exception e) {
+                return;
+            }
+        }
+    };
+    // paste
+    private ActionListener paste = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            Object copy = KalumetConsoleApplication.getApplication().getCopyComponent();
+            // check the copy object
+            if (copy == null || !(copy instanceof Environment)) {
+                return;
+            }
+            environment = (Environment) copy;
+            environment.setLock(KalumetConsoleApplication.getApplication().getUserid());
+            environmentName = null;
+            // update the window
+            update();
+        }
+    };
+    // delete
+    private ActionListener delete = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // check if the user has the environment lock
+            if (!environment.getLock().equals(KalumetConsoleApplication.getApplication().getUserid())) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.locked"), environmentName);
+                return;
+            }
+            // display confirm window
+            KalumetConsoleApplication.getApplication().getDefaultWindow().getContent().add(new ConfirmWindow(new ActionListener() {
+                public void actionPerformed(ActionEvent event) {
+                    // load Kalumet configuration
+                    Kalumet kalumet = null;
+                    try {
+                        kalumet = ConfigurationManager.loadStore();
+                    } catch (Exception e) {
+                        KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("db.read") + ": " + e.getMessage(), environmentName);
+                        return;
+                    }
+                    // looking for the delete object
+                    Environment delete = kalumet.getEnvironment(environmentName);
+                    kalumet.getEnvironments().remove(delete);
+                    // save configuration
+                    try {
+                        ConfigurationManager.writeStore(kalumet);
+                    } catch (Exception e) {
+                        KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("db.write") + ": " + e.getMessage(), environmentName);
+                        return;
+                    }
+                    // update the environments pane
+                    KalumetConsoleApplication.getApplication().getEnvironmentsPane().update();
+                    // close the window
+                    EnvironmentWindow.this.userClose();
+                }
+            }));
+        }
+    };
+    // update
+    private ActionListener update = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // check if the user has the lock
+            if (!environment.getLock().equals(KalumetConsoleApplication.getApplication().getUserid())) {
+                KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("environment.locked"), environmentName);
+                return;
+            }
+            // check if something has not been saved
+            if (isUpdated()) {
+                KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("environment.notsaved"), environmentName);
+                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("Environment " + environmentName + " update in progress...", environmentName);
+                    getChangeEvents().add("Update requested.");
+                    // start the update thread
+                    final UpdateThread updateThread = new UpdateThread();
+                    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, environmentName);
+                                    getChangeEvents().add(updateThread.message);
+                                } else {
+                                    KalumetConsoleApplication.getApplication().getLogPane().addConfirm("Environment " + environmentName + " updated.", environmentName);
+                                    getChangeEvents().add("Update completed successfully.");
+                                }
+                            } else {
+                                KalumetConsoleApplication.getApplication().enqueueTask(KalumetConsoleApplication.getApplication().getTaskQueue(), this);
+                            }
+                        }
+                    });
+                }
+            }));
+        }
+    };
+
+    /**
+     * Create a new <code>EnvironmentWindow</code>.
+     *
+     * @param environmentName the environment name.
+     */
+    public EnvironmentWindow(String environmentName) {
+        super();
+
+        this.environmentName = environmentName;
+
+        // init the change events
+        this.changeEvents = new LinkedList();
+
+        // init the updated flag
+        this.updated = false;
+
+        // load Kalumet configuration
+        Kalumet kalumet = null;
+        try {
+            kalumet = ConfigurationManager.loadStore();
+        } catch (Exception e) {
+            KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("db.read") + ": " + e.getMessage());
+            return;
+        }
+
+        // update the environment object from Kalumet
+        this.environment = kalumet.getEnvironment(environmentName);
+        if (this.environment == null) {
+            this.environment = new Environment();
+            this.environment.setLock(KalumetConsoleApplication.getApplication().getUserid());
+            this.adminPermission = true;
+        }
+
+        // check if the user has access to the environment
+        if (environmentName != null) {
+            // update permission flags
+            adminPermission = kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), "admin");
+            updatePermission = kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), "update");
+            jeeServersPermission = kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), "jee_servers");
+            jeeServersUpdatePermission = kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), "jee_servers_update");
+            jeeServersControlPermission = kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), "jee_servers_control");
+            jeeResourcesPermission = kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), "jee_resources");
+            jeeResourcesUpdatePermission = kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), "jee_resources_update");
+            jeeApplicationsPermission = kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), "jee_applications");
+            jeeApplicationsUpdatePermission = kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), "jee_applications_update");
+            softwaresPermission = kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), "softwares");
+            softwaresUpdatePermission = kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), "softwares_update");
+            releasePermission = kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), "release");
+            shellPermission = kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), "shell");
+            browserPermission = kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), "browser");
+            homepagePermission = kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), "homepage");
+
+            // check user permission on the environment
+            if (!kalumet.getSecurity().checkEnvironmentUserAccess(this.environment, KalumetConsoleApplication.getApplication().getUserid(), null)) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.restricted"), this.environmentName);
+                return;
+            }
+        } else {
+            adminPermission = true;
+        }
+
+        // try to take the environment lock (if the user can)
+        if ((adminPermission
+                || updatePermission
+                || jeeServersPermission
+                || jeeServersUpdatePermission
+                || jeeServersControlPermission
+                || jeeResourcesPermission
+                || jeeResourcesUpdatePermission
+                || jeeApplicationsPermission
+                || jeeApplicationsUpdatePermission
+                || softwaresPermission
+                || softwaresUpdatePermission
+                || releasePermission
+                || homepagePermission) && (this.environment.getLock() == null || this.environment.getLock().trim().length() < 1)) {
+            // lock the environment (but not yet saved)
+            this.environment.setLock(KalumetConsoleApplication.getApplication().getUserid());
+            // save the lock if required
+            if (environmentName != null) {
+                try {
+                    ConfigurationManager.writeStore(kalumet);
+                } catch (Exception e) {
+                    KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("db.write") + ": " + e.getMessage());
+                    return;
+                }
+            }
+        }
+
+        if (environmentName == null) {
+            setTitle(Messages.getString("environment"));
+        } else {
+            if (environment.getLock() == null || environment.getLock().trim().length() < 1) {
+                setTitle(Messages.getString("environment") + " " + environmentName);
+            } else {
+                setTitle(Messages.getString("environment") + " " + environmentName + " (" + Messages.getString("locked.by") + " " + this.environment.getLock() + ")");
+            }
+        }
+        setId("environmentwindow_" + environmentName);
+        setIcon(Styles.APPLICATION);
+        setStyleName("environment");
+        setModal(false);
+
+        SplitPane splitPane = new SplitPane(SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP, new Extent(32));
+        this.add(splitPane);
+
+        // add the control pane
+        Row controlRow = new Row();
+        controlRow.setStyleName("control");
+        splitPane.add(controlRow);
+        // add the refresh button
+        Button refreshButton = new Button(Messages.getString("reload"), Styles.DATABASE_REFRESH);
+        refreshButton.setStyleName("control");
+        refreshButton.setToolTipText(Messages.getString("reload"));
+        refreshButton.addActionListener(refresh);
+        controlRow.add(refreshButton);
+        // add the copy button
+        Button copyButton = new Button(Messages.getString("copy"), Styles.PAGE_COPY);
+        copyButton.setStyleName("control");
+        copyButton.setToolTipText(Messages.getString("copy"));
+        copyButton.addActionListener(copy);
+        controlRow.add(copyButton);
+        if (this.adminPermission
+                || this.jeeServersPermission
+                || this.jeeResourcesPermission
+                || this.jeeApplicationsPermission
+                || this.softwaresPermission
+                || this.releasePermission) {
+            // add the paste button
+            Button pasteButton = new Button(Messages.getString("paste"), Styles.PAGE_PASTE);
+            pasteButton.setStyleName("control");
+            pasteButton.setToolTipText(Messages.getString("paste"));
+            pasteButton.addActionListener(paste);
+            controlRow.add(pasteButton);
+            // add the save button
+            Button saveButton = new Button(Messages.getString("save"), Styles.DATABASE_SAVE);
+            saveButton.setStyleName("control");
+            saveButton.setToolTipText(Messages.getString("save"));
+            saveButton.addActionListener(save);
+            controlRow.add(saveButton);
+        }
+        // add the force unlock button if the user has the lock
+        if (this.adminPermission
+                || this.updatePermission
+                || this.jeeServersPermission
+                || this.jeeServersControlPermission
+                || this.jeeServersUpdatePermission
+                || this.jeeResourcesPermission
+                || this.jeeResourcesUpdatePermission
+                || this.jeeApplicationsPermission
+                || this.jeeApplicationsUpdatePermission
+                || this.softwaresPermission
+                || this.softwaresUpdatePermission
+                || this.releasePermission
+                || this.homepagePermission) {
+            lockButton = new Button(Styles.LOCK);
+            lockButton.addActionListener(toggleLock);
+            updateLockButton();
+            lockButton.setStyleName("control");
+            controlRow.add(lockButton);
+        }
+        if (this.adminPermission || this.updatePermission) {
+            // add the update button
+            Button updateButton = new Button(Messages.getString("update"), Styles.COG);
+            updateButton.setToolTipText(Messages.getString("update"));
+            updateButton.addActionListener(update);
+            updateButton.setStyleName("control");
+            controlRow.add(updateButton);
+        }
+        if (this.adminPermission) {
+            // add the delete button
+            Button deleteButton = new Button(Messages.getString("delete"), Styles.APPLICATION_DELETE);
+            deleteButton.setToolTipText(Messages.getString("delete"));
+            deleteButton.setStyleName("control");
+            deleteButton.addActionListener(delete);
+            controlRow.add(deleteButton);
+        }
+        // add the close button
+        Button closeButton = new Button(Messages.getString("close"), Styles.CROSS);
+        closeButton.setStyleName("control");
+        closeButton.addActionListener(close);
+        controlRow.add(closeButton);
+
+        // add the main tab pane
+        TabPane tabPane = new TabPane();
+        tabPane.setStyleName("default");
+        splitPane.add(tabPane);
+
+        // add the environment general tab
+        TabPaneLayoutData tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("general"));
+        generalPane = new GeneralPane(this);
+        generalPane.setLayoutData(tabLayoutData);
+        tabPane.add(generalPane);
+
+        // add the environment security tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("security"));
+        securityPane = new SecurityPane(this);
+        securityPane.setLayoutData(tabLayoutData);
+        tabPane.add(securityPane);
+
+        // add the environment jee application servers tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("applicationservers"));
+        applicationServersPane = new ApplicationServersPane(this);
+        applicationServersPane.setLayoutData(tabLayoutData);
+        tabPane.add(applicationServersPane);
+
+        // add the ressource tab pane
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("resources"));
+        TabPane resourcesPane = new TabPane();
+        resourcesPane.setStyleName("default");
+        resourcesPane.setLayoutData(tabLayoutData);
+        tabPane.add(resourcesPane);
+
+        // add the jdbc connection pools tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("connectionpools"));
+        connectionPoolsPane = new ConnectionPoolsPane(this);
+        connectionPoolsPane.setLayoutData(tabLayoutData);
+        resourcesPane.add(connectionPoolsPane);
+
+        // add the jdbc data sources tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("datasources"));
+        dataSourcesPane = new DataSourcesPane(this);
+        dataSourcesPane.setLayoutData(tabLayoutData);
+        resourcesPane.add(dataSourcesPane);
+
+        // add the jms connection factories tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("connectionfactories"));
+        connectionFactoriesPane = new ConnectionFactoriesPane(this);
+        connectionFactoriesPane.setLayoutData(tabLayoutData);
+        resourcesPane.add(connectionFactoriesPane);
+
+        // add the jms servers tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("jmsservers"));
+        jmsServersPane = new JmsServersPane(this);
+        jmsServersPane.setLayoutData(tabLayoutData);
+        resourcesPane.add(jmsServersPane);
+
+        // add the jndi name space bindings tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("namespacebindings"));
+        nameSpaceBindingsPane = new NameSpaceBindingsPane(this);
+        nameSpaceBindingsPane.setLayoutData(tabLayoutData);
+        resourcesPane.add(nameSpaceBindingsPane);
+
+        // add the shared librairies tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("sharedlibraries"));
+        sharedLibrariesPane = new SharedLibrariesPane(this);
+        sharedLibrariesPane.setLayoutData(tabLayoutData);
+        resourcesPane.add(sharedLibrariesPane);
+
+        // add the j2ee applications tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("applications"));
+        applicationsPane = new ApplicationsPane(this);
+        applicationsPane.setLayoutData(tabLayoutData);
+        tabPane.add(applicationsPane);
+
+        // add the softwares tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("softwares"));
+        softwaresPane = new SoftwaresPane(this);
+        softwaresPane.setLayoutData(tabLayoutData);
+        tabPane.add(softwaresPane);
+
+        // add the journal log tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("journal"));
+        journalPane = new JournalPane(this);
+        journalPane.setLayoutData(tabLayoutData);
+        tabPane.add(journalPane);
+
+        // add the notifiers tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("notifier"));
+        notifiersPane = new NotifiersPane(this);
+        notifiersPane.setLayoutData(tabLayoutData);
+        tabPane.add(notifiersPane);
+
+        // add the publishers tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("publisher"));
+        publishersPane = new PublishersPane(this);
+        publishersPane.setLayoutData(tabLayoutData);
+        tabPane.add(publishersPane);
+
+        // add the actions tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("dashboard"));
+        TabPane dashboardPane = new TabPane();
+        dashboardPane.setStyleName("default");
+        dashboardPane.setLayoutData(tabLayoutData);
+        tabPane.add(dashboardPane);
+
+        // add the updater action tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("control"));
+        actionPane = new ActionPane(this);
+        actionPane.setLayoutData(tabLayoutData);
+        dashboardPane.add(actionPane);
+
+        // add the checker tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("check"));
+        checkerPane = new CheckerPane(this);
+        checkerPane.setLayoutData(tabLayoutData);
+        dashboardPane.add(checkerPane);
+
+        if (adminPermission || shellPermission) {
+            // add the system launcher tab
+            tabLayoutData = new TabPaneLayoutData();
+            tabLayoutData.setTitle(Messages.getString("shell"));
+            shellPane = new ShellPane(this);
+            shellPane.setLayoutData(tabLayoutData);
+            dashboardPane.add(shellPane);
+        }
+
+        if (adminPermission || browserPermission) {
+            // add the file explorer tab
+            tabLayoutData = new TabPaneLayoutData();
+            tabLayoutData.setTitle(Messages.getString("file.browser"));
+            fileBrowserane = new FileBrowserPane(this);
+            fileBrowserane.setLayoutData(tabLayoutData);
+            dashboardPane.add(fileBrowserane);
+        }
+
+        // add the log viewer tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("logs.viewer"));
+        logViewerPane = new LogViewerPane(this);
+        logViewerPane.setLayoutData(tabLayoutData);
+        dashboardPane.add(logViewerPane);
+
+        // add the statistics tab
+        tabLayoutData = new TabPaneLayoutData();
+        tabLayoutData.setTitle(Messages.getString("stats"));
+        statisticsPane = new StatisticsPane(this);
+        statisticsPane.setLayoutData(tabLayoutData);
+        dashboardPane.add(statisticsPane);
+    }
+
+    /**
+     * Get the environment linked with the window
+     *
+     * @return the <code>Environment</code> linked with the window
+     */
+    public Environment getEnvironment() {
+        return this.environment;
+    }
+
+    /**
+     * Get the environment name
+     *
+     * @return the current <code>Environment</code> name
+     */
+    public String getEnvironmentName() {
+        return this.environmentName;
+    }
+
+    /**
+     * Get the change events list
+     *
+     * @return the change events list
+     */
+    public List getChangeEvents() {
+        return this.changeEvents;
+    }
+
+    /**
+     * Get the updated flag
+     *
+     * @return the updated flag
+     */
+    public boolean isUpdated() {
+        return this.updated;
+    }
+
+    /**
+     * Set the updated flag
+     *
+     * @param updated the new updated flag value
+     */
+    public void setUpdated(boolean updated) {
+        this.updated = updated;
+    }
+
+    /**
+     * Update the lock button (display lock or unlock depending of the state)
+     */
+    public void updateLockButton() {
+        // if the lock is taken by the user
+        if (environmentName != null &&
+                (environment.getLock().equals(KalumetConsoleApplication.getApplication().getUserid()) || KalumetConsoleApplication.getApplication().getUserid().equals("admin"))) {
+            lockButton.setText(Messages.getString("unlock"));
+        } else {
+            lockButton.setText(Messages.getString("lock"));
+        }
+    }
+
+    /**
+     * Update the complete <code>EnvironmentWindow</code> with all children tab.
+     */
+    public void update() {
+        generalPane.update();
+        securityPane.update();
+        applicationServersPane.update();
+        connectionPoolsPane.update();
+        dataSourcesPane.update();
+        connectionFactoriesPane.update();
+        jmsServersPane.update();
+        nameSpaceBindingsPane.update();
+        sharedLibrariesPane.update();
+        applicationsPane.update();
+        checkerPane.update();
+        softwaresPane.update();
+        journalPane.update();
+        notifiersPane.update();
+        publishersPane.update();
+        actionPane.update();
+        logViewerPane.update();
+        this.updateLockButton();
+    }
+
+    /**
+     * Only update the <code>EnvironmentJournalLogTabPane</code>
+     */
+    public void updateJournalPane() {
+        journalPane.update();
+    }
+
+}
\ No newline at end of file

Added: incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/EnvironmentsPane.java
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/EnvironmentsPane.java?rev=1205585&view=auto
==============================================================================
--- incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/EnvironmentsPane.java (added)
+++ incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/EnvironmentsPane.java Wed Nov 23 20:52:16 2011
@@ -0,0 +1,112 @@
+/*
+ * 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.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import nextapp.echo2.app.Button;
+import nextapp.echo2.app.Column;
+import nextapp.echo2.app.ContentPane;
+import nextapp.echo2.app.event.ActionEvent;
+import nextapp.echo2.app.event.ActionListener;
+import nextapp.echo2.extras.app.AccordionPane;
+import nextapp.echo2.extras.app.layout.AccordionPaneLayoutData;
+import org.apache.kalumet.console.configuration.ConfigurationManager;
+import org.apache.kalumet.model.Environment;
+import org.apache.kalumet.model.Kalumet;
+
+/**
+ * Display the list of environments organized by groups.
+ */
+public class EnvironmentsPane extends ContentPane {
+
+    private AccordionPane mainPane;
+
+    // edit
+    private ActionListener edit = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            String environmentName = event.getActionCommand();
+            if (KalumetConsoleApplication.getApplication().getDefaultWindow().getContent().getComponent("environmentwindow_" + environmentName) == null) {
+                KalumetConsoleApplication.getApplication().getDefaultWindow().getContent().add(new EnvironmentWindow(environmentName));
+            }
+        }
+    };
+
+    /**
+     * Create a new environments <code>AccordionPane</code>.
+     */
+    public EnvironmentsPane() {
+        super();
+        mainPane = new AccordionPane();
+        mainPane.setStyleName("environments");
+        add(mainPane);
+        update();
+    }
+
+    /**
+     * Update the pane.
+     */
+    public void update() {
+        // load Kalumet configuration
+        Kalumet kalumet = null;
+        try {
+            kalumet = ConfigurationManager.loadStore();
+        } catch (Exception e) {
+            KalumetConsoleApplication.getApplication().getLogPane().addError(Messages.getString("db.read") + ": " + e.getMessage());
+            return;
+        }
+
+        // get user environments by groups
+        Map userEnvironments = kalumet.getUserEnvironmentsByGroups(KalumetConsoleApplication.getApplication().getUserid());
+
+        // remove all
+        mainPane.removeAll();
+
+        // render environment groups
+        List groups = new LinkedList(userEnvironments.keySet());
+        Collections.sort(groups);
+        for (Iterator groupIterator = groups.iterator(); groupIterator.hasNext(); ) {
+            String group = (String) groupIterator.next();
+            Column groupColumn = new Column();
+            groupColumn.setStyleName("environments");
+            AccordionPaneLayoutData layoutData = new AccordionPaneLayoutData();
+            // define the layoutData as the column layout
+            groupColumn.setLayoutData(layoutData);
+            // display the group
+            layoutData.setTitle(group);
+            // add the column to the pane
+            mainPane.add(groupColumn);
+            List environments = (List) userEnvironments.get(group);
+            Collections.sort(environments);
+            for (Iterator environmentIterator = environments.iterator(); environmentIterator.hasNext(); ) {
+                Environment environment = (Environment) environmentIterator.next();
+                Button environmentButton = new Button(environment.getName());
+                environmentButton.setStyleName("default");
+                environmentButton.setActionCommand(environment.getName());
+                environmentButton.addActionListener(edit);
+                groupColumn.add(environmentButton);
+            }
+        }
+    }
+
+}
\ No newline at end of file

Added: incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/ErrorWindow.java
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/ErrorWindow.java?rev=1205585&view=auto
==============================================================================
--- incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/ErrorWindow.java (added)
+++ incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/ErrorWindow.java Wed Nov 23 20:52:16 2011
@@ -0,0 +1,80 @@
+/*
+ * 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.Label;
+import nextapp.echo2.app.Row;
+import nextapp.echo2.app.SplitPane;
+import nextapp.echo2.app.WindowPane;
+import nextapp.echo2.app.event.ActionEvent;
+import nextapp.echo2.app.event.ActionListener;
+
+/**
+ * Error window.
+ */
+public class ErrorWindow extends WindowPane {
+
+    /**
+     * Create a new <code>WindowPane</code> with the error message and the
+     * exception stack trace.
+     *
+     * @param message the error message to display.
+     * @param details the error detailed message.
+     */
+    public ErrorWindow(String message, String details) {
+        super();
+
+        setTitle(message);
+        setStyleName("error");
+        setIcon(Styles.EXCLAMATION);
+        setModal(true);
+
+        // define the split pane containing control row
+        SplitPane splitPane = new SplitPane(SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP, new Extent(32));
+        add(splitPane);
+
+        // define the control row
+        Row controlRow = new Row();
+        controlRow.setStyleName("control");
+        splitPane.add(controlRow);
+
+        // define the close button
+        Button closeButton = new Button(Messages.getString("close"), Styles.CROSS);
+        closeButton.setStyleName("control");
+        closeButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                ErrorWindow.this.userClose();
+            }
+        });
+        controlRow.add(closeButton);
+
+        // define a content pane
+        ContentPane contentPane = new ContentPane();
+        splitPane.add(contentPane);
+
+        // define the details
+        Label detailsLabel = new Label(details);
+        detailsLabel.setStyleName("error");
+        contentPane.add(detailsLabel);
+    }
+
+}
\ No newline at end of file

Added: incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/FileBrowserPane.java
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/FileBrowserPane.java?rev=1205585&view=auto
==============================================================================
--- incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/FileBrowserPane.java (added)
+++ incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/FileBrowserPane.java Wed Nov 23 20:52:16 2011
@@ -0,0 +1,210 @@
+/*
+ * 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.text.SimpleDateFormat;
+
+import nextapp.echo2.app.Button;
+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.SplitPane;
+import nextapp.echo2.app.TextField;
+import nextapp.echo2.app.event.ActionEvent;
+import nextapp.echo2.app.event.ActionListener;
+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.FileClient;
+import org.apache.kalumet.ws.client.SimplifiedFileObject;
+
+/**
+ * File browser pane.
+ */
+public class FileBrowserPane extends ContentPane {
+
+    private EnvironmentWindow parent;
+    private TextField pathField;
+    private Grid grid;
+
+    // view
+    private ActionListener view = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            String path = event.getActionCommand();
+            KalumetConsoleApplication.getApplication().getDefaultWindow().getContent().add(new ViewFileWindow(path, parent.getEnvironment().getAgent()));
+        }
+    };
+    // browse
+    private ActionListener browse = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            if (event != null && event.getActionCommand() != null) {
+                pathField.setText(event.getActionCommand());
+            }
+
+            update();
+        }
+    };
+
+    /**
+     * Create a new <code>FileBrowserPane</code>.
+     *
+     * @param parent the parent <code>EnvironmentWindow</code>.
+     */
+    public FileBrowserPane(EnvironmentWindow parent) {
+        super();
+        this.setStyleName("tab.content");
+
+        // update the parent
+        this.parent = parent;
+
+        SplitPane content = new SplitPane(SplitPane.ORIENTATION_VERTICAL_TOP_BOTTOM, new Extent(20));
+        add(content);
+
+        Row browseRow = new Row();
+        browseRow.setCellSpacing(new Extent(2));
+        browseRow.setInsets(new Insets(2));
+        content.add(browseRow);
+        pathField = new TextField();
+        pathField.setStyleName("default");
+        pathField.setText("/");
+        pathField.addActionListener(browse);
+        browseRow.add(pathField);
+        Button browseButton = new Button(Messages.getString("browse"), Styles.ACCEPT);
+        browseButton.addActionListener(browse);
+        browseRow.add(browseButton);
+
+        grid = new Grid(5);
+        grid.setStyleName("border.grid");
+        grid.setColumnWidth(0, new Extent(50, Extent.PX));
+        content.add(grid);
+
+        // empty header
+        // action header
+        Label actionHeader = new Label(" ");
+        actionHeader.setStyleName("grid.header");
+        grid.add(actionHeader);
+        // name header
+        Label nameHeader = new Label(Messages.getString("name"));
+        nameHeader.setStyleName("grid.header");
+        grid.add(nameHeader);
+        // path header
+        Label pathHeader = new Label(Messages.getString("path"));
+        pathHeader.setStyleName("grid.header");
+        grid.add(pathHeader);
+        // permission header
+        Label fileModeHeader = new Label(Messages.getString("size"));
+        fileModeHeader.setStyleName("grid.header");
+        grid.add(fileModeHeader);
+        // modification data header
+        Label fileModificationHeader = new Label(Messages.getString("last.modification.date"));
+        fileModificationHeader.setStyleName("grid.header");
+        grid.add(fileModificationHeader);
+    }
+
+    /**
+     * Update the pane.
+     */
+    public void update() {
+        // check path file value
+        String path = pathField.getText();
+        if (path == null || path.trim().length() < 1) {
+            return;
+        }
+
+        // cleanup the grid
+        grid.removeAll();
+        // action header
+        Label actionHeader = new Label(" ");
+        actionHeader.setStyleName("grid.header");
+        grid.add(actionHeader);
+        // name header
+        Label nameHeader = new Label(Messages.getString("name"));
+        nameHeader.setStyleName("grid.header");
+        grid.add(nameHeader);
+        // path header
+        Label pathHeader = new Label(Messages.getString("path"));
+        pathHeader.setStyleName("grid.header");
+        grid.add(pathHeader);
+        // permission header
+        Label fileModeHeader = new Label(Messages.getString("size"));
+        fileModeHeader.setStyleName("grid.header");
+        grid.add(fileModeHeader);
+        // modification data header
+        Label fileModificationHeader = new Label(Messages.getString("last.modification.date"));
+        fileModificationHeader.setStyleName("grid.header");
+        grid.add(fileModificationHeader);
+
+        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
+            FileClient client = new FileClient(agent.getHostname(), agent.getPort());
+            SimplifiedFileObject[] files = client.browse(path);
+            for (int i = 0; i < files.length; i++) {
+                SimplifiedFileObject file = files[i];
+                // actions
+                Row actionRow = new Row();
+                if (file.isFile()) {
+                    Button viewButton = new Button(Styles.INFORMATION);
+                    viewButton.setToolTipText(Messages.getString("view"));
+                    viewButton.setActionCommand(file.getPath());
+                    viewButton.addActionListener(view);
+                    actionRow.add(viewButton);
+                } else {
+                    Button browseButton = new Button(Styles.FOLDER_EXPLORE);
+                    browseButton.setToolTipText(Messages.getString("browse"));
+                    browseButton.setActionCommand(file.getPath());
+                    browseButton.addActionListener(browse);
+                    actionRow.add(browseButton);
+                }
+                grid.add(actionRow);
+                // file name
+                Button fileName = new Button(file.getName());
+                fileName.setActionCommand(file.getPath());
+                if (file.isFile()) {
+                    fileName.addActionListener(view);
+                } else {
+                    fileName.addActionListener(browse);
+                }
+                grid.add(fileName);
+                // file path
+                Label filePath = new Label(file.getPath());
+                grid.add(filePath);
+                // file size
+                Label fileSize = new Label(file.getSize() + " bytes");
+                grid.add(fileSize);
+                // file date
+                SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy HH:mm");
+                Label fileDate = new Label(dateFormatter.format(file.getLastModificationDate()));
+                grid.add(fileDate);
+            }
+        } catch (Exception e) {
+            KalumetConsoleApplication.getApplication().getLogPane().addError("Browsing " + path + " error: " + e.getMessage(), parent.getEnvironmentName());
+        }
+    }
+
+}
\ No newline at end of file



Mime
View raw message