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 [11/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/ConnectionPoolsPane.java
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/ConnectionPoolsPane.java?rev=1205585&view=auto
==============================================================================
--- incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/ConnectionPoolsPane.java (added)
+++ incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/ConnectionPoolsPane.java Wed Nov 23 20:52:16 2011
@@ -0,0 +1,559 @@
+/*
+ * 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.event.ActionEvent;
+import nextapp.echo2.app.event.ActionListener;
+import nextapp.echo2.app.list.DefaultListModel;
+import nextapp.echo2.app.list.ListModel;
+import org.apache.kalumet.console.configuration.ConfigurationManager;
+import org.apache.kalumet.model.Agent;
+import org.apache.kalumet.model.J2EEApplicationServer;
+import org.apache.kalumet.model.JDBCConnectionPool;
+import org.apache.kalumet.model.Kalumet;
+import org.apache.kalumet.ws.client.JDBCConnectionPoolClient;
+
+/**
+ * Environment JDBC connection pools pane.
+ */
+public class ConnectionPoolsPane extends ContentPane {
+
+    private EnvironmentWindow parent;
+    private SelectField scopeField;
+    private Grid grid;
+
+    // status thread
+    class StatusThread extends Thread {
+
+        public String connectionPoolName;
+        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 web service
+                JDBCConnectionPoolClient client = new JDBCConnectionPoolClient(agent.getHostname(), agent.getPort());
+                boolean uptodate = client.check(parent.getEnvironmentName(), (String) scopeField.getSelectedItem(), connectionPoolName);
+                if (uptodate) {
+                    message = "JDBC connection pool " + connectionPoolName + " is up to date.";
+                } else {
+                    failure = true;
+                    message = "JDBC connection pool " + connectionPoolName + " is not up to date.";
+                }
+            } catch (Exception e) {
+                failure = true;
+                message = "JDBC connection pool " + connectionPoolName + " status failed: " + e.getMessage();
+            } finally {
+                ended = true;
+            }
+        }
+
+    }
+
+    // update thread
+    class UpdateThread extends Thread {
+
+        public String connectionPoolName;
+        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 web service
+                JDBCConnectionPoolClient client = new JDBCConnectionPoolClient(agent.getHostname(), agent.getPort());
+                client.update(parent.getEnvironmentName(), (String) scopeField.getSelectedItem(), connectionPoolName);
+            } catch (Exception e) {
+                failure = true;
+                message = "JDBC Connection pool " + connectionPoolName + " update failed: " + e.getMessage();
+            } finally {
+                ended = true;
+            }
+        }
+
+    }
+
+    // scope select
+    private ActionListener scopeSelect = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            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 JDBC connection pool object
+            final JDBCConnectionPool connectionPool = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeField.getSelectedItem()).getJDBCConnectionPool(event.getActionCommand());
+            if (connectionPool == null) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("connectionpool.notfound"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // display confirm window
+            KalumetConsoleApplication.getApplication().getDefaultWindow().getContent().add(new ConfirmWindow(new ActionListener() {
+                public void actionPerformed(ActionEvent event) {
+                    // delete the connection pool
+                    parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeField.getSelectedItem()).getJDBCConnectionPools().remove(connectionPool);
+                    // add change event and update the log pane
+                    parent.getChangeEvents().add("Delete JDBC connection pool " + connectionPool.getName());
+                    // change the updated flag
+                    parent.setUpdated(true);
+                    // update the whole window
+                    parent.update();
+                }
+            }));
+        }
+    };
+    // 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 JDBC connection pool name
+            final String connectionPoolName = event.getActionCommand();
+            // put a message in the log pane and in the journal
+            KalumetConsoleApplication.getApplication().getLogPane().addInfo("JDBC connection pool " + connectionPoolName + " status check in progress...", parent.getEnvironmentName());
+            parent.getChangeEvents().add("JDBC connection pool " + connectionPoolName + " status check.");
+            // start the status thread
+            final StatusThread statusThread = new StatusThread();
+            statusThread.connectionPoolName = connectionPoolName;
+            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 log
+            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.restricited"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // check if something has been changed
+            if (getEnvironmentWindow().isUpdated()) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.notsaved"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // get JDBC connection pool name
+            final String connectionPoolName = event.getActionCommand();
+            // display confirm window
+            KalumetConsoleApplication.getApplication().getDefaultWindow().getContent().add(new ConfirmWindow(new ActionListener() {
+                public void actionPerformed(ActionEvent event) {
+                    // put a message in the log pane and the journal
+                    KalumetConsoleApplication.getApplication().getLogPane().addInfo("JDBC connection pool " + connectionPoolName + " update in progress...");
+                    parent.getChangeEvents().add("JDBC connection pool " + connectionPoolName + " update requested.");
+                    // start the update thread
+                    final UpdateThread updateThread = new UpdateThread();
+                    updateThread.connectionPoolName = connectionPoolName;
+                    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("JDBC connection pool " + connectionPoolName + " updated.", parent.getEnvironmentName());
+                                    parent.getChangeEvents().add("JDBC connection pool " + connectionPoolName + " updated.");
+                                }
+                            } else {
+                                KalumetConsoleApplication.getApplication().enqueueTask(KalumetConsoleApplication.getApplication().getTaskQueue(), this);
+                            }
+                        }
+                    });
+                }
+            }));
+        }
+    };
+    // edit
+    private ActionListener edit = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            if (KalumetConsoleApplication.getApplication().getDefaultWindow().getContent().getComponent("connectionpoolwindow_" + parent.getEnvironmentName() + "_" + (String) scopeField.getSelectedItem() + "_" + event.getActionCommand()) == null) {
+                KalumetConsoleApplication.getApplication().getDefaultWindow().getContent().add(new ConnectionPoolWindow(ConnectionPoolsPane.this, (String) scopeField.getSelectedItem(), event.getActionCommand()));
+            }
+        }
+    };
+    // create
+    private ActionListener create = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            ListModel listModel = scopeField.getModel();
+            if (listModel.size() == 0) {
+                return;
+            }
+            KalumetConsoleApplication.getApplication().getDefaultWindow().getContent().add(new ConnectionPoolWindow(ConnectionPoolsPane.this, (String) scopeField.getSelectedItem(), null));
+        }
+    };
+    // 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.restricited"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // looking for the connection pool object
+            JDBCConnectionPool connectionPool = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeField.getSelectedItem()).getJDBCConnectionPool(event.getActionCommand());
+            if (connectionPool == null) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("connectionpool.notfound"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // change the connection pool state and add a change event
+            if (connectionPool.isActive()) {
+                connectionPool.setActive(false);
+                parent.getChangeEvents().add("Disable JDBC connection pool " + connectionPool.getName());
+            } else {
+                connectionPool.setActive(true);
+                parent.getChangeEvents().add("Enable JDBC connection pool " + connectionPool.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 connection pool object
+            JDBCConnectionPool connectionPool = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeField.getSelectedItem()).getJDBCConnectionPool(event.getActionCommand());
+            if (connectionPool == null) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("connectionpool.notfound"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // change the connection pool blocker state and add a change event
+            if (connectionPool.isBlocker()) {
+                connectionPool.setBlocker(false);
+                parent.getChangeEvents().add("Set not blocker for JDBC connection pool " + connectionPool.getName());
+            } else {
+                connectionPool.setBlocker(true);
+                parent.getChangeEvents().add("Set blocker for JDBC connection pool " + connectionPool.getName());
+            }
+            // 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 connection pool object
+            JDBCConnectionPool connectionPool = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeField.getSelectedItem()).getJDBCConnectionPool(event.getActionCommand());
+            if (connectionPool == null) {
+                return;
+            }
+            try {
+                KalumetConsoleApplication.getApplication().setCopyComponent(connectionPool.clone());
+            } catch (Exception e) {
+                return;
+            }
+        }
+    };
+
+    /**
+     * Create a new <code>ConnectionPoolsPane</code>.
+     *
+     * @param parent the parent <code>EnvironmentWindow</code>.
+     */
+    public ConnectionPoolsPane(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 applicationServerScope = new Label(Messages.getString("scope"));
+        applicationServerScope.setStyleName("default");
+        layoutGrid.add(applicationServerScope);
+        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 the create button
+        if (getEnvironmentWindow().adminPermission
+                || getEnvironmentWindow().jeeResourcesPermission) {
+            Button createButton = new Button(Messages.getString("connectionpool.add"), Styles.ADD);
+            createButton.addActionListener(create);
+            content.add(createButton);
+        }
+
+        // add JDBC connection pools grid
+        grid = new Grid(5);
+        grid.setStyleName("border.grid");
+        grid.setColumnWidth(0, new Extent(50, Extent.PX));
+        content.add(grid);
+
+        // update
+        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 index = 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 = index;
+            }
+            index++;
+        }
+        // remove all JDBC connection pools grid children
+        grid.removeAll();
+        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 JDBC connection pools 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 typeHeader = new Label(Messages.getString("type"));
+        typeHeader.setStyleName("grid.header");
+        grid.add(typeHeader);
+        Label userHeader = new Label(Messages.getString("user"));
+        userHeader.setStyleName("grid.header");
+        grid.add(userHeader);
+        Label urlHeader = new Label(Messages.getString("url"));
+        urlHeader.setStyleName("grid.header");
+        grid.add(urlHeader);
+
+        // add the jdbc connection pools
+        for (Iterator jdbcConnectionPoolIterator = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer(applicationServerName).getJDBCConnectionPools().iterator(); jdbcConnectionPoolIterator.hasNext(); ) {
+            JDBCConnectionPool connectionPool = (JDBCConnectionPool) jdbcConnectionPoolIterator.next();
+            // name and actions
+            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(connectionPool.getName());
+            copyButton.addActionListener(copy);
+            row.add(copyButton);
+            // active
+            Button activeButton;
+            if (connectionPool.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(connectionPool.getName());
+                activeButton.addActionListener(toggleActive);
+            }
+            row.add(activeButton);
+            // blocker
+            Button blockerButton;
+            if (connectionPool.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(connectionPool.getName());
+                blockerButton.addActionListener(toggleBlocker);
+            }
+            row.add(blockerButton);
+            // status
+            Button statusButton = new Button(Styles.INFORMATION);
+            statusButton.setToolTipText(Messages.getString("status"));
+            statusButton.setActionCommand(connectionPool.getName());
+            statusButton.addActionListener(status);
+            row.add(statusButton);
+            // update
+            if (getEnvironmentWindow().adminPermission
+                    || getEnvironmentWindow().jeeResourcesUpdatePermission) {
+                Button updateButton = new Button(Styles.COG);
+                updateButton.setToolTipText(Messages.getString("update"));
+                updateButton.setActionCommand(connectionPool.getName());
+                updateButton.addActionListener(update);
+                row.add(updateButton);
+            }
+            // delete
+            if (getEnvironmentWindow().adminPermission
+                    || getEnvironmentWindow().jeeResourcesPermission) {
+                Button deleteButton = new Button(Styles.DELETE);
+                deleteButton.setToolTipText(Messages.getString("delete"));
+                deleteButton.setActionCommand(connectionPool.getName());
+                deleteButton.addActionListener(delete);
+                row.add(deleteButton);
+            }
+            // name
+            Button connectionPoolName = new Button(connectionPool.getName());
+            connectionPoolName.setActionCommand(connectionPool.getName());
+            connectionPoolName.addActionListener(edit);
+            grid.add(connectionPoolName);
+            // connection pool type (driver)
+            Label connectionPoolType = new Label(connectionPool.getDriver());
+            connectionPoolType.setStyleName("default");
+            grid.add(connectionPoolType);
+            // connection pool user
+            Label connectionPoolUser = new Label(connectionPool.getUser());
+            connectionPoolUser.setStyleName("default");
+            grid.add(connectionPoolUser);
+            // connection pool url
+            Label connectionPoolUrl = new Label(connectionPool.getUrl());
+            connectionPoolUrl.setStyleName("default");
+            grid.add(connectionPoolUrl);
+        }
+    }
+
+    /**
+     * Get the environment window
+     *
+     * @return the parent <code>EnvironmentWindow</code>
+     */
+    public EnvironmentWindow getEnvironmentWindow() {
+        return parent;
+    }
+
+}
\ No newline at end of file

Added: incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/DataSourcesPane.java
URL: http://svn.apache.org/viewvc/incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/DataSourcesPane.java?rev=1205585&view=auto
==============================================================================
--- incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/DataSourcesPane.java (added)
+++ incubator/kalumet/trunk/console/src/main/java/org/apache/kalumet/console/app/DataSourcesPane.java Wed Nov 23 20:52:16 2011
@@ -0,0 +1,746 @@
+/*
+ * 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 nextapp.echo2.app.list.ListModel;
+import org.apache.kalumet.console.configuration.ConfigurationManager;
+import org.apache.kalumet.model.*;
+import org.apache.kalumet.ws.client.JDBCDataSourceClient;
+
+/**
+ * Environment JDBC data sources pane.
+ */
+public class DataSourcesPane extends ContentPane {
+
+    private EnvironmentWindow parent;
+    private SelectField scopeSelectField;
+    private Grid grid;
+    private boolean newIsActive = true;
+    private boolean newIsBlocker = false;
+    private TextField newNameField;
+    private SelectField newConnectionPoolField;
+
+    // status thread
+    class StatusThread extends Thread {
+
+        public String datasourceName;
+        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 IllegalStateException("agent not found.");
+                }
+                // call the web service
+                JDBCDataSourceClient client = new JDBCDataSourceClient(agent.getHostname(), agent.getPort());
+                boolean ok = client.check(parent.getEnvironmentName(), (String) scopeSelectField.getSelectedItem(), datasourceName);
+                if (ok) {
+                    message = "JDBC data source " + datasourceName + " up to date.";
+                } else {
+                    message = "JDBC data source " + datasourceName + " is not up to date.";
+                }
+            } catch (Exception e) {
+                failure = true;
+                message = "JDBC data source " + datasourceName + " status check failed: " + e.getMessage();
+            } finally {
+                ended = true;
+            }
+        }
+
+    }
+
+    // update thread
+    class UpdateThread extends Thread {
+
+        public String datasourceName;
+        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 IllegalStateException("agent not found.");
+                }
+                // call the web service
+                JDBCDataSourceClient client = new JDBCDataSourceClient(agent.getHostname(), agent.getPort());
+                client.update(parent.getEnvironmentName(), (String) scopeSelectField.getSelectedItem(), datasourceName);
+            } catch (Exception e) {
+                failure = true;
+                message = "JDBC data source " + datasourceName + " update failed: " + e.getMessage();
+            } finally {
+                ended = true;
+            }
+        }
+
+    }
+
+    // scope select
+    private ActionListener scopeSelect = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            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 data source name
+            String dataSourceName = event.getActionCommand();
+            // get the field
+            TextField nameField = (TextField) DataSourcesPane.this.getComponent("dsname_" + parent.getEnvironmentName() + "_" + (String) scopeSelectField.getSelectedItem() + "_" + dataSourceName);
+            SelectField connectionPoolField = (SelectField) DataSourcesPane.this.getComponent("dspool_" + parent.getEnvironmentName() + "_" + (String) scopeSelectField.getSelectedItem() + "_" + dataSourceName);
+            // check if the user has selected a pool in the select field
+            if (connectionPoolField.getSelectedIndex() < 0) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("datasource.noconnectionpool"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // get values
+            String nameFieldValue = nameField.getText();
+            String connectionPoolFieldValue = (String) connectionPoolField.getSelectedItem();
+            // check mandatory fields
+            if (nameFieldValue == null || nameFieldValue.trim().length() < 1 || connectionPoolFieldValue == null || connectionPoolFieldValue.trim().length() < 1) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("datasource.mandatory"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // if the user change the data source name, check if the data source
+            // name is not already in use
+            if (!dataSourceName.equals(nameFieldValue)) {
+                if (getEnvironmentWindow().getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeSelectField.getSelectedItem()).getJDBCDataSource(nameFieldValue) != null) {
+                    KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("datasource.exists"), getEnvironmentWindow().getEnvironmentName());
+                    return;
+                }
+            }
+            // looking for the data source object
+            JDBCDataSource dataSource = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeSelectField.getSelectedItem()).getJDBCDataSource(dataSourceName);
+            if (dataSource == null) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("datasource.notfound"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // add a change event
+            parent.getChangeEvents().add("Change JDBC data source " + dataSource.getName() + " / " + dataSource.getPool());
+            // change the data source object
+            dataSource.setName(nameFieldValue);
+            dataSource.setPool(connectionPoolFieldValue);
+            // change the updated flag
+            parent.setUpdated(true);
+            // update the journal log tab pane
+            parent.updateJournalPane();
+            // update only the pane
+            update();
+        }
+    };
+    // create
+    private ActionListener create = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // check if the use 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;
+            }
+            // check if the pool is selected
+            ListModel listModel = newConnectionPoolField.getModel();
+            if (listModel.size() == 0 || newConnectionPoolField.getSelectedIndex() < 0) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("datasource.noconnectionpool"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            String newConnectionPoolFieldValue = (String) newConnectionPoolField.getSelectedItem();
+            String newNameFieldValue = newNameField.getText();
+            // mandatory field
+            if (newConnectionPoolFieldValue == null || newConnectionPoolFieldValue.trim().length() < 1 || newNameFieldValue == null || newNameFieldValue.trim().length() < 1) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("datasource.mandatory"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // create the new data source
+            JDBCDataSource dataSource = new JDBCDataSource();
+            dataSource.setName(newNameFieldValue);
+            dataSource.setPool(newConnectionPoolFieldValue);
+            dataSource.setActive(newIsActive);
+            // add the data source
+            try {
+                parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeSelectField.getSelectedItem()).addJDBCDataSource(dataSource);
+            } catch (Exception e) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("datasource.exists"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // add a change event
+            parent.getChangeEvents().add("Create JDBC data source " + dataSource.getName() + " / " + dataSource.getPool());
+            // change the updated flag
+            parent.setUpdated(true);
+            // update the journal log tab pane
+            parent.updateJournalPane();
+            // update only 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 data source
+            final JDBCDataSource dataSource = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeSelectField.getSelectedItem()).getJDBCDataSource(event.getActionCommand());
+            if (dataSource == null) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("datasource.notfound"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // display confirm window
+            KalumetConsoleApplication.getApplication().getDefaultWindow().getContent().add(new ConfirmWindow(new ActionListener() {
+                public void actionPerformed(ActionEvent event) {
+                    // remove the data source
+                    parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeSelectField.getSelectedItem()).getJDBCDataSources().remove(dataSource);
+                    // add a change event
+                    parent.getChangeEvents().add("Delete JDBC data source " + dataSource.getName());
+                    // change the updated flag
+                    parent.setUpdated(true);
+                    // update the journal log tab pane
+                    parent.updateJournalPane();
+                    // update only the pane
+                    update();
+                }
+            }));
+        }
+    };
+    // 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 JDBC data source name
+            final String datasourceName = event.getActionCommand();
+            // put a message into the log panel and in the journal
+            KalumetConsoleApplication.getApplication().getLogPane().addInfo("JDBC data source " + datasourceName + " status check in progress...", parent.getEnvironmentName());
+            parent.getChangeEvents().add("JDBC data source " + datasourceName + " status check.");
+            // start the status thread
+            final StatusThread statusThread = new StatusThread();
+            statusThread.datasourceName = datasourceName;
+            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 something has been changed
+            if (getEnvironmentWindow().isUpdated()) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("environment.notsaved"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // get the data source name
+            final String datasourceName = event.getActionCommand();
+            // display confirm window
+            KalumetConsoleApplication.getApplication().getDefaultWindow().getContent().add(new ConfirmWindow(new ActionListener() {
+                public void actionPerformed(ActionEvent event) {
+                    // put a message in the log pane and in the journal
+                    KalumetConsoleApplication.getApplication().getLogPane().addInfo("JDBC data source " + datasourceName + " update in progress...", parent.getEnvironmentName());
+                    parent.getChangeEvents().add("JDBC data source " + datasourceName + " update requested.");
+                    // start the update thread
+                    final UpdateThread updateThread = new UpdateThread();
+                    updateThread.datasourceName = datasourceName;
+                    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("JDBC data source " + datasourceName + " updated.", parent.getEnvironmentName());
+                                    parent.getChangeEvents().add("JDBC data source " + datasourceName + " updated.");
+                                }
+                            } else {
+                                KalumetConsoleApplication.getApplication().enqueueTask(KalumetConsoleApplication.getApplication().getTaskQueue(), this);
+                            }
+                        }
+                    });
+                }
+            }));
+        }
+    };
+    // 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 data source object
+            JDBCDataSource dataSource = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeSelectField.getSelectedItem()).getJDBCDataSource(event.getActionCommand());
+            if (dataSource == null) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("datasource.notfound"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // change the data source state and add a change event
+            if (dataSource.isActive()) {
+                dataSource.setActive(false);
+                parent.getChangeEvents().add("Disable JDBC data source " + dataSource.getName());
+            } else {
+                dataSource.setActive(true);
+                parent.getChangeEvents().add("Enable JDBC data source " + dataSource.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 data source object
+            JDBCDataSource dataSource = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeSelectField.getSelectedItem()).getJDBCDataSource(event.getActionCommand());
+            if (dataSource == null) {
+                KalumetConsoleApplication.getApplication().getLogPane().addWarning(Messages.getString("datasource.notfound"), getEnvironmentWindow().getEnvironmentName());
+                return;
+            }
+            // change the data source blocker state and add a change event
+            if (dataSource.isBlocker()) {
+                dataSource.setBlocker(false);
+                parent.getChangeEvents().add("Set Not blocker for JDBC data source " + dataSource.getName());
+            } else {
+                dataSource.setBlocker(true);
+                parent.getChangeEvents().add("Set blocker for JDBC data source " + dataSource.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();
+        }
+    };
+    // copy
+    private ActionListener copy = new ActionListener() {
+        public void actionPerformed(ActionEvent event) {
+            // looking for the connection pool object
+            JDBCDataSource dataSource = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer((String) scopeSelectField.getSelectedItem()).getJDBCDataSource(event.getActionCommand());
+            if (dataSource == null) {
+                return;
+            }
+            try {
+                KalumetConsoleApplication.getApplication().setCopyComponent(dataSource.clone());
+            } 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 JDBCDataSource)) {
+                return;
+            }
+            // update the new fields
+            newNameField.setText(((JDBCDataSource) copy).getName());
+            DefaultListModel listModel = (DefaultListModel) newConnectionPoolField.getModel();
+            newConnectionPoolField.setSelectedIndex(0);
+            for (int i = 0; i < listModel.size(); i++) {
+                String poolName = (String) listModel.get(i);
+                if (((JDBCDataSource) copy).getPool().equals(poolName)) {
+                    newConnectionPoolField.setSelectedIndex(i);
+                }
+            }
+        }
+    };
+
+    /**
+     * Create a new <code>DataSourcesPane</code>.
+     *
+     * @param parent the parent <code>EnvironmentWindow</code>.
+     */
+    public DataSourcesPane(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 scope = new Label(Messages.getString("scope"));
+        scope.setStyleName("default");
+        layoutGrid.add(scope);
+        scopeSelectField = new SelectField();
+        scopeSelectField.addActionListener(scopeSelect);
+        scopeSelectField.setStyleName("default");
+        layoutGrid.add(scopeSelectField);
+        DefaultListModel scopeListModel = (DefaultListModel) scopeSelectField.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) {
+            scopeSelectField.setSelectedIndex(0);
+        }
+
+        // add JDBC data sources 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) scopeSelectField.getModel();
+        if (scopeListModel.size() > 0) {
+            applicationServerName = (String) scopeSelectField.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 JDBC data sources 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) {
+            scopeSelectField.setSelectedIndex(0);
+        } else {
+            scopeSelectField.setSelectedIndex(found);
+        }
+        // update the application server name from the scope (in case of
+        // application server deletion)
+        applicationServerName = (String) scopeSelectField.getSelectedItem();
+
+        Label dataSourceActionHeader = new Label(" ");
+        dataSourceActionHeader.setStyleName("grid.header");
+        grid.add(dataSourceActionHeader);
+        Label dataSourceNameHeader = new Label(Messages.getString("name"));
+        dataSourceNameHeader.setStyleName("grid.header");
+        grid.add(dataSourceNameHeader);
+        Label dataSourcePoolHeader = new Label(Messages.getString("connectionpool"));
+        dataSourcePoolHeader.setStyleName("grid.header");
+        grid.add(dataSourcePoolHeader);
+        // add the jdbc data sources
+        for (Iterator jdbcDataSourceIterator = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer(applicationServerName).getJDBCDataSources().iterator(); jdbcDataSourceIterator.hasNext(); ) {
+            JDBCDataSource dataSource = (JDBCDataSource) jdbcDataSourceIterator.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(dataSource.getName());
+            copyButton.addActionListener(copy);
+            row.add(copyButton);
+            // active
+            Button activeButton;
+            if (dataSource.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(dataSource.getName());
+                activeButton.addActionListener(toggleActive);
+            }
+            row.add(activeButton);
+            // blocker
+            Button blockerButton;
+            if (dataSource.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(dataSource.getName());
+                blockerButton.addActionListener(toggleBlocker);
+            }
+            row.add(blockerButton);
+            // status
+            Button statusButton = new Button(Styles.INFORMATION);
+            statusButton.setToolTipText(Messages.getString("status"));
+            statusButton.setActionCommand(dataSource.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(dataSource.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(dataSource.getName());
+                editButton.addActionListener(edit);
+                row.add(editButton);
+                // delete
+                Button deleteButton = new Button(Styles.DELETE);
+                deleteButton.setToolTipText(Messages.getString("delete"));
+                deleteButton.setActionCommand(dataSource.getName());
+                deleteButton.addActionListener(delete);
+                row.add(deleteButton);
+            }
+            // name
+            TextField dataSourceName = new TextField();
+            dataSourceName.setStyleName("default");
+            dataSourceName.setWidth(new Extent(100, Extent.PERCENT));
+            dataSourceName.setId("dsname_" + parent.getEnvironmentName() + "_" + applicationServerName + "_" + dataSource.getName());
+            dataSourceName.setText(dataSource.getName());
+            grid.add(dataSourceName);
+            // data source pool
+            SelectField dataSourcePool = new SelectField();
+            dataSourcePool.setStyleName("default");
+            dataSourcePool.setWidth(new Extent(100, Extent.PERCENT));
+            dataSourcePool.setId("dspool_" + parent.getEnvironmentName() + "_" + applicationServerName + "_" + dataSource.getName());
+            DefaultListModel listModel = (DefaultListModel) dataSourcePool.getModel();
+            listModel.removeAll();
+            for (Iterator poolIterator = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer(applicationServerName).getJDBCConnectionPools().iterator(); poolIterator.hasNext(); ) {
+                JDBCConnectionPool pool = (JDBCConnectionPool) poolIterator.next();
+                listModel.add(pool.getName());
+            }
+            dataSourcePool.setSelectedItem(dataSource.getPool());
+            grid.add(dataSourcePool);
+        }
+
+        // add create data source row in the JDBC data sources grid
+        if (getEnvironmentWindow().adminPermission || getEnvironmentWindow().jeeResourcesPermission) {
+            // row
+            Row row = new Row();
+            row.setInsets(new Insets(2));
+            row.setCellSpacing(new Extent(2));
+            grid.add(row);
+            // paste
+            Button pasteButton = new Button(Styles.PAGE_PASTE);
+            pasteButton.setToolTipText(Messages.getString("paste"));
+            pasteButton.addActionListener(paste);
+            row.add(pasteButton);
+            // 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);
+            // 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);
+            // connection pool
+            newConnectionPoolField = new SelectField();
+            newConnectionPoolField.setStyleName("default");
+            newConnectionPoolField.setWidth(new Extent(100, Extent.PERCENT));
+            DefaultListModel listModel = (DefaultListModel) newConnectionPoolField.getModel();
+            listModel.removeAll();
+            for (Iterator poolIterator = parent.getEnvironment().getJ2EEApplicationServers().getJ2EEApplicationServer(applicationServerName).getJDBCConnectionPools().iterator(); poolIterator.hasNext(); ) {
+                JDBCConnectionPool pool = (JDBCConnectionPool) poolIterator.next();
+                listModel.add(pool.getName());
+            }
+            grid.add(newConnectionPoolField);
+        }
+    }
+
+    public EnvironmentWindow getEnvironmentWindow() {
+        return parent;
+    }
+
+}
\ No newline at end of file



Mime
View raw message