001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019:
020: package org.openharmonise.him.displaycomponents.table.order;
021:
022: import java.awt.*;
023: import java.awt.event.*;
024: import java.net.*;
025: import java.util.*;
026:
027: import javax.swing.*;
028:
029: import org.openharmonise.him.actions.dir.*;
030: import org.openharmonise.him.context.StateHandler;
031: import org.openharmonise.him.window.messages.builders.*;
032: import org.openharmonise.him.window.swing.ResourcePathCellRenderer;
033: import org.openharmonise.localversioningfilesystem.*;
034: import org.openharmonise.vfs.*;
035: import org.openharmonise.vfs.context.*;
036: import org.openharmonise.vfs.gui.*;
037: import org.openharmonise.vfs.status.*;
038:
039: /**
040: * Dialog for setting the server side order of resources in a collection.
041: *
042: * @author Matthew Large
043: * @version $Revision: 1.1 $
044: *
045: */
046: public class OrderDialog extends JDialog implements LayoutManager,
047: ActionListener, ContextListener {
048:
049: /**
050: * OK button.
051: */
052: private JButton m_okButton = null;
053:
054: /**
055: * Cancel button.
056: */
057: private JButton m_cancelButton = null;
058:
059: /**
060: * Move resource up button.
061: */
062: private JButton m_upButton = null;
063:
064: /**
065: * Move resource down button.
066: */
067: private JButton m_downButton = null;
068:
069: /**
070: * List of resources.
071: */
072: private JList m_fileList = null;
073:
074: /**
075: * Collection to be order.
076: */
077: private VirtualFile m_vfDir = null;
078:
079: /**
080: * Scroller panel.
081: */
082: private JPanel m_innerPane = null;
083:
084: /**
085: * true if the order was changed.
086: */
087: private boolean m_bOrderChanaged = false;
088:
089: /**
090: * Constructs a new order dialog.
091: *
092: * @param arg0 Owning frame
093: * @param arg1 Dialog title
094: * @param vfDir Collection to be ordered
095: * @throws HeadlessException
096: */
097: public OrderDialog(Frame arg0, String arg1, VirtualFile vfDir)
098: throws HeadlessException {
099: super (arg0, arg1, true);
100: this .m_vfDir = vfDir;
101: this .setup();
102: }
103:
104: public static void main(String[] args) {
105: JFrame frame = new JFrame();
106: frame.setIconImage(((ImageIcon) IconManager.getInstance()
107: .getIcon("32-sim-logo.gif")).getImage());
108:
109: ToolTipManager.sharedInstance().setInitialDelay(1000);
110: ToolTipManager.sharedInstance().setDismissDelay(500);
111:
112: AbstractVirtualFileSystem vfs = null;
113: try {
114: vfs = new LocalVersioningFileSystem(new URI(
115: "file:/C:/ContentManagerTesting2/webdav/"));
116: } catch (URISyntaxException e) {
117: e.printStackTrace();
118: }
119: VirtualFile vfDir = vfs.getVirtualFile(
120: "/webdav/Assets/Web Resources/linkdir1").getResource();
121:
122: OrderDialog dialog = new OrderDialog(frame,
123: "Set Default order", vfDir);
124: dialog.show();
125: }
126:
127: /**
128: * Configures this dialog.
129: */
130: private void setup() {
131: ContextHandler.getInstance().addListener(
132: ContextType.CONTEXT_APP_FOCUS, this );
133:
134: this .setResizable(false);
135:
136: this .getContentPane().setLayout(this );
137:
138: this .setSize(250, 275);
139: int x = this .getGraphicsConfiguration().getBounds().width / 2
140: - this .getSize().width / 2;
141: int y = this .getGraphicsConfiguration().getBounds().height / 2
142: - this .getSize().height / 2;
143:
144: this .setLocation(x, y);
145:
146: String fontName = "Dialog";
147: int fontSize = 11;
148: Font font = new Font(fontName, Font.PLAIN, fontSize);
149: this .getContentPane().setBackground(new Color(224, 224, 224));
150:
151: m_fileList = new JList();
152: m_fileList.setCellRenderer(new ResourcePathCellRenderer(
153: this .m_vfDir.getVFS()));
154: m_fileList.setFont(font);
155:
156: ArrayList children = new ArrayList();
157: Iterator itor = this .m_vfDir.getChildren().iterator();
158: while (itor.hasNext()) {
159: String element = (String) itor.next();
160: VirtualFile vfChild = this .m_vfDir.getVFS().getVirtualFile(
161: element).getResource();
162: children.add(vfChild.getFullPath());
163: }
164:
165: m_fileList.setListData(children.toArray());
166: m_fileList.setBorder(BorderFactory.createEtchedBorder());
167:
168: m_innerPane = new JPanel();
169: m_innerPane.setLayout(new BorderLayout());
170: JScrollPane scroller = new JScrollPane(m_fileList,
171: JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
172: JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
173: scroller.setBorder(BorderFactory.createEmptyBorder());
174: m_innerPane.add(scroller);
175: this .getContentPane().add(m_innerPane);
176:
177: m_upButton = new JButton();
178: m_upButton.setToolTipText("Move selected resource up list");
179: m_upButton.setIcon(IconManager.getInstance().getIcon(
180: "16-command-up.png"));
181: m_upButton.setActionCommand("UP");
182: m_upButton.addActionListener(this );
183: this .getContentPane().add(m_upButton);
184:
185: m_downButton = new JButton();
186: m_downButton.setToolTipText("Move selected resource down list");
187: m_downButton.setIcon(IconManager.getInstance().getIcon(
188: "16-command-down.png"));
189: m_downButton.setActionCommand("DOWN");
190: m_downButton.addActionListener(this );
191: this .getContentPane().add(m_downButton);
192:
193: m_okButton = new JButton("Ok");
194: m_okButton.setActionCommand("OK");
195: m_okButton.setFont(font);
196: m_okButton.addActionListener(this );
197: this .getContentPane().add(m_okButton);
198:
199: m_cancelButton = new JButton("Cancel");
200: m_cancelButton.setActionCommand("CANCEL");
201: m_cancelButton.setFont(font);
202: m_cancelButton.addActionListener(this );
203: this .getContentPane().add(m_cancelButton);
204: }
205:
206: /**
207: * Checks if the order has been changed.
208: *
209: * @return true if the order has been changed
210: */
211: public boolean isOrderChanged() {
212: return this .m_bOrderChanaged;
213: }
214:
215: /**
216: * @throws java.awt.HeadlessException
217: */
218: private OrderDialog() throws HeadlessException {
219: super ();
220: }
221:
222: /**
223: * @param arg0
224: * @throws java.awt.HeadlessException
225: */
226: private OrderDialog(Dialog arg0) throws HeadlessException {
227: super (arg0);
228: }
229:
230: /**
231: * @param arg0
232: * @param arg1
233: * @throws java.awt.HeadlessException
234: */
235: private OrderDialog(Dialog arg0, boolean arg1)
236: throws HeadlessException {
237: super (arg0, arg1);
238: }
239:
240: /**
241: * @param arg0
242: * @throws java.awt.HeadlessException
243: */
244: private OrderDialog(Frame arg0) throws HeadlessException {
245: super (arg0);
246: }
247:
248: /**
249: * @param arg0
250: * @param arg1
251: * @throws java.awt.HeadlessException
252: */
253: private OrderDialog(Frame arg0, boolean arg1)
254: throws HeadlessException {
255: super (arg0, arg1);
256: }
257:
258: /**
259: * @param arg0
260: * @param arg1
261: * @throws java.awt.HeadlessException
262: */
263: private OrderDialog(Dialog arg0, String arg1)
264: throws HeadlessException {
265: super (arg0, arg1);
266: }
267:
268: /**
269: * @param arg0
270: * @param arg1
271: * @param arg2
272: * @throws java.awt.HeadlessException
273: */
274: private OrderDialog(Dialog arg0, String arg1, boolean arg2)
275: throws HeadlessException {
276: super (arg0, arg1, arg2);
277: }
278:
279: /**
280: * @param arg0
281: * @param arg1
282: * @param arg2
283: * @throws java.awt.HeadlessException
284: */
285: private OrderDialog(Frame arg0, String arg1, boolean arg2)
286: throws HeadlessException {
287: super (arg0, arg1, arg2);
288: }
289:
290: /**
291: * @param arg0
292: * @param arg1
293: * @param arg2
294: * @param arg3
295: * @throws java.awt.HeadlessException
296: */
297: private OrderDialog(Dialog arg0, String arg1, boolean arg2,
298: GraphicsConfiguration arg3) throws HeadlessException {
299: super (arg0, arg1, arg2, arg3);
300: }
301:
302: /**
303: * @param arg0
304: * @param arg1
305: * @param arg2
306: * @param arg3
307: */
308: private OrderDialog(Frame arg0, String arg1, boolean arg2,
309: GraphicsConfiguration arg3) {
310: super (arg0, arg1, arg2, arg3);
311: }
312:
313: /* (non-Javadoc)
314: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
315: */
316: public void removeLayoutComponent(Component arg0) {
317:
318: }
319:
320: /* (non-Javadoc)
321: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
322: */
323: public void layoutContainer(Container arg0) {
324:
325: m_innerPane.setLocation(10, 10);
326: m_innerPane.setSize(200, 200);
327:
328: m_upButton.setLocation(215, 80);
329: m_upButton.setSize(25, 25);
330:
331: m_downButton.setLocation(215, 110);
332: m_downButton.setSize(25, 25);
333:
334: m_okButton.setLocation(20, 220);
335: m_okButton.setSize(70, 20);
336:
337: m_cancelButton.setLocation(105, 220);
338: m_cancelButton.setSize(70, 20);
339: }
340:
341: /* (non-Javadoc)
342: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
343: */
344: public void addLayoutComponent(String arg0, Component arg1) {
345:
346: }
347:
348: /* (non-Javadoc)
349: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
350: */
351: public Dimension minimumLayoutSize(Container arg0) {
352: return this .getSize();
353: }
354:
355: /* (non-Javadoc)
356: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
357: */
358: public Dimension preferredLayoutSize(Container arg0) {
359: return this .getSize();
360: }
361:
362: /* (non-Javadoc)
363: * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
364: */
365: public void actionPerformed(ActionEvent ae) {
366: if (ae.getActionCommand().equals("OK")) {
367: StateHandler.getInstance().addWait(this , "ORDER-COL");
368: StatusData status = new VFSStatus();
369: String sDirName = null;
370: status.setMethodName(ActionOrder.ACTION_NAME);
371: try {
372: ListModel model = this .m_fileList.getModel();
373: ArrayList values = new ArrayList();
374: for (int i = 0; i < model.getSize(); i++) {
375: values.add(model.getElementAt(i));
376: }
377:
378: StatusData statusData = this .m_vfDir
379: .setChildrenOrder(values);
380: status.addStatusData(statusData);
381:
382: this .hide();
383:
384: sDirName = this .m_vfDir.getVFS()
385: .getVirtualFileSystemView().getDisplayName(
386: this .m_vfDir);
387:
388: } catch (Exception e) {
389: e.printStackTrace(System.err);
390: status.setStatusLevel(StatusData.LEVEL_ERROR);
391: sDirName = this .m_vfDir.getVFS()
392: .getVirtualFileSystemView().getDisplayName(
393: this .m_vfDir);
394: } finally {
395: VFSMessageBuilder.getInstance().fireMessage(
396: ActionOrder.ACTION_NAME, status, sDirName);
397: StateHandler.getInstance()
398: .removeWait(this , "ORDER-COL");
399: }
400: } else if (ae.getActionCommand().equals("CANCEL")) {
401: this .m_bOrderChanaged = false;
402: this .hide();
403: } else if (ae.getActionCommand().equals("UP")) {
404: ListModel model = this .m_fileList.getModel();
405: ArrayList values = new ArrayList();
406: for (int i = 0; i < model.getSize(); i++) {
407: values.add(model.getElementAt(i));
408: }
409: int nIndex = this .m_fileList.getSelectedIndex();
410: if (nIndex > 0) {
411: String sValueUp = (String) values.get(nIndex);
412: String sValueDown = (String) values.get(nIndex - 1);
413: values.set(nIndex - 1, sValueUp);
414: values.set(nIndex, sValueDown);
415: this .m_fileList.setListData(values.toArray());
416: this .m_fileList.setSelectedIndex(nIndex - 1);
417: }
418: this .m_bOrderChanaged = true;
419: this .validateTree();
420: this .repaint();
421: } else if (ae.getActionCommand().equals("DOWN")) {
422: ListModel model = this .m_fileList.getModel();
423: ArrayList values = new ArrayList();
424: for (int i = 0; i < model.getSize(); i++) {
425: values.add(model.getElementAt(i));
426: }
427: int nIndex = this .m_fileList.getSelectedIndex();
428: if (nIndex < model.getSize() - 1) {
429: String sValueDown = (String) values.get(nIndex);
430: String sValueUp = (String) values.get(nIndex + 1);
431: values.set(nIndex + 1, sValueDown);
432: values.set(nIndex, sValueUp);
433: this .m_fileList.setListData(values.toArray());
434: this .m_fileList.setSelectedIndex(nIndex + 1);
435: }
436: this .m_bOrderChanaged = true;
437: this .validateTree();
438: this .repaint();
439: }
440: }
441:
442: /* (non-Javadoc)
443: * @see com.simulacramedia.contentmanager.context.ContextListener#contextMessage(com.simulacramedia.contentmanager.context.ContextEvent)
444: */
445: public void contextMessage(ContextEvent ce) {
446: if (ce.CONTEXT_TYPE == ContextType.CONTEXT_APP_FOCUS) {
447: this.toFront();
448: }
449: }
450:
451: }
|