001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.bpel.properties.editors.controls;
020:
021: import java.awt.BorderLayout;
022: import java.lang.reflect.Constructor;
023: import javax.swing.JPanel;
024: import org.netbeans.modules.soa.ui.form.CustomNodeEditor;
025: import org.netbeans.modules.bpel.nodes.BpelNode;
026: import org.netbeans.modules.soa.ui.SoaUiUtil;
027: import org.openide.ErrorManager;
028: import org.openide.util.HelpCtx;
029:
030: public class SimpleCustomEditor<T> extends AbstractCustomNodeEditor<T> {
031:
032: private static final long serialVersionUID = 1L;
033:
034: private JPanel mainPanel;
035: private Class<? extends JPanel> mainPanelClass;
036:
037: public SimpleCustomEditor(BpelNode<T> node,
038: Class<? extends JPanel> mainPanelClass, EditingMode mode) {
039: super (node);
040: this .mainPanelClass = mainPanelClass;
041: if (mode != null) {
042: setEditingMode(mode);
043: }
044: createContent();
045: initControls();
046: subscribeListeners();
047: }
048:
049: public SimpleCustomEditor(BpelNode<T> node, JPanel mainPanel,
050: EditingMode mode) {
051: super (node);
052: this .mainPanel = mainPanel;
053: this .mainPanelClass = mainPanel.getClass();
054: //
055: if (mainPanel instanceof CustomNodeEditor.Owner) {
056: ((CustomNodeEditor.Owner) mainPanel).setEditor(this );
057: }
058: //
059: if (mode != null) {
060: setEditingMode(mode);
061: }
062: createContent();
063: initControls();
064: subscribeListeners();
065: }
066:
067: public void createContent() {
068: this .setLayout(new BorderLayout());
069: // this.setBorder(BorderFactory.createEmptyBorder(4, 4, 0, 4));
070: //
071: if (mainPanel == null) {
072: try {
073: Constructor<? extends JPanel> constructor = mainPanelClass
074: .getConstructor(CustomNodeEditor.class);
075: mainPanel = constructor.newInstance(this );
076: } catch (Exception ex) {
077: ErrorManager.getDefault().notify(ex);
078: }
079: }
080: //
081: if (mainPanel != null) {
082: this .add(mainPanel, BorderLayout.CENTER);
083: // The accessibleContext is derived from the main child panel.
084: accessibleContext = mainPanel.getAccessibleContext();
085: }
086: //
087: SoaUiUtil.activateInlineMnemonics(this );
088: }
089:
090: public JPanel getMainPanel() {
091: return mainPanel;
092: }
093:
094: public HelpCtx getHelpCtx() {
095: if (mainPanel != null && mainPanel instanceof HelpCtx.Provider) {
096: return ((HelpCtx.Provider) mainPanel).getHelpCtx();
097: } else if (mainPanelClass != null) {
098: return new HelpCtx(mainPanelClass);
099: }
100: return null;
101: }
102:
103: }
|