1 19 20 package org.openharmonise.him.displaycomponents.table.order; 21 22 import java.awt.*; 23 import java.awt.event.*; 24 import java.net.*; 25 import java.util.*; 26 27 import javax.swing.*; 28 29 import org.openharmonise.him.actions.dir.*; 30 import org.openharmonise.him.context.StateHandler; 31 import org.openharmonise.him.window.messages.builders.*; 32 import org.openharmonise.him.window.swing.ResourcePathCellRenderer; 33 import org.openharmonise.localversioningfilesystem.*; 34 import org.openharmonise.vfs.*; 35 import org.openharmonise.vfs.context.*; 36 import org.openharmonise.vfs.gui.*; 37 import org.openharmonise.vfs.status.*; 38 39 40 47 public class OrderDialog extends JDialog implements LayoutManager, ActionListener, ContextListener { 48 49 52 private JButton m_okButton = null; 53 54 57 private JButton m_cancelButton = null; 58 59 62 private JButton m_upButton = null; 63 64 67 private JButton m_downButton = null; 68 69 72 private JList m_fileList = null; 73 74 77 private VirtualFile m_vfDir = null; 78 79 82 private JPanel m_innerPane = null; 83 84 87 private boolean m_bOrderChanaged = false; 88 89 97 public OrderDialog(Frame arg0, String arg1, VirtualFile vfDir) throws HeadlessException { 98 super(arg0, arg1, true); 99 this.m_vfDir = vfDir; 100 this.setup(); 101 } 102 103 public static void main(String [] args) { 104 JFrame frame = new JFrame(); 105 frame.setIconImage( ((ImageIcon)IconManager.getInstance().getIcon("32-sim-logo.gif")).getImage() ); 106 107 ToolTipManager.sharedInstance().setInitialDelay(1000); 108 ToolTipManager.sharedInstance().setDismissDelay(500); 109 110 AbstractVirtualFileSystem vfs = null; 111 try { 112 vfs = 113 new LocalVersioningFileSystem( 114 new URI("file:/C:/ContentManagerTesting2/webdav/")); 115 } catch (URISyntaxException e) { 116 e.printStackTrace(); 117 } 118 VirtualFile vfDir = vfs.getVirtualFile("/webdav/Assets/Web Resources/linkdir1").getResource(); 119 120 OrderDialog dialog = new OrderDialog(frame, "Set Default order", vfDir); 121 dialog.show(); 122 } 123 124 127 private void setup() { 128 ContextHandler.getInstance().addListener(ContextType.CONTEXT_APP_FOCUS, this); 129 130 this.setResizable(false); 131 132 this.getContentPane().setLayout(this); 133 134 this.setSize(250,275); 135 int x = this.getGraphicsConfiguration().getBounds().width/2-this.getSize().width/2; 136 int y = this.getGraphicsConfiguration().getBounds().height/2-this.getSize().height/2; 137 138 this.setLocation(x, y); 139 140 String fontName = "Dialog"; 141 int fontSize = 11; 142 Font font = new Font(fontName, Font.PLAIN, fontSize); 143 this.getContentPane().setBackground(new Color(224,224,224)); 144 145 m_fileList = new JList(); 146 m_fileList.setCellRenderer( new ResourcePathCellRenderer(this.m_vfDir.getVFS()) ); 147 m_fileList.setFont(font); 148 149 ArrayList children = new ArrayList(); 150 Iterator itor = this.m_vfDir.getChildren().iterator(); 151 while (itor.hasNext()) { 152 String element = (String ) itor.next(); 153 VirtualFile vfChild = this.m_vfDir.getVFS().getVirtualFile(element).getResource(); 154 children.add(vfChild.getFullPath()); 155 } 156 157 m_fileList.setListData(children.toArray()); 158 m_fileList.setBorder(BorderFactory.createEtchedBorder()); 159 160 m_innerPane = new JPanel(); 161 m_innerPane.setLayout(new BorderLayout()); 162 JScrollPane scroller = new JScrollPane(m_fileList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 163 scroller.setBorder(BorderFactory.createEmptyBorder()); 164 m_innerPane.add(scroller); 165 this.getContentPane().add(m_innerPane); 166 167 m_upButton = new JButton(); 168 m_upButton.setToolTipText("Move selected resource up list"); 169 m_upButton.setIcon( IconManager.getInstance().getIcon("16-command-up.png") ); 170 m_upButton.setActionCommand("UP"); 171 m_upButton.addActionListener(this); 172 this.getContentPane().add(m_upButton); 173 174 m_downButton = new JButton(); 175 m_downButton.setToolTipText("Move selected resource down list"); 176 m_downButton.setIcon( IconManager.getInstance().getIcon("16-command-down.png") ); 177 m_downButton.setActionCommand("DOWN"); 178 m_downButton.addActionListener(this); 179 this.getContentPane().add(m_downButton); 180 181 m_okButton = new JButton("Ok"); 182 m_okButton.setActionCommand("OK"); 183 m_okButton.setFont(font); 184 m_okButton.addActionListener(this); 185 this.getContentPane().add(m_okButton); 186 187 m_cancelButton = new JButton("Cancel"); 188 m_cancelButton.setActionCommand("CANCEL"); 189 m_cancelButton.setFont(font); 190 m_cancelButton.addActionListener(this); 191 this.getContentPane().add(m_cancelButton); 192 } 193 194 199 public boolean isOrderChanged() { 200 return this.m_bOrderChanaged; 201 } 202 203 206 private OrderDialog() throws HeadlessException { 207 super(); 208 } 209 210 214 private OrderDialog(Dialog arg0) throws HeadlessException { 215 super(arg0); 216 } 217 218 223 private OrderDialog(Dialog arg0, boolean arg1) throws HeadlessException { 224 super(arg0, arg1); 225 } 226 227 231 private OrderDialog(Frame arg0) throws HeadlessException { 232 super(arg0); 233 } 234 235 240 private OrderDialog(Frame arg0, boolean arg1) throws HeadlessException { 241 super(arg0, arg1); 242 } 243 244 249 private OrderDialog(Dialog arg0, String arg1) throws HeadlessException { 250 super(arg0, arg1); 251 } 252 253 259 private OrderDialog(Dialog arg0, String arg1, boolean arg2) 260 throws HeadlessException { 261 super(arg0, arg1, arg2); 262 } 263 264 270 private OrderDialog(Frame arg0, String arg1, boolean arg2) 271 throws HeadlessException { 272 super(arg0, arg1, arg2); 273 } 274 275 282 private OrderDialog( 283 Dialog arg0, 284 String arg1, 285 boolean arg2, 286 GraphicsConfiguration arg3) 287 throws HeadlessException { 288 super(arg0, arg1, arg2, arg3); 289 } 290 291 297 private OrderDialog( 298 Frame arg0, 299 String arg1, 300 boolean arg2, 301 GraphicsConfiguration arg3) { 302 super(arg0, arg1, arg2, arg3); 303 } 304 305 308 public void removeLayoutComponent(Component arg0) { 309 310 } 311 312 315 public void layoutContainer(Container arg0) { 316 317 m_innerPane.setLocation(10,10); 318 m_innerPane.setSize(200,200); 319 320 m_upButton.setLocation(215, 80); 321 m_upButton.setSize( 25,25 ); 322 323 m_downButton.setLocation(215, 110); 324 m_downButton.setSize( 25,25 ); 325 326 m_okButton.setLocation(20, 220); 327 m_okButton.setSize(70,20); 328 329 m_cancelButton.setLocation(105, 220); 330 m_cancelButton.setSize(70,20); 331 } 332 333 336 public void addLayoutComponent(String arg0, Component arg1) { 337 338 } 339 340 343 public Dimension minimumLayoutSize(Container arg0) { 344 return this.getSize(); 345 } 346 347 350 public Dimension preferredLayoutSize(Container arg0) { 351 return this.getSize(); 352 } 353 354 357 public void actionPerformed(ActionEvent ae) { 358 if(ae.getActionCommand().equals("OK")) { 359 StateHandler.getInstance().addWait(this, "ORDER-COL"); 360 StatusData status = new VFSStatus(); 361 String sDirName =null; 362 status.setMethodName(ActionOrder.ACTION_NAME); 363 try { 364 ListModel model = this.m_fileList.getModel(); 365 ArrayList values = new ArrayList(); 366 for (int i = 0; i < model.getSize(); i++) { 367 values.add(model.getElementAt(i)); 368 } 369 370 StatusData statusData = this.m_vfDir.setChildrenOrder(values); 371 status.addStatusData(statusData); 372 373 this.hide(); 374 375 sDirName = this.m_vfDir.getVFS().getVirtualFileSystemView().getDisplayName(this.m_vfDir); 376 377 } catch (Exception e) { 378 e.printStackTrace(System.err); 379 status.setStatusLevel(StatusData.LEVEL_ERROR); 380 sDirName = this.m_vfDir.getVFS().getVirtualFileSystemView().getDisplayName(this.m_vfDir); 381 } finally { 382 VFSMessageBuilder.getInstance().fireMessage(ActionOrder.ACTION_NAME, status, sDirName); 383 StateHandler.getInstance().removeWait(this, "ORDER-COL"); 384 } 385 } else if(ae.getActionCommand().equals("CANCEL")) { 386 this.m_bOrderChanaged=false; 387 this.hide(); 388 } else if(ae.getActionCommand().equals("UP")) { 389 ListModel model = this.m_fileList.getModel(); 390 ArrayList values = new ArrayList(); 391 for (int i = 0; i < model.getSize(); i++) { 392 values.add(model.getElementAt(i)); 393 } 394 int nIndex = this.m_fileList.getSelectedIndex(); 395 if(nIndex>0) { 396 String sValueUp = (String ) values.get(nIndex); 397 String sValueDown = (String ) values.get(nIndex-1); 398 values.set(nIndex-1, sValueUp); 399 values.set(nIndex, sValueDown); 400 this.m_fileList.setListData(values.toArray()); 401 this.m_fileList.setSelectedIndex(nIndex-1); 402 } 403 this.m_bOrderChanaged=true; 404 this.validateTree(); 405 this.repaint(); 406 } else if(ae.getActionCommand().equals("DOWN")) { 407 ListModel model = this.m_fileList.getModel(); 408 ArrayList values = new ArrayList(); 409 for (int i = 0; i < model.getSize(); i++) { 410 values.add(model.getElementAt(i)); 411 } 412 int nIndex = this.m_fileList.getSelectedIndex(); 413 if(nIndex<model.getSize()-1) { 414 String sValueDown = (String ) values.get(nIndex); 415 String sValueUp = (String ) values.get(nIndex+1); 416 values.set(nIndex+1, sValueDown); 417 values.set(nIndex, sValueUp); 418 this.m_fileList.setListData(values.toArray()); 419 this.m_fileList.setSelectedIndex(nIndex+1); 420 } 421 this.m_bOrderChanaged=true; 422 this.validateTree(); 423 this.repaint(); 424 } 425 } 426 427 430 public void contextMessage(ContextEvent ce) { 431 if(ce.CONTEXT_TYPE==ContextType.CONTEXT_APP_FOCUS) { 432 this.toFront(); 433 } 434 } 435 436 } | Popular Tags |