001:/*
002: * Copyright (c) 2000, Jacob Smullyan.
003: *
004: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
005: * for the latest version.
006: *
007: * SkunkDAV is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License as published
009: * by the Free Software Foundation; either version 2, or (at your option)
010: * any later version.
011: *
012: * SkunkDAV is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with SkunkDAV; see the file COPYING. If not, write to the Free
019: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
020: * 02111-1307, USA.
021:*/
022:
023:package org.skunk.dav.client.gui;
024:
025:import java.awt.BorderLayout;
026:import java.awt.Dimension;
027:import java.awt.GridBagConstraints;
028:import java.awt.GridBagLayout;
029:import java.awt.Insets;
030:import java.awt.event.ItemEvent;
031:import java.awt.event.ItemListener;
032:import java.util.ArrayList;
033:import java.util.Iterator;
034:import javax.swing.BorderFactory;
035:import javax.swing.JCheckBox;
036:import javax.swing.JComponent;
037:import javax.swing.JPanel;
038:import javax.swing.border.TitledBorder;
039:import javax.swing.event.ListDataEvent;
040:import javax.swing.event.ListDataListener;
041:import org.skunk.assert.Assertion;
042:import org.skunk.config.Configurator;
043:import org.skunk.swing.DualListPanel;
044:import org.skunk.trace.Debug;
045:
046:public class TableViewCustomizer extends PreferencesCustomizer
047:{
048: private JPanel customizer;
049: private DAVTableHeader[] sourceHeaders, configHeaders;
050: private DualListPanel duellist;
051: private ListDataListener listDataListener;
052:
053: private static final DAVTableHeader[] allHeaders=
054: {
055: DAVTableHeader.LOCK,
056: DAVTableHeader.FILE_NAME,
057: DAVTableHeader.CREATION_DATE,
058: DAVTableHeader.DISPLAY_NAME,
059: DAVTableHeader.CONTENT_LANGUAGE,
060: DAVTableHeader.CONTENT_LENGTH,
061: DAVTableHeader.CONTENT_TYPE,
062: DAVTableHeader.ETAG,
063: DAVTableHeader.LAST_MODIFIED,
064: DAVTableHeader.EXECUTABLE,
065: DAVTableHeader.LOCKTOKEN,
066: DAVTableHeader.LOCKTYPE,
067: DAVTableHeader.LOCKSCOPE,
068: DAVTableHeader.OWNER,
069: DAVTableHeader.RESOURCETYPE
070: };
071:
072: public TableViewCustomizer(String title, Configurator configurator)
073: {
074: super (title, configurator);
075: initConfig();
076: initComponents();
077: }
078:
079: private void initConfig()
080: {
081: for (Iterator it=Explorer.explorers();it.hasNext();)
082: addConfigTarget(it.next());
083: Object val=getConfigurator().getStore().getConfigValue(Explorer.class,
084: Explorer.TABLE_HEADERS_PROPERTY);
085: if (val==null)
086: {
087: Explorer ex=null;
088: for (Iterator it=Explorer.explorers();it.hasNext();)
089: {
090: ex=(Explorer) it.next(); //any one will do
091: break;
092: }
093: Assertion.assert((ex!=null), "explorer not null");
094: val=ex.getTableHeaders();
095: }
096: if (val instanceof DAVTableHeader[])
097: configHeaders=(DAVTableHeader[]) val;
098: else configHeaders=new DAVTableHeader[0];
099: Debug.trace(this , Debug.DP3, "we got back from config an instance of {0}", val.getClass());
100: //create two arrays of headers, source and sink
101: sourceHeaders=new DAVTableHeader[allHeaders.length-configHeaders.length];
102: int j=0;
103: for (int i=0;i<allHeaders.length;i++)
104: {
105: if (!inArray(allHeaders[i], configHeaders))
106: sourceHeaders[j++]=allHeaders[i];
107: }
108: }
109:
110: private void initComponents()
111: {
112: customizer=new JPanel(new BorderLayout());
113: String sourceLabel=ResourceManager.getMessage(ResourceManager.TABLE_VIEW_SOURCE_LIST_TITLE);
114: String sinkLabel=ResourceManager.getMessage(ResourceManager.TABLE_VIEW_SINK_LIST_TITLE);
115: duellist=new DualListPanel(sourceHeaders, configHeaders, sourceLabel, sinkLabel);
116: duellist.setListPreferredSize(new Dimension(160, 340));
117: listDataListener=new HeaderListener();
118: duellist.addListDataListener(listDataListener);
119: String borderTitle=ResourceManager.getMessage(ResourceManager.TABLE_VIEW_CUSTOMIZER_BORDER_TITLE);
120: customizer.add(duellist, BorderLayout.NORTH);
121: customizer.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
122: borderTitle,
123: TitledBorder.LEFT,
124: TitledBorder.TOP));
125: }
126:
127: private static boolean inArray(Object obj, Object[] oArray)
128: {
129: for (int i=0;i<oArray.length;i++)
130: if (obj.toString().equals(oArray[i].toString()))
131: return true;
132: return false;
133: }
134:
135: public void revert()
136: {
137: super .revert();
138: resetDualListPanel();
139: }
140:
141: private void resetDualListPanel(Object[] values)
142: {
143: duellist.removeListDataListener(listDataListener);
144: if (values !=null && values instanceof Object[])
145: duellist.reset(values);
146: else duellist.reset();
147: duellist.addListDataListener(listDataListener);
148: listDataListener.intervalAdded(null);
149: }
150:
151: private void resetDualListPanel()
152: {
153: resetDualListPanel(null);
154: }
155:
156: public void revertToDefault()
157: {
158: super .revertToDefault();
159: Object val=getConfigurator().getDefaultStore().getConfigValue(Explorer.class,
160: Explorer.TABLE_HEADERS_PROPERTY);
161: if (val instanceof Object[])
162: {
163: Debug.trace(this , Debug.DP3, "resetting to {0}", new Object[] {val});
164: resetDualListPanel((Object[]) val);
165: }
166: else
167: {
168: Debug.trace(this , Debug.DP3, "default value is unexpected: {0}", new Object[] {val});
169: }
170: }
171:
172: public JComponent getCustomizer()
173: {
174: return customizer;
175: }
176:
177: class HeaderListener implements ListDataListener
178: {
179: public void intervalAdded(ListDataEvent e)
180: {
181: Debug.trace(this , Debug.DP3, "in intervalAdded()");
182: _process(e);
183: }
184:
185: public void intervalRemoved(ListDataEvent e)
186: {
187: Debug.trace(this , Debug.DP3, "in intervalRemoved()");
188: _process(e);
189: }
190:
191: public void contentsChanged(ListDataEvent e)
192: {
193: Debug.trace(this , Debug.DP3, "in contentsChanged()");
194: _process(e);
195: }
196:
197: private void _process(ListDataEvent e)
198: {
199: Object[] chosenItems=duellist.getChosenItems();
200: DAVTableHeader[] tmpHeaders=new DAVTableHeader[chosenItems.length];
201: for (int i=0;i<chosenItems.length;i++)
202: tmpHeaders[i]=(DAVTableHeader) chosenItems[i];
203: setConfigValue(Explorer.class, Explorer.TABLE_HEADERS_PROPERTY, tmpHeaders);
204: if (e!=null) setDirty(true);
205: }
206: }
207:}
208:
209:/* $Log: TableViewCustomizer.java,v $
210:/* Revision 1.10 2001/02/06 22:13:40 smulloni
211:/* first more-or-less working version of syntax highlighting, with customization.
212:/*
213:/* Revision 1.9 2000/12/19 22:36:05 smulloni
214:/* adjustments to preamble.
215:/*
216:/* Revision 1.8 2000/12/03 23:53:26 smulloni
217:/* added license and copyright preamble to java files.
218:/*
219:/* Revision 1.7 2000/11/10 22:40:08 smullyan
220:/* added icon to table for resource type; fixes to copy and move; disabling of
221:/* menu items that are inappropriate.
222:/*
223:/* Revision 1.6 2000/11/09 23:35:00 smullyan
224:/* log added to every Java file, with the help of python. Lock stealing
225:/* implemented, and treatment of locks made more robust.
226:/* */
|