KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > design > multiview > DesignMultiViewElement


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.design.multiview;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.ObjectInput JavaDoc;
25 import java.io.ObjectOutput JavaDoc;
26 import javax.swing.JComponent JavaDoc;
27 import javax.swing.JToolBar JavaDoc;
28 import org.openide.windows.TopComponent;
29 import org.openide.awt.UndoRedo;
30 import org.netbeans.core.spi.multiview.CloseOperationState;
31 import org.netbeans.core.spi.multiview.MultiViewElement;
32 import org.netbeans.core.spi.multiview.MultiViewElementCallback;
33 import org.netbeans.modules.websvc.api.jaxws.project.config.Service;
34 import org.netbeans.modules.websvc.design.view.DesignView;
35 import org.openide.filesystems.FileObject;
36 import org.openide.util.lookup.Lookups;
37
38 /**
39  *
40  * @author Ajit Bhate
41  */

42 public class DesignMultiViewElement extends TopComponent
43         implements MultiViewElement {
44     /** silence compiler warnings */
45     private static final long serialVersionUID = 1L;
46     private transient MultiViewElementCallback multiViewCallback;
47     private transient JToolBar JavaDoc toolbar;
48     private transient DesignView designView;
49     private transient Service service;
50     private transient FileObject implementationClass;
51
52     /**
53      * Nullary constructor for deserialization.
54      */

55     public DesignMultiViewElement() {
56     }
57     
58     /**
59      *
60      * @param mvSupport
61      */

62     public DesignMultiViewElement(MultiViewSupport mvSupport) {
63         this();
64         initialize(mvSupport);
65     }
66     
67     private void initialize(MultiViewSupport mvSupport) {
68         associateLookup(Lookups.fixed(mvSupport));
69         service = mvSupport.getService();
70         implementationClass = mvSupport.getDataObject().getPrimaryFile();
71     }
72     
73     public int getPersistenceType() {
74         return PERSISTENCE_NEVER;
75     }
76     
77     public void setMultiViewCallback(MultiViewElementCallback callback) {
78         multiViewCallback = callback;
79     }
80     
81     public CloseOperationState canCloseElement() {
82         return CloseOperationState.STATE_OK;
83     }
84     
85     
86     /**
87      * Initializes the UI. Here it checks for the state of the underlying
88      * schema model. If valid, draws the UI, else empties the UI with proper
89      * error message.
90      */

91     private void initUI() {
92         setLayout(new BorderLayout JavaDoc());
93         designView = new DesignView(service,implementationClass);
94         add(designView);
95     }
96     
97     
98     public void componentActivated() {
99         super.componentActivated();
100     }
101     
102     public void componentDeactivated() {
103         super.componentDeactivated();
104     }
105     
106     public void componentOpened() {
107         super.componentOpened();
108         // create UI, this will be moved to componentShowing for refresh/sync
109
initUI();
110     }
111     
112     public void componentClosed() {
113         super.componentClosed();
114     }
115     
116     public void componentShowing() {
117         super.componentShowing();
118     }
119     
120     public void componentHidden() {
121         super.componentHidden();
122     }
123     
124     public JComponent JavaDoc getToolbarRepresentation() {
125         // This is called every time user switches between elements.
126
if (toolbar == null) {
127             toolbar = new JToolBar JavaDoc();
128             toolbar.setFloatable(false);
129         }
130         return toolbar;
131     }
132     
133     public UndoRedo getUndoRedo() {
134         return super.getUndoRedo();
135     }
136     
137     public JComponent JavaDoc getVisualRepresentation() {
138         return this;
139     }
140     
141     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
142         // The superclass persists things such as the caret position.
143
super.writeExternal(out);
144         Object JavaDoc obj = getLookup().lookup(MultiViewSupport.class);
145         if(obj!=null) {
146             out.writeObject(obj);
147         }
148     }
149     
150     public void readExternal(ObjectInput JavaDoc in)
151             throws IOException JavaDoc, ClassNotFoundException JavaDoc {
152         super.readExternal(in);
153     Object JavaDoc firstObject = in.readObject();
154     if (firstObject instanceof MultiViewSupport ) {
155             initialize((MultiViewSupport)firstObject);
156     }
157     }
158     
159 }
160
Popular Tags