4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
7 * Wooyoung Cho <wooyoung1.cho@samsung.com>
8 * Shihyun Kim <shihyun.kim@samsung.com>
9 * Taeyoung Son <taeyoung2.son@samsung.com>
10 * Yongsung kim <yongsung1.kim@samsung.com>
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
16 * http://www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
29 package org.tizen.installmanager.ui.page;
31 import java.util.ArrayList;
32 import java.util.Collection;
34 import org.eclipse.swt.SWT;
35 import org.eclipse.swt.events.SelectionAdapter;
36 import org.eclipse.swt.events.SelectionEvent;
37 import org.eclipse.swt.widgets.Button;
38 import org.eclipse.swt.widgets.Composite;
39 import org.eclipse.swt.widgets.Label;
40 import org.tizen.installmanager.core.IMFatalException;
41 import org.tizen.installmanager.core.InstallManager;
42 import org.tizen.installmanager.core.SDKExtensionInfo;
43 import org.tizen.installmanager.lib.ErrorController;
44 import org.tizen.installmanager.lib.IMError;
45 import org.tizen.installmanager.lib.Log;
46 import org.tizen.installmanager.ui.InstallManagerWindow;
47 import org.tizen.installmanager.ui.model.Item;
48 import org.tizen.installmanager.pkg.lib.PackageManager;
49 import org.tizen.installmanager.pkg.model.Package;
52 * This class displays installable package list on page.
54 * @author Yongsung Kim <yongsung1.kim@samsung.com>
56 public class InstallableListPage extends PackageListPage {
58 static final String RSC_PATH_IMAGE = RESOURCE_PATH
59 + "/install_manager_graphicmotif_002.png";
60 static final String STRING_TITLE = "Install Type";
62 static final String TYPICAL_BUTTON_NAME = "Typical";
63 static final String MINIMAL_BUTTON_NAME = "Minimal";
64 static final String CUSTOM_BUTTON_NAME = "Custom";
66 private Composite buttonComposite;
68 // Install Type button
69 private Button typicalButton;
70 private Button minimalButton;
71 private Button customButton;
73 // Install Type Explain Label
74 private Label typicalLabel;
75 private Label minimalLabel;
81 public InstallableListPage(Composite parent, int style) {
82 super(parent, style, Type.INSTALL);
83 setLeftImageFromResource(RSC_PATH_IMAGE);
84 setTitleBounds(160, 3, 468, 20);
85 disableSubtitleBounds();
86 setTitle(STRING_TITLE);
88 buttonComposite = new Composite(this, SWT.NONE);
90 buttonComposite.setSize(468, 60);
91 buttonComposite.setLocation(160, 27);
93 .setBackground(InstallManagerWindow.getBackgroundColor());
99 * Set Install Type radio buttons.
101 private void setButtons() {
108 * Set Typical Type radio button.
110 private void setTypicalButton() {
111 if (typicalButton == null) {
112 typicalButton = new Button(buttonComposite, SWT.RADIO);
115 typicalButton.setSelection(true);
117 typicalButton.addSelectionListener(new SelectionAdapter() {
119 public void widgetSelected(SelectionEvent e) {
120 setCheckedByType(TYPICAL_BUTTON_NAME.toUpperCase());
121 checkboxTreeViewer.refresh();
122 checkboxTreeViewer.getTree().setEnabled(false);
124 lblRequiredSize.setText("Total space required : "
125 + convertToVolumeSize(getCheckedPackageSize()));
127 setNextBtnEnabledAboutCheckedPackageCount();
131 typicalButton.setBounds(0, 0, 80, 15);
132 typicalButton.setText(TYPICAL_BUTTON_NAME + ":");
133 typicalButton.setBackground(InstallManagerWindow.getBackgroundColor());
135 typicalLabel = new Label(buttonComposite, SWT.NONE);
136 typicalLabel.setBounds(81, 0, 410, 15);
140 * Set Minimal Type radio button.
142 private void setMinimalButton() {
143 if (minimalButton == null) {
144 minimalButton = new Button(buttonComposite, SWT.RADIO);
147 minimalButton.addSelectionListener(new SelectionAdapter() {
149 public void widgetSelected(SelectionEvent e) {
150 setCheckedByType(MINIMAL_BUTTON_NAME.toUpperCase());
151 checkboxTreeViewer.refresh();
152 checkboxTreeViewer.getTree().setEnabled(false);
154 lblRequiredSize.setText("Total space required : "
155 + convertToVolumeSize(getCheckedPackageSize()));
157 setNextBtnEnabledAboutCheckedPackageCount();
161 minimalButton.setBounds(0, 20, 80, 15);
162 minimalButton.setText(MINIMAL_BUTTON_NAME + ":");
163 minimalButton.setBackground(InstallManagerWindow.getBackgroundColor());
165 minimalLabel = new Label(buttonComposite, SWT.NONE);
166 minimalLabel.setBounds(81, 20, 410, 15);
170 * Set Custom Type radio button.
172 private void setCustomButton() {
173 if (customButton == null) {
174 customButton = new Button(buttonComposite, SWT.RADIO);
177 customButton.setBounds(0, 40, 80, 15);
178 customButton.setText(CUSTOM_BUTTON_NAME);
179 customButton.setBackground(InstallManagerWindow.getBackgroundColor());
181 customButton.addSelectionListener(new SelectionAdapter() {
183 public void widgetSelected(SelectionEvent e) {
184 checkboxTreeViewer.getTree().setEnabled(true);
190 * Check tree item by each install type.
192 private void setCheckedByType(String installType) {
193 if (installType == null || installType.isEmpty()) {
194 Log.err("Install type is empty. check install type or package server is old.");
196 Package pkg = InstallManager.getInstance().getPackageManager()
197 .getPackageByName(installType);
200 Log.err(installType + " do not exist in package list.");
204 Collection<Item> checkedItems = new ArrayList<Item>();
206 for (String pkgName : pkg.getDependentPackageNames()) {
207 Item item = findItem(pkgName, items);
210 checkedItems.add(item);
214 setCheckedItem(checkedItems);
217 private void setCheckedItem(Collection<Item> itemList) {
218 checkboxTreeViewer.setCheckedElements(itemList.toArray());
220 // refresh tree item. All of items are unchecked.
221 setAllChecked(false);
223 // check selected item.
224 for (Item item : itemList) {
225 setCheckbox(item, true);
230 * Display installable package list from view controller.
232 public boolean loadPage(ViewController controller) {
233 this.viewController = controller;
236 // back to next on component selection page case.
237 // in this case, page status should be typical selection case.
238 if (customButton.getSelection()) {
239 customButton.setSelection(false);
240 typicalButton.setSelection(true);
241 } else if (minimalButton.getSelection()) {
242 minimalButton.setSelection(false);
243 typicalButton.setSelection(true);
247 loadPackagesToTreeViewer(viewController.getRootMetaPackageListOfRepository());
249 SDKExtensionInfo sdkExtensionInfo = SDKExtensionInfo.getInstance();
250 addExtensionPackagesToExtra(sdkExtensionInfo.getExtensionPackages());
251 } catch (IMFatalException fatalException) {
252 Log.err(ErrorController.getErrorMessage());
253 IMError.fatalError(ErrorController.getErrorMessage());
256 checkboxTreeViewer.refresh();
258 if (getItems().size() <= 0) {
262 setCheckedByType(TYPICAL_BUTTON_NAME.toUpperCase());
263 checkboxTreeViewer.getTree().setEnabled(false);
265 checkboxTreeViewer.refresh();
267 setNextBtnEnabledAboutCheckedPackageCount();
268 lblRequiredSize.setText("Total space required : "
269 + convertToVolumeSize(getCheckedPackageSize()));
271 initDescriptionToInstallType();
276 private void initDescriptionToInstallType() {
277 PackageManager pm = PackageManager.getInstance();
279 //set typical description
280 String typicalExplain = "";
281 Package typicalPackage = pm.getPackageByName(TYPICAL_BUTTON_NAME.toUpperCase());
282 if (typicalPackage != null) {
283 typicalExplain = typicalPackage.getDescription();
286 typicalLabel.setText(typicalExplain);
287 typicalLabel.setBackground(InstallManagerWindow.getBackgroundColor());
289 //set minimal description
290 String minimalExplain = "";
291 Package minimalPackage = pm.getPackageByName(MINIMAL_BUTTON_NAME.toUpperCase());
292 if (minimalPackage != null) {
293 minimalExplain = minimalPackage.getDescription();
296 minimalLabel.setText(minimalExplain);
297 minimalLabel.setBackground(InstallManagerWindow.getBackgroundColor());
301 * Find item which should be checked in component tree.
304 * the name of item which should be checked.
306 * @return item which should be checked in component tree.
308 private Item findItem(String name, Collection<Item> itemList) {
310 for (Item item : itemList) {
311 if (name.equalsIgnoreCase(item.getPackageName())) {
314 Collection<Item> childItemList = item.getChildren();
316 if (childItemList.size() > 0) {
317 retItem = findItem(name, childItemList);
319 if (retItem != null) {