001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.openide.explorer.view;
042:
043: import org.openide.explorer.ExplorerManager;
044: import org.openide.explorer.view.TableSheet.ControlledTableView;
045: import org.openide.nodes.Node;
046: import org.openide.nodes.Node.Property;
047: import org.openide.util.WeakListeners;
048:
049: import java.awt.Dimension;
050: import java.awt.event.FocusEvent;
051: import java.awt.event.FocusListener;
052:
053: import java.beans.PropertyChangeEvent;
054: import java.beans.PropertyChangeListener;
055:
056: import javax.swing.*;
057: import javax.swing.event.ListDataEvent;
058: import javax.swing.event.ListDataListener;
059:
060: /** Explorer view. Allows to view list of nodes on the left
061: * and its properties in table on the right.
062: *
063: * @deprecated Use <code>org.openide.explorer.view.TreeTableView</code> instead.
064: *
065: * @author jrojcek
066: * @since 1.7
067: */
068: public @Deprecated
069: class ListTableView extends ListView {
070: /** flag that allows group more requests into one */
071: private boolean tableChanging = false;
072:
073: /** manager is used only for synchronization of header name */
074: private ExplorerManager manager;
075:
076: /** listener on explorer manager */
077: private PropertyChangeListener wlpc;
078:
079: /** table view that is controlled by list view */
080: private ControlledTableView controlledTableView;
081:
082: /** listener on changes in list model */
083: private Listener listener;
084:
085: /** preferred size*/
086: private Dimension prefSize;
087:
088: /** table */
089: private JTable table;
090:
091: /** Create ListTableView with default NodeTableModel
092: */
093: public ListTableView() {
094: this (null);
095: }
096:
097: /** Creates ListTableView with provided NodeTableModel.
098: * @param ntm node table model
099: */
100: public ListTableView(NodeTableModel ntm) {
101: // do not use scroll bars, this scroll pane is dummy, only for border painting
102: setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
103: setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
104:
105: // remove list from viewportview
106: setViewportView(null);
107:
108: // insert list into new scrollpane
109: JScrollPane listView = new JScrollPane(list);
110: listView
111: .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
112: listView.setBorder(null);
113:
114: // create table view controlled by new scrollpane
115: controlledTableView = (ntm == null) ? new TableSheet.ControlledTableView(
116: listView)
117: : new TableSheet.ControlledTableView(listView, ntm);
118: setViewportView(controlledTableView.compoundScrollPane());
119:
120: listener = new Listener();
121: delayedFireTableDataChanged();
122:
123: setPreferredSize(new Dimension(400, 400));
124:
125: table = controlledTableView.getTable();
126: }
127:
128: /** Set columns.
129: * @param props each column is constructed from Node.Property
130: */
131: public void setProperties(Property[] props) {
132: controlledTableView.setProperties(props);
133: }
134:
135: /** Sets resize mode of table.
136: *
137: * @param mode - One of 5 legal values: <pre>JTable.AUTO_RESIZE_OFF,
138: * JTable.AUTO_RESIZE_NEXT_COLUMN,
139: * JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS,
140: * JTable.AUTO_RESIZE_LAST_COLUMN,
141: * JTable.AUTO_RESIZE_ALL_COLUMNS</pre>
142: */
143: public final void setTableAutoResizeMode(int mode) {
144: controlledTableView.setAutoResizeMode(mode);
145: }
146:
147: /** Gets resize mode of table.
148: *
149: * @return mode - One of 5 legal values: <pre>JTable.AUTO_RESIZE_OFF,
150: * JTable.AUTO_RESIZE_NEXT_COLUMN,
151: * JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS,
152: * JTable.AUTO_RESIZE_LAST_COLUMN,
153: * JTable.AUTO_RESIZE_ALL_COLUMNS</pre>
154: */
155: public final int getTableAutoResizeMode() {
156: return controlledTableView.getAutoResizeMode();
157: }
158:
159: /** Sets preferred width of table column
160: * @param index column index
161: * @param width preferred column width
162: */
163: public final void setTableColumnPreferredWidth(int index, int width) {
164: controlledTableView.setColumnPreferredWidth(index, width);
165: }
166:
167: /** Gets preferred width of table column
168: * @param index column index
169: * @return preferred column width
170: */
171: public final int getTableColumnPreferredWidth(int index) {
172: return controlledTableView.getColumnPreferredWidth(index);
173: }
174:
175: /** Set preferred width of list view
176: * @param width preferred width
177: */
178: public void setListPreferredWidth(int width) {
179: controlledTableView.setControllingViewWidth(width);
180:
181: Dimension dim = getPreferredSize();
182:
183: // controlledTableView.setPreferredSize(new Dimension(dim.width - width, dim.height));
184: table.setPreferredScrollableViewportSize(new Dimension(
185: dim.width - width, dim.height));
186: }
187:
188: /** Get preferred size of list view
189: * @return preferred width of list view
190: */
191: public final int getListPreferredWidth() {
192: return controlledTableView.getControllingViewWidth();
193: }
194:
195: public void setPreferredSize(Dimension dim) {
196: super .setPreferredSize(dim);
197: prefSize = dim;
198: }
199:
200: public Dimension getPreferredSize() {
201: return prefSize;
202: }
203:
204: public void addNotify() {
205: super .addNotify();
206:
207: ExplorerManager newManager = ExplorerManager.find(this );
208:
209: if (newManager != manager) {
210: if (manager != null) {
211: manager.removePropertyChangeListener(wlpc);
212: }
213:
214: manager = newManager;
215: manager
216: .addPropertyChangeListener(wlpc = org.openide.util.WeakListeners
217: .propertyChange(listener, manager));
218: controlledTableView.setHeaderText(manager
219: .getExploredContext().getDisplayName());
220: }
221:
222: list.getModel().addListDataListener(listener);
223: list.addFocusListener(listener);
224: delayedFireTableDataChanged();
225: }
226:
227: public void removeNotify() {
228: super .removeNotify();
229: list.getModel().removeListDataListener(listener);
230: list.removeFocusListener(listener);
231:
232: // clear node listeners
233: controlledTableView.setNodes(new Node[] {});
234: }
235:
236: /** Chnage table data in awt thread */
237: private void delayedFireTableDataChanged() {
238: if (tableChanging) {
239: return;
240: }
241:
242: tableChanging = true;
243: SwingUtilities.invokeLater(new Runnable() {
244: public void run() {
245: if (list.getCellBounds(0, 0) != null) {
246: controlledTableView.setRowHeight(list
247: .getCellBounds(0, 0).height);
248: }
249:
250: changeTableModel();
251: tableChanging = false;
252: }
253: });
254: }
255:
256: /** Change table model. Sets rows (nodes) of table mmodel */
257: private void changeTableModel() {
258: Node[] nodes = new Node[list.getModel().getSize()];
259:
260: for (int i = 0; i < list.getModel().getSize(); i++) {
261: nodes[i] = Visualizer.findNode(list.getModel()
262: .getElementAt(i));
263: }
264:
265: controlledTableView.setNodes(nodes);
266: }
267:
268: /** Listenes on changes in list model.
269: */
270: private class Listener implements PropertyChangeListener,
271: FocusListener, ListDataListener {
272: Listener() {
273: }
274:
275: /**
276: * Sent after the indices in the index0,index1
277: * interval have been inserted in the data model.
278: * The new interval includes both index0 and index1.
279: *
280: * @param e a ListDataEvent encapuslating the event information
281: */
282: public void intervalAdded(ListDataEvent e) {
283: delayedFireTableDataChanged();
284: }
285:
286: /**
287: * Sent after the indices in the index0,index1 interval
288: * have been removed from the data model. The interval
289: * includes both index0 and index1.
290: *
291: * @param e a ListDataEvent encapuslating the event information
292: */
293: public void intervalRemoved(ListDataEvent e) {
294: delayedFireTableDataChanged();
295: }
296:
297: /**
298: * Sent when the contents of the list has changed in a way
299: * that's too complex to characterize with the previous
300: * methods. Index0 and index1 bracket the change.
301: *
302: * @param e a ListDataEvent encapuslating the event information
303: */
304: public void contentsChanged(ListDataEvent e) {
305: delayedFireTableDataChanged();
306: }
307:
308: public void focusGained(FocusEvent evt) {
309: }
310:
311: public void focusLost(FocusEvent evt) {
312: if (evt.isTemporary()) {
313: return;
314: }
315:
316: int selectedRow = list.getSelectedIndex();
317: table.getSelectionModel().setAnchorSelectionIndex(
318: selectedRow);
319: table.getColumnModel().getSelectionModel()
320: .setAnchorSelectionIndex(0);
321: }
322:
323: /** Updates header name.
324: * @param evt event
325: */
326: public void propertyChange(PropertyChangeEvent evt) {
327: if (ExplorerManager.PROP_EXPLORED_CONTEXT.equals(evt
328: .getPropertyName())) {
329: controlledTableView.setHeaderText(manager
330: .getExploredContext().getDisplayName());
331: }
332: }
333: }
334:
335: /*
336: public static void main (String[] args) {
337: SwingUtilities.invokeLater(new Runnable() {
338: public void run() {
339: Node n = new org.netbeans.core.ModuleNode();
340: ExplorerManager em = new ExplorerManager();
341: em.setRootContext(n);
342: ListTableView ttv = new ListTableView();
343: // ttv.model.setDepth(2);
344: // ttv.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
345: ttv.setProperties(
346: // n.getChildren().getNodes()[0].getPropertySets()[0].getProperties());
347: new Node.Property[]{
348: new PropertySupport.ReadWrite (
349: "enabled", // NOI18N
350: Boolean.TYPE,
351: org.openide.util.NbBundle.getMessage (org.netbeans.core.Main.class, "PROP_modules_enabled"),
352: org.openide.util.NbBundle.getMessage (org.netbeans.core.Main.class, "HINT_modules_enabled")
353: ) {
354: public Object getValue () {
355: return null;
356: }
357:
358: public void setValue (Object o) {
359: }
360: },
361: new PropertySupport.ReadOnly (
362: "specVersion", // NOI18N
363: String.class,
364: org.openide.util.NbBundle.getMessage (org.netbeans.core.Main.class, "PROP_modules_specversion"),
365: org.openide.util.NbBundle.getMessage (org.netbeans.core.Main.class, "HINT_modules_specversion")
366: ) {
367: public Object getValue () {
368: return null;
369: }
370:
371: }
372: }
373: );
374:
375: org.openide.explorer.ExplorerPanel ep = new org.openide.explorer.ExplorerPanel (em);
376: ep.setLayout (new java.awt.BorderLayout ());
377: ep.add ("Center", ttv);
378: ep.open ();
379: }
380: });
381: }
382: */
383: }
|