1 19 package org.openharmonise.him.serverconfig; 20 21 import java.awt.*; 22 import java.awt.event.*; 23 24 import javax.swing.*; 25 26 import org.openharmonise.him.*; 27 import org.openharmonise.him.editors.preview.*; 28 import org.openharmonise.him.harmonise.*; 29 import org.openharmonise.him.swing.resourcetree.*; 30 import org.openharmonise.vfs.*; 31 import org.openharmonise.vfs.metadata.*; 32 import org.openharmonise.vfs.servers.ServerList; 33 import org.w3c.dom.*; 34 import org.xml.sax.*; 35 36 37 43 public class PagePreviewConfigOptions extends AbstractPreviewConfigOptions 44 implements TreeViewListener, LayoutManager, ActionListener, 45 MouseListener { 46 47 private int m_nHeight = 30; 48 49 private ResourceTree m_pageTree = null; 50 51 private JButton m_addButton = null; 52 53 private JButton m_removeButton = null; 54 55 private JButton m_editButton = null; 56 57 private JSpinner m_spinner = null; 58 59 private JTextArea m_dialogLabel = null; 60 61 private JTextArea m_pageLabel = null; 62 63 private JTextArea m_stateLabel = null; 64 65 private JList m_stateList = null; 66 67 private StateContainer m_stateContainer = null; 68 69 private StateXmlDialog m_xmlDialog = null; 70 71 public PagePreviewConfigOptions(PreviewConfigDialog dialog) { 72 super(dialog); 73 m_stateContainer = new StateContainer(); 74 setup(); 75 } 76 77 80 private void setup() { 81 setLayout(this); 82 83 String fontName = "Dialog"; 84 int fontSize = 11; 85 Font font = new Font(fontName, Font.PLAIN, fontSize); 86 87 m_pageTree = new ResourceTree(); 88 m_pageTree.addListener(this); 89 m_pageTree.setBorder(BorderFactory.createEtchedBorder()); 90 m_pageTree.setShowLeafNodes(true); 91 m_pageTree.setShowApprovedOnly(true); 92 93 AbstractVirtualFileSystem vfs = ServerList.getInstance() 95 .getHarmoniseServer().getVFS(); 96 m_pageTree.addCollection(vfs 97 .getVirtualFile(HarmonisePaths.PATH_PAGE_TEMPLATES).getResource()); 98 add(m_pageTree); 99 100 m_stateList = new JList(); 101 refreshJList(); 102 add(m_stateList); 103 m_stateList.addMouseListener(this); 104 105 this.m_addButton = new JButton("Add"); 106 this.m_addButton.setActionCommand("ADD"); 107 this.m_addButton.addActionListener(this); 108 add(this.m_addButton); 109 110 this.m_removeButton = new JButton("Delete"); 111 this.m_removeButton.setActionCommand("REMOVE"); 112 this.m_removeButton.addActionListener(this); 113 add(this.m_removeButton); 114 115 this.m_editButton = new JButton("Edit"); 116 this.m_editButton.setActionCommand("EDIT"); 117 this.m_editButton.addActionListener(this); 118 m_editButton.setEnabled(false); 119 add(this.m_editButton); 120 121 m_pageLabel = new JTextArea("Choose a page"); 122 m_pageLabel.setOpaque(false); 123 add(m_pageLabel); 124 125 m_stateLabel = new JTextArea("Choose a state"); 126 m_stateLabel.setOpaque(false); 127 add(m_stateLabel); 128 129 this.m_dialogLabel = new JTextArea("Edit the state"); 130 m_dialogLabel.setOpaque(false); 131 132 JFrame frame = new JFrame(); 133 m_xmlDialog = new StateXmlDialog(frame, "State xml", this); 134 135 } 136 137 public void refreshJList() { 138 this.m_stateList.setListData(m_stateContainer.getStates().keySet() 139 .toArray()); 140 } 141 142 145 private PropertyInstance getPropertyInstance() { 146 return null; 147 } 148 149 154 public void layoutContainer(Container arg0) { 155 int width = getParent().getWidth(); 156 int height = getParent().getHeight(); 157 setSize(width, height); 158 setLocation(0, 20); 159 setBorder( BorderFactory.createEtchedBorder() ); 160 161 m_pageLabel.setSize(150, 20); 162 m_pageLabel.setLocation(10, 10); 163 164 this.m_pageTree.setSize(200, 230); 165 this.m_pageTree.setLocation(10, 30); 166 167 m_stateLabel.setSize(150, 20); 168 m_stateLabel.setLocation(220, 10); 169 170 m_stateList.setSize(230, 200); 171 m_stateList.setLocation(220, 30); 172 m_stateList.setBorder(BorderFactory.createEtchedBorder()); 173 174 this.m_addButton.setSize(70, 20); 175 this.m_addButton.setLocation(220, height-50); 176 177 this.m_removeButton.setSize(70, 20); 178 this.m_removeButton.setLocation(300, height-50); 179 180 m_editButton.setSize(70,20); 181 m_editButton.setLocation(380, height-50); 182 183 this.m_dialogLabel.setSize(420, 20); 184 this.m_dialogLabel.setLocation(10, 10); 185 186 } 187 188 193 public Dimension minimumLayoutSize(Container arg0) { 194 return this.getPreferredSize(); 195 } 196 197 202 public Dimension preferredLayoutSize(Container arg0) { 203 return this.getPreferredSize(); 204 } 205 206 211 public Dimension getPreferredSize() { 212 int nWidth = this.getParent().getWidth() - 40; 213 int nHeight = 170; 214 return new Dimension(nWidth, nHeight); 215 } 216 217 public void mouseClicked(MouseEvent me) { 218 if (me.getClickCount() > 0 && me.getComponent() == m_stateList) { 219 String scenario = (String ) m_stateList.getSelectedValue(); 220 m_stateContainer.removeMemberFromScenarios(); 221 m_stateContainer.addMemberToScenario(scenario); 222 this.m_dialog.changesMade(); 223 if(scenario.equalsIgnoreCase("None")){ 224 m_editButton.setEnabled(false); 225 } else { 226 this.m_editButton.setEnabled(true); 227 if(me.getClickCount() == 2){ 228 Document stateDoc = m_stateContainer.getState(scenario); 229 m_xmlDialog.populateState(scenario, stateDoc); 230 m_xmlDialog.show(); 231 } 232 } 233 } 234 } 235 236 public void actionPerformed(ActionEvent ae) { 237 if (ae.getActionCommand().equals("ADD")) { 238 doAdd(); 239 } else if (ae.getActionCommand().equals("REMOVE")) { 240 doRemove(); 241 } else if (ae.getActionCommand().equals("EDIT")) { 242 doEdit(); 243 } 244 } 245 246 249 private void doRemove() { 250 boolean success = m_stateContainer.removeFromStates((String ) m_stateList.getSelectedValue()); 251 if (success) { 252 refreshJList(); 253 m_stateContainer.save(); 254 setMessage("Removed"); 255 } 256 } 257 258 261 private void doAdd() { 262 m_xmlDialog.clear(); 263 m_xmlDialog.show(); 264 } 265 266 private void doEdit() { 267 String scenario = (String ) m_stateList.getSelectedValue(); 268 if(scenario != null && scenario.length() > 0) { 269 Document stateDoc = m_stateContainer.getState(scenario); 270 m_xmlDialog.populateState(scenario, stateDoc); 271 m_xmlDialog.show(); 272 } 273 } 274 275 public void addState(String name, String xml) throws SAXException{ 276 boolean success = m_stateContainer.addToStates(name, xml); 277 if (success) { 278 m_stateContainer.save(); 279 refreshJList(); 280 } 281 } 282 283 private void setMessage(String mess) { 284 m_dialogLabel.setForeground(Color.BLACK); 285 m_dialogLabel.setText(mess); 286 } 287 288 private void setAlertMessage(String mess) { 289 m_dialogLabel.setForeground(Color.RED); 290 m_dialogLabel.setText(mess); 291 } 292 293 299 public void virtualFileSelected(AbstractVirtualFileSystem vfs, String sPath) { 300 m_stateContainer.setVFilePath(sPath); 301 String stateName = m_stateContainer.getScenario(sPath); 302 if(stateName != null ){ 303 m_stateList.setSelectedValue(stateName, false); 304 } else { 305 m_stateList.clearSelection(); 306 } 307 } 308 public void save(){ 309 m_stateContainer.save(); 310 } 311 312 317 public void removeLayoutComponent(Component arg0) { 318 } 319 320 326 public void addLayoutComponent(String arg0, Component arg1) { 327 } 328 329 334 public void mouseEntered(MouseEvent arg0) { 335 } 336 337 342 public void mouseExited(MouseEvent arg0) { 343 } 344 345 350 public void mousePressed(MouseEvent arg0) { 351 } 352 353 358 public void mouseReleased(MouseEvent arg0) { 359 } 360 }
| Popular Tags
|