diff options
Diffstat (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/UstSettingDialogBase.java')
-rw-r--r-- | plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/UstSettingDialogBase.java | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/UstSettingDialogBase.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/UstSettingDialogBase.java new file mode 100644 index 0000000..70b0816 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/UstSettingDialogBase.java | |||
@@ -0,0 +1,170 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010 Intel Corporation. | ||
3 | * All rights reserved. This program and the accompanying materials | ||
4 | * are made available under the terms of the Eclipse Public License v1.0 | ||
5 | * which accompanies this distribution, and is available at | ||
6 | * http://www.eclipse.org/legal/epl-v10.html | ||
7 | * | ||
8 | * Contributors: | ||
9 | * Intel - initial API and implementation | ||
10 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import org.yocto.sdk.remotetools.Activator; | ||
14 | import org.yocto.sdk.remotetools.Messages; | ||
15 | import org.yocto.sdk.remotetools.SWTFactory; | ||
16 | import org.eclipse.jface.dialogs.IDialogSettings; | ||
17 | import org.eclipse.swt.SWT; | ||
18 | import org.eclipse.swt.events.ModifyEvent; | ||
19 | import org.eclipse.swt.events.ModifyListener; | ||
20 | import org.eclipse.swt.layout.GridData; | ||
21 | import org.eclipse.swt.layout.GridLayout; | ||
22 | import org.eclipse.swt.widgets.Combo; | ||
23 | import org.eclipse.swt.widgets.Composite; | ||
24 | import org.eclipse.swt.widgets.Control; | ||
25 | import org.eclipse.swt.widgets.Label; | ||
26 | import org.eclipse.swt.widgets.Shell; | ||
27 | import org.eclipse.linuxtools.tmf.core.TmfProjectNature; | ||
28 | import org.eclipse.core.resources.IWorkspaceRoot; | ||
29 | import org.eclipse.core.resources.ResourcesPlugin; | ||
30 | import org.eclipse.core.resources.IProject; | ||
31 | |||
32 | |||
33 | public class UstSettingDialogBase extends BaseSettingDialog { | ||
34 | protected Label projectLabel; | ||
35 | protected Combo projectCombo; | ||
36 | protected String curProject = null; | ||
37 | |||
38 | protected UstSettingDialogBase(Shell parentShell, String title, String conn) { | ||
39 | super(parentShell,title,conn); | ||
40 | } | ||
41 | |||
42 | public String getProject() { | ||
43 | return curProject; | ||
44 | } | ||
45 | |||
46 | @Override | ||
47 | protected void okPressed() { | ||
48 | IDialogSettings settings = Activator.getDefault().getDialogSettings(); | ||
49 | // store the value of the generate sections checkbox | ||
50 | if(getCurrentConnection()==null) { | ||
51 | settings.put(IBaseConstants.CONNECTION_NAME_UST, | ||
52 | (String)null); | ||
53 | }else { | ||
54 | settings.put(IBaseConstants.CONNECTION_NAME_UST, | ||
55 | getCurrentConnection().getAliasName()); | ||
56 | } | ||
57 | super.okPressed(); | ||
58 | } | ||
59 | |||
60 | @Override | ||
61 | protected Control createDialogArea(Composite parent) { | ||
62 | Composite comp=(Composite)super.createDialogArea(parent); | ||
63 | GridLayout topLayout = new GridLayout(); | ||
64 | comp.setLayout(topLayout); | ||
65 | |||
66 | /*argument*/ | ||
67 | SWTFactory.createVerticalSpacer(comp, 1); | ||
68 | createImportProjectGroup(comp); | ||
69 | createArgument(comp); | ||
70 | |||
71 | updateOkButton(); | ||
72 | return comp; | ||
73 | } | ||
74 | |||
75 | protected void createImportProjectGroup(Composite parent) { | ||
76 | Composite projComp = new Composite(parent, SWT.NONE); | ||
77 | GridLayout projLayout = new GridLayout(); | ||
78 | projLayout.numColumns = 6; | ||
79 | projLayout.marginHeight = 0; | ||
80 | projLayout.marginWidth = 0; | ||
81 | projComp.setLayout(projLayout); | ||
82 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
83 | projComp.setLayoutData(gd); | ||
84 | |||
85 | projectLabel = new Label(projComp, SWT.NONE); | ||
86 | projectLabel.setText(Messages.Import_to_Project); | ||
87 | gd = new GridData(); | ||
88 | gd.horizontalSpan = 1; | ||
89 | projectLabel.setLayoutData(gd); | ||
90 | |||
91 | projectCombo = new Combo(projComp, SWT.DROP_DOWN | SWT.READ_ONLY); | ||
92 | gd = new GridData(GridData.FILL_HORIZONTAL); | ||
93 | gd.horizontalSpan = 4; | ||
94 | projectCombo.setLayoutData(gd); | ||
95 | projectCombo.addModifyListener(new ModifyListener() { | ||
96 | |||
97 | public void modifyText(ModifyEvent e) { | ||
98 | updateCurProject(); | ||
99 | } | ||
100 | }); | ||
101 | |||
102 | updateProjectPulldown(); | ||
103 | } | ||
104 | |||
105 | protected void updateCurProject() { | ||
106 | IProject currentProjectSelected = getCurrentProject(); | ||
107 | |||
108 | if (currentProjectSelected != null) | ||
109 | curProject = currentProjectSelected.getName(); | ||
110 | |||
111 | updateOkButton(); | ||
112 | } | ||
113 | |||
114 | protected IProject getCurrentProject() { | ||
115 | if (projectCombo.getItemCount() == 0) | ||
116 | return null; | ||
117 | int currentSelection = projectCombo.getSelectionIndex(); | ||
118 | String importProject = currentSelection >= 0 ? projectCombo | ||
119 | .getItem(currentSelection) : null; | ||
120 | IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); | ||
121 | IProject project = wsroot.getProject(importProject); | ||
122 | return project; | ||
123 | } | ||
124 | |||
125 | protected void updateProjectPulldown() { | ||
126 | int index=-1; | ||
127 | |||
128 | projectCombo.removeAll(); | ||
129 | IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); | ||
130 | IProject[] projects = wsroot.getProjects(); | ||
131 | |||
132 | for (int i = 0; i < projects.length; ++i) { | ||
133 | try { | ||
134 | if (projects[i].isOpen() && projects[i].hasNature(TmfProjectNature.ID)) { | ||
135 | String projName = projects[i].getName(); | ||
136 | projectCombo.add(projName); | ||
137 | if (curProject != null) | ||
138 | if (projName.matches(curProject)) | ||
139 | index = i; | ||
140 | } | ||
141 | } catch (Exception e) { | ||
142 | // TODO Auto-generated catch block | ||
143 | e.printStackTrace(); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | if(index>=0) { | ||
148 | projectCombo.select(index); | ||
149 | }else if (projectCombo.getItemCount()> 0) { | ||
150 | projectCombo.select(projectCombo.getItemCount() - 1); | ||
151 | } | ||
152 | |||
153 | //TODO | ||
154 | //connectionCombo.computeSize(SWT.DEFAULT, SWT.DEFAULT,true); | ||
155 | projectCombo.pack(true); | ||
156 | projectCombo.layout(); | ||
157 | projectCombo.getParent().layout(); | ||
158 | |||
159 | updateCurProject(); | ||
160 | } | ||
161 | protected void createArgument(Composite parent) | ||
162 | { | ||
163 | } | ||
164 | |||
165 | @Override | ||
166 | protected boolean updateOkButton() { | ||
167 | boolean ret=super.updateOkButton(); | ||
168 | return ret; | ||
169 | } | ||
170 | } | ||