KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > spi > ui > UI


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.refactoring.spi.ui;
21
22 import java.awt.Component JavaDoc;
23 import javax.swing.Action JavaDoc;
24 import javax.swing.JLabel JavaDoc;
25 import javax.swing.SwingConstants JavaDoc;
26 import org.netbeans.modules.refactoring.api.RefactoringSession;
27 import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
28 import org.netbeans.modules.refactoring.spi.impl.RefactoringPanel;
29 import org.netbeans.modules.refactoring.spi.impl.RefactoringPanelContainer;
30 import org.openide.windows.TopComponent;
31
32 /**
33  * Various static UI helper methods
34  * @see RefactoringUI
35  * @author Jan Becicka
36  */

37 public final class UI {
38
39     private UI() {
40     }
41
42     /**
43      * Open Refactoring UI for specified RefactoringUI
44      * @param ui
45      * @see RefactoringUI
46      */

47     public static void openRefactoringUI(RefactoringUI ui) {
48         new RefactoringPanel(ui);
49     }
50     
51     /**
52      * Open Refactoring UI for specufied RefactoringUI from specified TopComponent.
53      * callerTC will get focus when refactoring is finished.
54      * @param ui
55      * @param callerTC
56      * @see RefactoringUI
57      */

58     public static void openRefactoringUI(RefactoringUI ui, TopComponent callerTC) {
59         new RefactoringPanel(ui, callerTC);
60     }
61
62     /**
63      * Open Refactoring UI for specufied RefactoringUI from specified TopComponent.
64      * callerTC will get focus when refactoring is finished.
65      * @param callback this action will be called when user clicks refresh button
66      * @param callerTC which component will get focus when refactoring is finished
67      * @param ui this RefactoringUI will open
68      * @see RefactoringUI
69      * @see RefactoringSession
70      */

71     public static void openRefactoringUI(RefactoringUI ui, RefactoringSession callerTC, Action JavaDoc callback) {
72         new RefactoringPanel(ui, callerTC, callback).setVisible(true);
73     }
74     
75     /**
76      * use this method from RefactoringElementImplementation.showPreview
77      * @param component is set as a preview component of RefactoringPanel
78      * @return component was successfuly set
79      */

80     public static boolean setComponentForRefactoringPreview(Component JavaDoc component) {
81         TopComponent activated = TopComponent.getRegistry().getActivated();
82         RefactoringPanel refactoringPanel = null;
83         if (activated instanceof RefactoringPanelContainer) {
84             RefactoringPanelContainer panel = (RefactoringPanelContainer) activated;
85             refactoringPanel = panel.getCurrentPanel();
86         }
87         if (refactoringPanel == null) {
88             refactoringPanel = RefactoringPanelContainer.getRefactoringComponent().getCurrentPanel();
89         }
90         if (refactoringPanel == null) {
91             refactoringPanel = RefactoringPanelContainer.getUsagesComponent().getCurrentPanel();
92         }
93         if (refactoringPanel == null)
94             return false;
95         if (component == null) {
96             if (refactoringPanel.splitPane.getRightComponent() == null)
97                 return false;
98             component = new JLabel JavaDoc("<Preview not Available>", SwingConstants.CENTER);
99         }
100         refactoringPanel.splitPane.setRightComponent(component);
101         return true;
102         
103     }
104 }
105
Popular Tags