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.xslt.tmap.navigator;
020:
021: import java.awt.BorderLayout;
022: import java.awt.event.KeyEvent;
023: import javax.swing.ActionMap;
024: import javax.swing.InputMap;
025: import javax.swing.JComponent;
026: import javax.swing.JLabel;
027: import javax.swing.JPanel;
028: import javax.swing.KeyStroke;
029: import javax.swing.SwingUtilities;
030: import javax.swing.tree.TreeSelectionModel;
031: import org.netbeans.modules.soa.ui.ExtendedLookup;
032: import org.netbeans.modules.xml.xam.Model;
033: import org.netbeans.modules.xslt.tmap.model.api.TMapModel;
034: import org.netbeans.modules.xslt.tmap.nodes.LogicalTreeHandler;
035: import org.netbeans.modules.xslt.tmap.nodes.NavigatorNodeFactory;
036: import org.netbeans.modules.xslt.tmap.nodes.TransformMapNode;
037: import org.openide.ErrorManager;
038: import org.openide.util.HelpCtx;
039: import org.openide.util.Lookup;
040: import org.openide.explorer.ExplorerManager;
041: import org.openide.explorer.ExplorerUtils;
042: import org.openide.explorer.view.BeanTreeView;
043: import org.openide.nodes.Node;
044: import org.openide.util.NbBundle;
045: import org.openide.util.lookup.ProxyLookup;
046:
047: /**
048: *
049: * @author Vitaly Bychkov
050: * @version 1.0
051: */
052: public class TMapLogicalPanel extends JPanel implements
053: ExplorerManager.Provider, Lookup.Provider, HelpCtx.Provider {
054: private static final long serialVersionUID = 1L;
055: private static final String DELETE = "delete"; // NOI18N
056: private static final KeyStroke DELETE_KEYSTROKE = KeyStroke
057: .getKeyStroke(KeyEvent.VK_DELETE, 0); // NOI18N
058: private JLabel myMsgLabel;
059: private ExplorerManager myExplorerManager;
060: private LogicalTreeHandler myTreeHandler;
061:
062: // this navigator context lookup
063: private Lookup myContextLookup;
064:
065: private TMapModel myModel;
066: // this panel lookup
067: private Lookup myLookup;
068:
069: public TMapLogicalPanel() {
070: initComponent();
071: }
072:
073: public void navigate(Lookup contextLookup, TMapModel model) {
074: // get the model and create the new logical tree in background
075: if (contextLookup == null || model == null) {
076: return;
077: }
078: myModel = model;
079: myContextLookup = contextLookup;
080: showWaitMsg();
081: Thread treeThread = new Thread(new Runnable() {
082: public void run() {
083: showNavTree();
084: }
085: });
086: treeThread.start();
087:
088: // switch navigator to the appropriate view
089: // BpelNavigatorController.switchNavigatorPanel();
090: }
091:
092: protected TMapModel getModel() {
093: return myModel;
094: }
095:
096: public ExplorerManager getExplorerManager() {
097: return myExplorerManager;
098: }
099:
100: protected Lookup getContextLookup() {
101: return myContextLookup;
102: }
103:
104: public Lookup getLookup() {
105: return myLookup;
106: }
107:
108: public HelpCtx getHelpCtx() {
109: return HelpCtx.DEFAULT_HELP;
110: }
111:
112: private void initComponent() {
113: setLayout(new BorderLayout());
114: //init empty panel
115: myMsgLabel = new JLabel();
116: add(myMsgLabel, BorderLayout.CENTER);
117: }
118:
119: public void showWaitMsg() {
120: if (SwingUtilities.isEventDispatchThread()) {
121: showingWaitMessage();
122: } else {
123: SwingUtilities.invokeLater(new Runnable() {
124: public void run() {
125: showingWaitMessage();
126: }
127: });
128: }
129: }
130:
131: private void showingWaitMessage() {
132: removeAll();
133: myMsgLabel.setText(NbBundle.getMessage(TMapLogicalPanel.class,
134: "LBL_Wait")); // NOI18N
135: add(myMsgLabel, BorderLayout.CENTER);
136: repaint();
137: }
138:
139: private void showNavTree() {
140: final BeanTreeView beanTree = getBeanTreeView();
141: if (beanTree == null) {
142: return;
143: }
144:
145: SwingUtilities.invokeLater(new Runnable() {
146: public void run() {
147: removeAll();
148: add(beanTree);
149: revalidate();
150: }
151: });
152: }
153:
154: protected boolean initNavTree() {
155: myExplorerManager = new ExplorerManager();
156: if (!Model.State.VALID.equals(myModel.getState())) {
157: return false;
158: }
159: initActionMap();
160: Lookup contextLookup = getContextLookup();
161: Node rootNode = NavigatorNodeFactory.getInstance()
162: .getTransformMapNode(myModel, contextLookup);
163: if (rootNode == null) {
164: return false;
165: }
166: myExplorerManager.setRootContext(rootNode);
167: return true;
168: }
169:
170: protected BeanTreeView getBeanTreeView() {
171: boolean isInited = initNavTree();
172: if (!isInited) {
173: return null;
174: }
175:
176: BeanTreeView beanTree = null;
177: if (myTreeHandler != null) {
178: myTreeHandler.removeListeners();
179: myTreeHandler = null;
180: }
181:
182: myTreeHandler = new LogicalTreeHandler(myExplorerManager,
183: myModel, getContextLookup());
184:
185: beanTree = myTreeHandler.getBeanTreeView();
186: return beanTree;
187: }
188:
189: protected void initActionMap() {
190: ActionMap actionMap = getActionMap();
191:
192: // TODO add delete and some else actions support
193: // actionMap.put(DefaultEditorKit.copyAction,
194: // ExplorerUtils.actionCopy(myExplorerManager));
195: // actionMap.put(DefaultEditorKit.cutAction,
196: // ExplorerUtils.actionCut(myExplorerManager));
197: // actionMap.put(DefaultEditorKit.pasteAction,
198: // ExplorerUtils.actionPaste(myExplorerManager));
199: // actionMap.put(GOTOSOURCE,SystemAction.get(GoToSourceAction.class));
200: // actionMap.put(GOTODIAGRAMM,SystemAction.get(GoToDiagrammAction.class));
201: actionMap.put(DELETE, // NOI18N
202: ExplorerUtils.actionDelete(myExplorerManager, true));
203: ////// actionMap.put(FINDUSAGES, SystemAction.get(FindUsagesAction.class));
204: ////
205: InputMap keys = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
206: //// keys.put(KeyStroke.getKeyStroke("control C"), DefaultEditorKit.copyAction);// NOI18N
207: //// keys.put(KeyStroke.getKeyStroke("control X"), DefaultEditorKit.cutAction);// NOI18N
208: //// keys.put(KeyStroke.getKeyStroke("control V"), DefaultEditorKit.pasteAction);// NOI18N
209: keys.put(DELETE_KEYSTROKE, DELETE); // NOI18N
210: // keys.put(GOTOSOURCE_KEYSTROKE, GOTOSOURCE); // NOI18N
211: // keys.put(GOTODIAGRAMM_KEYSTROKE, GOTODIAGRAMM); // NOI18N
212: ////// keys.put((KeyStroke) SystemAction.get(FindUsagesAction.class)
213: ////// .getValue(FindUsagesAction.ACCELERATOR_KEY), FINDUSAGES); // NOI18N
214:
215: // ...and initialization of lookup variable
216:
217: //myLookup = ExplorerUtils.createLookup(myExplorerManager, actionMap);
218: myLookup = new ProxyLookup(myContextLookup, ExplorerUtils
219: .createLookup(myExplorerManager, actionMap));
220: }
221:
222: }
|