1 19 package org.lucane.applications.administrator.gui; 20 21 import java.util.*; 22 import java.awt.*; 23 import java.awt.event.*; 24 25 import javax.swing.*; 26 27 import org.lucane.applications.administrator.AdministratorPlugin; 28 import org.lucane.common.concepts.*; 29 30 public class ServicePanel extends JPanel 31 implements MouseListener, ActionListener 32 { 33 private transient AdministratorPlugin plugin; 34 35 private JTextField serviceName; 36 private JCheckBox serviceInstalled; 37 private JTextArea serviceDescription; 38 39 private JButton btnUpdate; 40 private JButton btnRemove; 41 42 private ConceptTable serviceGroups; 43 44 private ConceptPanel panel; 45 46 public ServicePanel(AdministratorPlugin plugin, ConceptPanel panel) 47 { 48 super(new BorderLayout()); 49 this.plugin = plugin; 50 this.panel = panel; 51 52 serviceName = new JTextField(); 54 serviceName.setEnabled(false); 55 serviceInstalled = new JCheckBox(); 56 serviceDescription = new JTextArea(); 57 serviceGroups = new ConceptTable(plugin, tr("groups")); 58 serviceGroups.addMouseListener(this); 59 60 JPanel labels = new JPanel(new GridLayout(2,1)); 62 labels.add(new JLabel(tr("name"))); 63 labels.add(new JLabel(tr("installed"))); 64 65 JPanel fields = new JPanel(new GridLayout(2, 1)); 66 fields.add(serviceName); 67 fields.add(serviceInstalled); 68 69 JPanel nameAndInstalled = new JPanel(new BorderLayout()); 70 nameAndInstalled.add(labels, BorderLayout.WEST); 71 nameAndInstalled.add(fields, BorderLayout.CENTER); 72 73 JPanel description = new JPanel(new BorderLayout()); 75 description.add(new JLabel(tr("description")), BorderLayout.NORTH); 76 description.add(new JScrollPane(serviceDescription), BorderLayout.CENTER); 77 78 JPanel groups = new JPanel(new BorderLayout()); 80 groups.add(new JLabel(tr("groups")), BorderLayout.NORTH); 81 groups.add(new JScrollPane(serviceGroups)); 82 83 JPanel descriptionAndGroups = new JPanel(new GridLayout(2, 1)); 85 descriptionAndGroups.add(description); 86 descriptionAndGroups.add(groups); 87 88 JPanel buttonsContainer = new JPanel(new BorderLayout()); 90 JPanel buttons = new JPanel(new GridLayout(1, 2)); 91 btnRemove = new JButton(tr("btn.remove")); 92 btnRemove.addActionListener(this); 93 buttons.add(btnRemove); 94 btnUpdate = new JButton(tr("btn.save")); 95 btnUpdate.addActionListener(this); 96 buttons.add(btnUpdate); 97 buttonsContainer.add(buttons, BorderLayout.EAST); 98 99 this.add(nameAndInstalled, BorderLayout.NORTH); 101 this.add(descriptionAndGroups, BorderLayout.CENTER); 102 this.add(buttonsContainer, BorderLayout.SOUTH); 103 } 104 105 public void showConcept(ServiceConcept concept) 106 { 107 serviceName.setText(concept.getName()); 108 serviceInstalled.setSelected(concept.isInstalled()); 109 serviceDescription.setText(concept.getDescription()); 110 setGroups(concept); 111 } 112 113 public void setGroups(ServiceConcept service) 114 { 115 ArrayList groups = new ArrayList(); 116 Iterator allGroups = plugin.getAllGroups(false).iterator(); 117 118 while(allGroups.hasNext()) 119 { 120 GroupConcept group = (GroupConcept)allGroups.next(); 121 if(group.hasService(service)) 122 groups.add(group); 123 } 124 125 serviceGroups.setConcepts(groups); 126 } 127 128 private String tr(String s) 129 { 130 return plugin.tr(s); 131 } 132 133 135 public void mouseEntered(MouseEvent e) {} 136 public void mouseExited(MouseEvent e) {} 137 public void mousePressed(MouseEvent e) {} 138 public void mouseReleased(MouseEvent e) {} 139 public void mouseClicked(MouseEvent e) 140 { 141 if(e.getClickCount() < 2) 142 return; 143 144 int row = serviceGroups.getSelectedRow(); 145 if(row < 0) 146 return; 147 148 panel.showConcept(serviceGroups.getConceptAt(row)); 149 } 150 151 public void actionPerformed(ActionEvent ae) 153 { 154 ServiceConcept concept = new ServiceConcept(serviceName.getText(), serviceInstalled.isSelected()); 155 if(ae.getSource() == btnUpdate) 156 { 157 plugin.updateConcept(concept); 158 panel.refresh(); 159 } 160 else if(ae.getSource() == btnRemove) 161 { 162 plugin.removeConcept(concept); 163 panel.refresh(); 164 panel.showConcept(null); 165 } 166 } 167 } | Popular Tags |