diff options
author | Bernard Normier <bernard@zeroc.com> | 2006-03-29 21:21:02 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2006-03-29 21:21:02 +0000 |
commit | 20744ae1f1182d08e26b175f59d14041aabaf754 (patch) | |
tree | 937d125b80663966b3a61e13e744e28daf1f22da /java/src/IceGridGUI/Application/DbEnvEditor.java | |
parent | Java metadata (diff) | |
download | ice-20744ae1f1182d08e26b175f59d14041aabaf754.tar.bz2 ice-20744ae1f1182d08e26b175f59d14041aabaf754.tar.xz ice-20744ae1f1182d08e26b175f59d14041aabaf754.zip |
IceGrid GUI refactoring
Diffstat (limited to 'java/src/IceGridGUI/Application/DbEnvEditor.java')
-rwxr-xr-x | java/src/IceGridGUI/Application/DbEnvEditor.java | 250 |
1 files changed, 250 insertions, 0 deletions
diff --git a/java/src/IceGridGUI/Application/DbEnvEditor.java b/java/src/IceGridGUI/Application/DbEnvEditor.java new file mode 100755 index 00000000000..fc3db163a09 --- /dev/null +++ b/java/src/IceGridGUI/Application/DbEnvEditor.java @@ -0,0 +1,250 @@ +// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGridGUI.Application;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JFrame;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+
+import com.jgoodies.forms.builder.DefaultFormBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+
+import IceGrid.*;
+import IceGridGUI.*;
+
+class DbEnvEditor extends CommunicatorChildEditor
+{
+ DbEnvEditor(JFrame parentFrame)
+ {
+ _name.getDocument().addDocumentListener(_updateListener);
+ _name.setToolTipText(
+ "Identifies this Freeze database environment within an Ice communicator");
+ _description.getDocument().addDocumentListener(_updateListener);
+ _description.setToolTipText(
+ "An optional description for this database environment");
+
+ JTextField dbHomeTextField = (JTextField)
+ _dbHome.getEditor().getEditorComponent();
+ dbHomeTextField.getDocument().addDocumentListener(_updateListener);
+ _dbHome.setToolTipText("<html><i>node data dir</i>/servers/<i>server id</i>"
+ + "/dbs/<i>db env name</i> if created by the IceGrid Node;<br>"
+ + "otherwise, IceGrid does not create this directory"
+ + "</html>");
+
+
+ _properties.setEditable(false);
+
+ //
+ // _propertiesButton
+ //
+ _propertiesDialog = new TableDialog(parentFrame,
+ "Berkeley DB Configuration Properties",
+ "Name",
+ "Value", true);
+
+ Action openPropertiesDialog = new AbstractAction("...")
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ java.util.Map result =
+ _propertiesDialog.show(_propertiesMap,
+ getProperties());
+ if(result != null)
+ {
+ updated();
+ _propertiesMap = result;
+ setPropertiesField();
+ }
+ }
+ };
+ openPropertiesDialog.putValue(Action.SHORT_DESCRIPTION,
+ "Edit properties");
+ _propertiesButton = new JButton(openPropertiesDialog);
+ }
+
+ void writeDescriptor()
+ {
+ DbEnvDescriptor descriptor =
+ (DbEnvDescriptor)getDbEnv().getDescriptor();
+ descriptor.name = _name.getText();
+ descriptor.description = _description.getText();
+ descriptor.dbHome = getDbHomeAsString();
+ descriptor.properties = Editor.mapToProperties(_propertiesMap);
+ }
+
+ boolean isSimpleUpdate()
+ {
+ DbEnvDescriptor descriptor =
+ (DbEnvDescriptor)getDbEnv().getDescriptor();
+ return descriptor.name.equals(_name.getText());
+ }
+
+ Communicator.ChildList getChildList()
+ {
+ return ((Communicator)_target.getParent()).getDbEnvs();
+ }
+
+ protected void appendProperties(DefaultFormBuilder builder)
+ {
+ builder.append("Name" );
+ builder.append(_name, 3);
+ builder.nextLine();
+
+ builder.append("Description");
+ builder.nextLine();
+ builder.append("");
+ builder.nextRow(-2);
+ CellConstraints cc = new CellConstraints();
+ JScrollPane scrollPane = new JScrollPane(_description);
+ builder.add(scrollPane,
+ cc.xywh(builder.getColumn(), builder.getRow(), 3, 3));
+ builder.nextRow(2);
+ builder.nextLine();
+
+ builder.append("DB Home" );
+ builder.append(_dbHome, 3);
+ builder.nextLine();
+
+ builder.append("Properties");
+ builder.append(_properties, _propertiesButton);
+ builder.nextLine();
+ }
+
+ protected void buildPropertiesPanel()
+ {
+ super.buildPropertiesPanel();
+ _propertiesPanel.setName("Database Environment Properties");
+ }
+
+ void show(DbEnv dbEnv)
+ {
+ detectUpdates(false);
+ _target = dbEnv;
+
+ DbEnvDescriptor descriptor = (DbEnvDescriptor)dbEnv.getDescriptor();
+
+ Utils.Resolver resolver = null;
+ if(dbEnv.getCoordinator().substitute())
+ {
+ resolver = dbEnv.getResolver();
+ }
+ boolean isEditable = dbEnv.isEditable() && resolver == null;
+
+ _name.setText(
+ Utils.substitute(descriptor.name, resolver));
+ _name.setEditable(isEditable);
+
+ _description.setText(
+ Utils.substitute(descriptor.description, resolver));
+ _description.setEditable(isEditable);
+ _description.setOpaque(isEditable);
+
+ _dbHome.setEnabled(true);
+ _dbHome.setEditable(true);
+ setDbHome(Utils.substitute(descriptor.dbHome, resolver));
+ _dbHome.setEnabled(isEditable);
+ _dbHome.setEditable(isEditable);
+
+ _propertiesMap = Editor.propertiesToMap(descriptor.properties, resolver);
+ setPropertiesField();
+ _propertiesButton.setEnabled(isEditable);
+
+ _applyButton.setEnabled(dbEnv.isEphemeral());
+ _discardButton.setEnabled(dbEnv.isEphemeral());
+ detectUpdates(true);
+ }
+
+ private DbEnv getDbEnv()
+ {
+ return (DbEnv)_target;
+ }
+
+ private void setDbHome(String dbHome)
+ {
+ if(dbHome.equals(""))
+ {
+ _dbHome.setSelectedItem(NO_DB_HOME);
+ }
+ else
+ {
+ _dbHome.setSelectedItem(dbHome);
+ }
+ }
+
+ private String getDbHomeAsString()
+ {
+ Object obj = _dbHome.getSelectedItem();
+ if(obj == NO_DB_HOME)
+ {
+ return "";
+ }
+ else
+ {
+ return obj.toString();
+ }
+ }
+
+
+ private void setPropertiesField()
+ {
+ final Utils.Resolver resolver = getDbEnv().getResolver();
+
+ Ice.StringHolder toolTipHolder = new Ice.StringHolder();
+ Utils.Stringifier stringifier = new Utils.Stringifier()
+ {
+ public String toString(Object obj)
+ {
+ java.util.Map.Entry entry = (java.util.Map.Entry)obj;
+
+ return Utils.substitute((String)entry.getKey(), resolver)
+ + "="
+ + Utils.substitute((String)entry.getValue(), resolver);
+ }
+ };
+
+ _properties.setText(
+ Utils.stringify(_propertiesMap.entrySet(), stringifier,
+ ", ", toolTipHolder));
+
+ String toolTip = "<html>Properties used to generate a"
+ + " DB_CONFIG file in the DB home directory";
+ if(toolTipHolder.value != null)
+ {
+ toolTip += ":<br>" + toolTipHolder.value;
+ }
+ toolTip += "</html>";
+
+ _properties.setToolTipText(toolTip);
+ }
+
+ private JTextField _name = new JTextField(20);
+ private JTextArea _description = new JTextArea(3, 20);
+
+ private JComboBox _dbHome = new JComboBox(new Object[]{NO_DB_HOME});
+
+ private JTextField _properties = new JTextField(20);
+ private java.util.Map _propertiesMap;
+ private TableDialog _propertiesDialog;
+ private JButton _propertiesButton = new JButton("...");
+
+ static private final Object NO_DB_HOME = new Object()
+ {
+ public String toString()
+ {
+ return "Created by the IceGrid Node";
+ }
+ };
+}
|