2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.xml.schema.ui.nodes.categorized;
44
import java.awt.BorderLayout;
45
import java.awt.Color;
46
import java.awt.Component;
47
import java.awt.Container;
48
import java.awt.GridBagConstraints;
49
import java.awt.GridBagLayout;
50
import java.awt.Insets;
51
import java.awt.event.ActionEvent;
52
import java.awt.event.ActionListener;
53
import java.awt.event.FocusEvent;
54
import java.beans.PropertyChangeEvent;
55
import java.beans.PropertyVetoException;
56
import java.io.IOException;
57
import java.util.Date;
58
import javax.swing.JButton;
59
import javax.swing.JComponent;
60
import javax.swing.JPanel;
61
import javax.swing.JScrollPane;
62
import javax.swing.JTextArea;
63
import javax.swing.border.EmptyBorder;
64
import org.netbeans.modules.xml.schema.ui.basic.SchemaColumn;
65
import org.netbeans.modules.xml.xam.ui.column.ColumnProvider;
66
import org.netbeans.modules.xml.xam.ui.customizer.AbstractCustomizer;
67
import org.netbeans.modules.xml.xam.ui.customizer.Customizer;
68
import org.openide.ErrorManager;
69
import org.openide.nodes.AbstractNode;
70
import org.openide.nodes.Children;
71
import org.openide.nodes.Node;
72
import org.openide.util.HelpCtx;
73
import org.openide.util.Lookup;
74
import org.openide.util.LookupEvent;
75
import org.openide.util.LookupListener;
76
import org.openide.util.NbBundle;
77
import org.openide.util.lookup.Lookups;
80
* Inner class implementing details column.
82
* The customizer component provided by parent node is in the center.
83
* If no customizer is provided dummy will be used.
84
* The save and reset buttons will be in south.
86
public class DetailsColumn extends SchemaColumn
87
implements ActionListener, LookupListener
89
static final long serialVersionUID = 1L;
94
private boolean readonly;
97
* customizer as center panel
99
private Customizer customizer;
105
// private JLabel title;
108
* bottom panel containing buttons
110
private JPanel bottomPanel;
115
private JButton applyButton;
120
private JButton resetButton;
123
* scroll pane for main pael
125
private JScrollPane scrollPane;
128
private Lookup.Result lookupResult;
131
* Creates details column using the customizer
133
public DetailsColumn(Customizer cust)
135
super(null, null, false);
136
customizer = cust==null || cust.getComponent()==null
137
? new DummyDetails() : cust;
139
// listen to customizer lookup event of type ColumnProvider
140
lookupResult = getCustomizer().getLookup().lookup(
141
new Lookup.Template(ColumnProvider.class));
142
if(lookupResult!=null) lookupResult.addLookupListener(this);
147
* Initializes the details column
149
private void initialize()
151
setLayout(new BorderLayout());
152
setBackground(Color.white);
156
// title = new JLabel(getTitle(), SwingConstants.CENTER);
157
// add(title,BorderLayout.NORTH);
160
getCustomizer().getComponent().setBackground(Color.white);
161
add(getCustomizer().getComponent(),BorderLayout.CENTER);
162
scrollPane = new JScrollPane(getCustomizer().getComponent());
163
scrollPane.setBorder(null);
164
scrollPane.setViewportBorder(null);
165
add(scrollPane,BorderLayout.CENTER);
168
bottomPanel = new JPanel();
169
applyButton = new JButton();
170
applyButton.setText(NbBundle.getMessage(DetailsColumn.class, "LBL_DetailsColumn_ApplyButton"));
171
applyButton.setEnabled(false);
172
applyButton.addActionListener(this);
173
resetButton = new JButton();
174
resetButton.setText(NbBundle.getMessage(DetailsColumn.class, "LBL_DetailsColumn_ResetButton"));
175
resetButton.setEnabled(false);
176
resetButton.addActionListener(this);
177
bottomPanel.setLayout(new GridBagLayout());
178
GridBagConstraints gridBagConstraints = new GridBagConstraints();
179
gridBagConstraints.insets = new Insets(10, 10, 10, 2);
180
gridBagConstraints.anchor = GridBagConstraints.EAST;
181
gridBagConstraints.weightx = 1.0;
182
bottomPanel.add(applyButton,gridBagConstraints);
183
gridBagConstraints.insets = new Insets(10, 2, 10, 10);
184
gridBagConstraints.weightx = 0.0;
185
bottomPanel.add(resetButton,gridBagConstraints);
186
bottomPanel.setBackground(Color.white);
187
add(bottomPanel,BorderLayout.SOUTH);
189
// add this as propertychangelistener of customizer
190
getCustomizer().addPropertyChangeListener(this);
198
public String getTitle()
200
return NbBundle.getMessage(DetailsColumn.class, "LBL_DetailsColumn"); // NOI18N
203
// overridden as customizer component is main component
204
public boolean requestFocusInWindow()
206
return getCustomizer().getComponent().requestFocusInWindow();
213
public JComponent getComponent()
218
public boolean isShowing()
220
boolean retValue = super.isShowing();
223
boolean enable = !isReadOnly();
224
if(enable != getCustomizer().getComponent().isEnabled())
226
DetailsColumn.setEnabledComponent(getCustomizer().getComponent(),enable);
232
public boolean isReadOnly()
234
return readonly || !getCustomizer().isEditable();
237
public void setReadOnly(boolean readonly)
239
this.readonly = readonly;
242
private Customizer getCustomizer()
247
// property change events
248
// consider special events first
250
public void propertyChange(PropertyChangeEvent evt)
252
if(isReadOnly()) return;
253
if (evt.getPropertyName().equals(Customizer.PROP_ACTION_APPLY))
255
applyButton.setEnabled(((Boolean) evt.getNewValue()).booleanValue());
257
else if (evt.getPropertyName().equals(Customizer.PROP_ACTION_RESET))
259
resetButton.setEnabled(((Boolean) evt.getNewValue()).booleanValue());
262
super.propertyChange(evt);
266
public void actionPerformed(ActionEvent e)
268
if(isReadOnly()) return;
269
if (e.getSource() == applyButton)
273
getCustomizer().apply();
275
catch (IOException ioe)
277
String msg = NbBundle.getMessage(DetailsColumn.class, "MSG_DetailsColumn_ApplyFailed");
278
IllegalArgumentException iae = new IllegalArgumentException(msg);
279
ErrorManager.getDefault().annotate(iae, ErrorManager.USER,
280
msg, msg, ioe, new Date());
281
getCustomizer().reset();
285
else if (e.getSource() == resetButton)
287
getCustomizer().reset();
291
// overridden to not do anything on focus gained event
292
public void focusGained(FocusEvent e)
297
public void resultChanged(LookupEvent ev)
299
if(isReadOnly()) return;
300
Lookup.Result source = (Lookup.Result) ev.getSource();
301
if(source.allInstances().isEmpty())
303
getColumnView().removeColumnsAfter(this);
307
for (Object obj: source.allInstances())
309
if (obj instanceof ColumnProvider)
311
ColumnProvider columnProvider = (ColumnProvider)obj;
312
Node selNode = new AbstractNode(Children.LEAF,
313
Lookups.singleton(columnProvider));
314
getExplorerManager().setRootContext(selNode);
317
getExplorerManager().setSelectedNodes(new Node[]{selNode});
318
} catch (PropertyVetoException ex)
328
* Recursively enable/disable all components in the hierarchy under parent
330
private static void setEnabledComponent(Component component, boolean enabled)
332
component.setEnabled(enabled);
333
if(component instanceof Container)
335
Component[] children = ((Container)component).getComponents();
336
for (Component child:children)
338
setEnabledComponent(child, enabled);
344
* Inner class implementing customizer.
345
* Its just a dummy customizer.
347
static class DummyDetails extends AbstractCustomizer
350
static final long serialVersionUID = 1L;
352
public DummyDetails()
358
private void initialize()
360
JTextArea textArea = new JTextArea();
361
textArea.setText(NbBundle.getMessage(DetailsColumn.class, "LBL_DetailsColumn_NoCustomizer"));
362
textArea.setColumns(25);
363
textArea.setLineWrap(true);
364
textArea.setWrapStyleWord(true);
365
textArea.setEditable(false);
366
textArea.setBorder(new EmptyBorder(3,3,3,3));
373
setSaveEnabled(false);
379
setResetEnabled(false);
382
public boolean isEditable()
387
public HelpCtx getHelpCtx()
389
return HelpCtx.DEFAULT_HELP;
b'\\ No newline at end of file'