c5c328c9f0832617287fcc5a4d4d5dc17022670c
[sdk/ide/common-eplugin.git] / org.tizen.common / src / org / tizen / common / swt / TrayWizardPage.java
1 /*
2 *  Common
3 *
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5 *
6 * Contact: 
7 * Kangho Kim <kh5325.kim@samsung.com>
8
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 * Contributors:
22 * - S-Core Co., Ltd
23 *
24 */
25
26 package org.tizen.common.swt;
27
28 import org.eclipse.jface.dialogs.DialogTray;
29 import org.eclipse.jface.dialogs.TrayDialog;
30 import org.eclipse.jface.resource.ImageDescriptor;
31 import org.eclipse.jface.wizard.IWizardContainer;
32 import org.eclipse.jface.wizard.WizardPage;
33 import org.eclipse.swt.SWT;
34 import org.eclipse.swt.events.SelectionEvent;
35 import org.eclipse.swt.events.SelectionListener;
36 import org.eclipse.swt.layout.GridData;
37 import org.eclipse.swt.layout.GridLayout;
38 import org.eclipse.swt.widgets.Button;
39 import org.eclipse.swt.widgets.Composite;
40 import org.eclipse.swt.widgets.Control;
41
42
43 /**
44  * a extended WizardPage class using ClosableTray class
45  * 
46  * @author Jihoon Song {@literal <jihoon80.song@samsung.com>} (S-Core)
47  */
48 public abstract class TrayWizardPage extends WizardPage {
49     
50     protected TrayWizardPage(String pageName) {
51         super(pageName);
52     }
53     
54     protected TrayWizardPage(String pageName, String title, ImageDescriptor titleImage) {
55         super(pageName, title, titleImage);
56     }
57     
58     /**
59      * a extended WizardPage class using ClosableTray class
60      * 
61      * @param parent a composite control which will be the parent of the new instance (cannot be null)
62      * @param buttonText the new text of Button control
63      * @param tray the ClosableTray to show in dialog
64      * @return <b>Control</b> - return created Button control
65      */
66     protected Control createTrayButtonControl(Composite parent, String buttonText, final ClosableTray tray) {
67         Composite child = new Composite(parent, SWT.NONE);
68         child.setLayout(new GridLayout());
69         child.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
70         
71         Button expandButton = new Button(child, SWT.NONE);
72         expandButton.setText(buttonText);
73         expandButton.addSelectionListener(new SelectionListener() {
74             @Override
75             public void widgetSelected(SelectionEvent e) {
76                 openClosableTray(tray);
77             }
78             
79             @Override
80             public void widgetDefaultSelected(SelectionEvent e) {
81             }
82         });
83         
84         return expandButton;
85     }
86     
87     /**
88      * open a tray using ClosableTray class. If another tray was opened, open new tray after close the opened tray automatically
89      * 
90      * @param tray the ClosableTray to show in dialog
91      * @return <b>Control</b> - return created Button control
92      */
93     protected void openClosableTray(ClosableTray tray) {
94         IWizardContainer wc = getContainer();
95         if (wc instanceof TrayDialog) {
96             TrayDialog wd = (TrayDialog) wc;
97             
98             // alreay opened
99             DialogTray currentTray = wd.getTray();
100             if (! (currentTray instanceof ClosableTray)) {
101                 if (currentTray != null) {
102                     wd.closeTray();
103                 }
104                 wd.openTray(tray);
105             }
106         }
107     }
108 }