KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > exports > AbstractExportTab


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.wizards.exports;
12
13 import org.eclipse.jface.dialogs.IDialogSettings;
14 import org.eclipse.pde.internal.ui.PDEPlugin;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.widgets.Combo;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19 import org.eclipse.swt.widgets.FileDialog;
20
21 public abstract class AbstractExportTab {
22     
23     protected AbstractExportWizardPage fPage;
24     
25     public AbstractExportTab(AbstractExportWizardPage page) {
26         fPage = page;
27     }
28     
29     protected abstract Control createControl(Composite parent);
30
31     protected abstract void initialize(IDialogSettings settings);
32     
33     protected abstract void saveSettings(IDialogSettings settings);
34
35     protected void initializeCombo(IDialogSettings settings, String JavaDoc key, Combo combo) {
36         for (int i = 0; i < 6; i++) {
37             String JavaDoc curr = settings.get(key + String.valueOf(i));
38             if (curr != null && combo.indexOf(curr) == -1) {
39                 combo.add(curr);
40             }
41         }
42         if (combo.getItemCount() > 0)
43             combo.setText(combo.getItem(0));
44     }
45
46     protected void saveCombo(IDialogSettings settings, String JavaDoc key, Combo combo) {
47         if (combo.getText().trim().length() > 0) {
48             settings.put(key + String.valueOf(0), combo.getText().trim());
49             String JavaDoc[] items = combo.getItems();
50             int nEntries = Math.min(items.length, 5);
51             for (int i = 0; i < nEntries; i++) {
52                 settings.put(key + String.valueOf(i + 1), items[i].trim());
53             }
54         }
55     }
56     
57     protected void chooseFile(Combo combo, String JavaDoc filter) {
58         FileDialog dialog = new FileDialog(fPage.getShell(), SWT.SAVE);
59         String JavaDoc path = combo.getText();
60         if (path.trim().length() == 0)
61             path = PDEPlugin.getWorkspace().getRoot().getLocation().toString();
62         dialog.setFileName(path);
63         dialog.setFilterExtensions(new String JavaDoc[] { filter });
64         String JavaDoc res = dialog.open();
65         if (res != null) {
66             if (combo.indexOf(res) == -1)
67                 combo.add(res, 0);
68             combo.setText(res);
69         }
70     }
71
72
73 }
74
Popular Tags