001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.addressbook.gui.tree.util;
019:
020: import java.awt.BorderLayout;
021: import java.awt.GridLayout;
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024:
025: import javax.swing.BorderFactory;
026: import javax.swing.JButton;
027: import javax.swing.JDialog;
028: import javax.swing.JFrame;
029: import javax.swing.JPanel;
030: import javax.swing.JScrollPane;
031: import javax.swing.JTree;
032: import javax.swing.SwingConstants;
033: import javax.swing.event.TreeSelectionEvent;
034: import javax.swing.event.TreeSelectionListener;
035: import javax.swing.tree.TreeModel;
036: import javax.swing.tree.TreePath;
037:
038: import org.columba.addressbook.config.FolderItem;
039: import org.columba.addressbook.folder.AddressbookFolder;
040: import org.columba.addressbook.folder.AddressbookTreeNode;
041: import org.columba.addressbook.folder.IFolder;
042: import org.columba.addressbook.gui.tree.AddressbookTreeModel;
043: import org.columba.addressbook.util.AddressbookResourceLoader;
044: import org.columba.core.gui.base.ButtonWithMnemonic;
045: import org.columba.core.gui.base.SingleSideEtchedBorder;
046:
047: public class SelectAddressbookFolderDialog extends JDialog implements
048: ActionListener, TreeSelectionListener, ISelectFolderDialog {
049:
050: // private MainInterface mainInterface;
051: private boolean bool = false;
052:
053: // public SelectFolderTree tree;
054: private JTree tree;
055:
056: private JButton[] buttons;
057:
058: // private TreeView treeViewer;
059: private IFolder selectedFolder;
060:
061: private TreeModel model;
062:
063: public SelectAddressbookFolderDialog(TreeModel model) {
064: super (new JFrame(), true);
065:
066: setTitle(AddressbookResourceLoader.getString("tree",
067: "folderdialog", "select_folder"));
068:
069: this .model = model;
070:
071: initComponents();
072:
073: layoutComponents();
074:
075: pack();
076: setLocationRelativeTo(null);
077: setVisible(true);
078: }
079:
080: private void layoutComponents() {
081: getContentPane().setLayout(new BorderLayout());
082:
083: JPanel mainPanel = new JPanel(new BorderLayout());
084: mainPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12,
085: 12));
086: mainPanel.add(new JScrollPane(tree), BorderLayout.CENTER);
087:
088: getContentPane().add(mainPanel, BorderLayout.CENTER);
089:
090: JPanel bottomPanel = new JPanel(new BorderLayout());
091: bottomPanel.setBorder(new SingleSideEtchedBorder(
092: SwingConstants.TOP));
093:
094: JPanel buttonPanel = new JPanel(new GridLayout(1, 2, 6, 0));
095: buttonPanel.setBorder(BorderFactory.createEmptyBorder(12, 12,
096: 12, 12));
097:
098: buttonPanel.add(buttons[0]);
099: buttonPanel.add(buttons[1]);
100: bottomPanel.add(buttonPanel, BorderLayout.EAST);
101:
102: getContentPane().add(bottomPanel, BorderLayout.SOUTH);
103: }
104:
105: private void initComponents() {
106: buttons = new JButton[3];
107:
108: buttons[0] = new ButtonWithMnemonic(AddressbookResourceLoader
109: .getString("global", "cancel"));
110: buttons[0].setActionCommand("CANCEL");
111: buttons[0].setDefaultCapable(true);
112: buttons[1] = new ButtonWithMnemonic(AddressbookResourceLoader
113: .getString("global", "ok"));
114: buttons[1].setEnabled(true);
115: buttons[1].setActionCommand("OK");
116: buttons[2] = new JButton(AddressbookResourceLoader.getString(
117: "tree", "folderdialog", "new_subFolder"));
118: buttons[2].setActionCommand("NEW");
119: buttons[2].setEnabled(false);
120:
121: getRootPane().setDefaultButton(buttons[1]);
122:
123: tree = new JTree(model);
124: tree.expandRow(0);
125: tree.expandRow(1);
126: tree.putClientProperty("JTree.lineStyle", "Angled");
127: tree.setShowsRootHandles(true);
128: tree.setRootVisible(false);
129:
130: tree.addTreeSelectionListener(this );
131: tree.setCellRenderer(new AddressbookTreeCellRenderer(true));
132:
133: for (int i = 0; i < 3; i++) {
134: buttons[i].addActionListener(this );
135: }
136:
137: tree.setSelectionPath(new TreePath(AddressbookTreeModel
138: .getInstance().getFolder("101").getPath()));
139: }
140:
141: public boolean success() {
142: return bool;
143: }
144:
145: public IFolder getSelectedFolder() {
146: return selectedFolder;
147: }
148:
149: public int getUid() {
150: /*
151: * FolderTreeNode node = tree.getSelectedNode(); FolderItem item =
152: * node.getFolderItem();
153: */
154: return 101;
155:
156: // return item.getUid();
157: }
158:
159: public void actionPerformed(ActionEvent e) {
160: String action = e.getActionCommand();
161:
162: if (action.equals("OK")) {
163: bool = true;
164: setVisible(false);
165: } else if (action.equals("CANCEL")) {
166: bool = false;
167: setVisible(false);
168: } else if (action.equals("NEW")) {
169: /*
170: * EditFolderDialog dialog = treeViewer.getEditFolderDialog( "New
171: * Folder" ); dialog.showDialog(); String name; if (
172: * dialog.success() == true ) { // ok pressed name =
173: * dialog.getName(); } else { // cancel pressed return; }
174: * treeViewer.getFolderTree().addUserFolder( getSelectedFolder(),
175: * name ); //TreeNodeEvent updateEvent2 = new TreeNodeEvent(
176: * getSelectedFolder(), TreeNodeEvent.STRUCTURE_CHANGED );
177: * //treeViewer.mainInterface.crossbar.fireTreeNodeChanged(updateEvent2);
178: */
179: }
180: }
181:
182: /**
183: * ***************************** tree selection listener
184: * *******************************
185: */
186: public void valueChanged(TreeSelectionEvent e) {
187: AddressbookTreeNode node = (AddressbookTreeNode) tree
188: .getLastSelectedPathComponent();
189:
190: if (node == null) {
191: return;
192: }
193:
194: FolderItem item = node.getFolderItem();
195:
196: if (item.get("type").equals("AddressbookFolder")) {
197: buttons[1].setEnabled(true);
198: selectedFolder = (AddressbookFolder) node;
199: } else {
200: buttons[1].setEnabled(false);
201: }
202: }
203: }
|