From 99eed1e3c7e7292aea91131baeb36f81e23e3e82 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 26 Jun 2012 12:41:11 +0200 Subject: Initial refactor from kernel --- .../java/com/c2kernel/gui/tabs/PropertiesPane.java | 200 +++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 src/main/java/com/c2kernel/gui/tabs/PropertiesPane.java (limited to 'src/main/java/com/c2kernel/gui/tabs/PropertiesPane.java') diff --git a/src/main/java/com/c2kernel/gui/tabs/PropertiesPane.java b/src/main/java/com/c2kernel/gui/tabs/PropertiesPane.java new file mode 100644 index 0000000..4a78581 --- /dev/null +++ b/src/main/java/com/c2kernel/gui/tabs/PropertiesPane.java @@ -0,0 +1,200 @@ +/* + * StatusPane.java + * + * Created on March 20, 2001, 3:30 PM + */ + +package com.c2kernel.gui.tabs; + +/** + * @author abranson + * @version + */ +import java.awt.GridBagConstraints; +import java.awt.GridLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.HashMap; + +import javax.swing.Box; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.SwingConstants; + +import com.c2kernel.entity.proxy.EntityProxyObserver; +import com.c2kernel.entity.proxy.ItemProxy; +import com.c2kernel.entity.proxy.MemberSubscription; +import com.c2kernel.gui.MainFrame; +import com.c2kernel.gui.tree.NodeAgent; +import com.c2kernel.persistency.ClusterStorage; +import com.c2kernel.process.Gateway; +import com.c2kernel.property.Property; +import com.c2kernel.utils.Language; +import com.c2kernel.utils.Logger; + +/** + * Pane to display all work orders that this agent can execute, and activate + * them on request from the user. Subscribes to NodeItem for Property objects. + * @version $Revision: 1.44 $ $Date: 2005/08/31 07:21:20 $ + * @author $Author: abranson $ + */ +public class PropertiesPane extends EntityTabPane implements EntityProxyObserver, ActionListener { + + Box propertyBox; + boolean subbed = false; + HashMap loadedProps = new HashMap(); + JLabel domTitle; + DomainPathAdmin domAdmin; + + public PropertiesPane() { + super("Properties", "Properties"); + initPanel(); + + // Create box container for properties + getGridBagConstraints(); + c.gridx = 0; c.gridy = 1; + c.anchor = GridBagConstraints.NORTHWEST; + c.fill = GridBagConstraints.NONE; + c.weightx = 1.0; c.weighty = 2.0; + propertyBox = Box.createVerticalBox(); + gridbag.setConstraints(propertyBox, c); + add(propertyBox); + if (MainFrame.isAdmin) { // edit dompath + c.gridy++; + c.fill = GridBagConstraints.NONE; + c.weighty=0.0; + domTitle = new JLabel("Domain Paths", titleIcon, SwingConstants.LEFT); + domTitle.setFont(titleFont); + domTitle.setForeground(headingColor); + gridbag.setConstraints(domTitle, c); + add(domTitle); + + c.gridy++; + c.fill = GridBagConstraints.BOTH; + c.weighty=1.0; + domAdmin = new DomainPathAdmin(); + gridbag.setConstraints(domAdmin, c); + add(domAdmin); + + + if ("true".equals(Gateway.getProperty("EnableItemErase"))) { + c.gridy++; + c.fill = GridBagConstraints.NONE; + JButton eraseButton = new JButton(Language.translate("Erase!")); + eraseButton.addActionListener(this); + eraseButton.setActionCommand("Erase Item"); + gridbag.setConstraints(eraseButton, c); + add(eraseButton); + } + } + } + + @Override + public void reload() { + Gateway.getStorage().clearCache(sourceEntity.getSysKey(), ClusterStorage.PROPERTY); + loadedProps = new HashMap(); + initForEntity(sourceEntity); + } + + @Override + public void run() { + Thread.currentThread().setName("Property Pane Builder"); + if (sourceEntity instanceof NodeAgent) { + remove(domAdmin); + remove(domTitle); + } + else if (domAdmin != null) + domAdmin.setEntity((ItemProxy)sourceEntity.getEntity()); + propertyBox.removeAll(); + propertyBox.add(Box.createGlue()); + revalidate(); + sourceEntity.getEntity().subscribe(new MemberSubscription(this, ClusterStorage.PROPERTY, true)); + + } + /** + * + */ + @Override + public void add(Property newProp) { + JLabel propLabel = loadedProps.get(newProp.getName()); + if (propLabel == null) { // new prop + JPanel summaryPanel = new JPanel(new GridLayout(0,2)); + summaryPanel.add(new JLabel(Language.translate(newProp.getName()) + ":")); + Box valueBox = Box.createHorizontalBox(); + propLabel = new JLabel(newProp.getValue()); + loadedProps.put(newProp.getName(), propLabel); + valueBox.add(propLabel); + if (MainFrame.isAdmin) { + JButton editButton = new JButton("..."); + editButton.setMargin(new Insets(0,0,0,0)); + editButton.setActionCommand(newProp.getName()); + editButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e){ + String oldVal = loadedProps.get(e.getActionCommand()).getText(); + String newVal = (String)JOptionPane.showInputDialog(null, "Enter new value for "+e.getActionCommand(), "Edit Property", + JOptionPane.QUESTION_MESSAGE, null, null, oldVal); + if (newVal!=null && !(newVal.equals(oldVal))) { + try { + ((ItemProxy)sourceEntity.getEntity()).setProperty(MainFrame.userAgent, e.getActionCommand(), newVal); + } catch (Exception ex) { + Logger.exceptionDialog(ex); + } + } + } + }); + valueBox.add(Box.createVerticalStrut(7)); + valueBox.add(editButton); + + } + summaryPanel.add(valueBox); + propertyBox.add(Box.createVerticalStrut(7)); + propertyBox.add(summaryPanel); + } + propLabel.setText(newProp.getValue()); + revalidate(); + } + + @Override + public void remove(String id) { + String propName = id.substring(id.lastIndexOf("/")+1); + JLabel propbox = loadedProps.get(propName); + if (propbox!= null) propbox.setText("DELETED"); + revalidate(); + } + + @Override + public void actionPerformed(ActionEvent e) { + String[] params; + String predefStep; + + if (JOptionPane.showConfirmDialog(this, + "Are you sure?", + e.getActionCommand(), + JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) + return; + + if (e.getActionCommand().equals("Erase Item")) { + params = new String[0]; + predefStep = "Erase"; + } + else + return; + + try { + MainFrame.userAgent.execute((ItemProxy)sourceEntity.getEntity(), predefStep, params); + } catch (Exception ex) { + Logger.exceptionDialog(ex); + } + } + + @Override + public void control(String control, String msg) { + // TODO Auto-generated method stub + + } + +} -- cgit v1.2.3