01: /*******************************************************************************
02: * Copyright (c) 2005, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.exports;
11:
12: import org.eclipse.jface.dialogs.IDialogSettings;
13: import org.eclipse.pde.internal.ui.PDEPlugin;
14: import org.eclipse.swt.SWT;
15: import org.eclipse.swt.widgets.Combo;
16: import org.eclipse.swt.widgets.Composite;
17: import org.eclipse.swt.widgets.Control;
18: import org.eclipse.swt.widgets.FileDialog;
19:
20: public abstract class AbstractExportTab {
21:
22: protected AbstractExportWizardPage fPage;
23:
24: public AbstractExportTab(AbstractExportWizardPage page) {
25: fPage = page;
26: }
27:
28: protected abstract Control createControl(Composite parent);
29:
30: protected abstract void initialize(IDialogSettings settings);
31:
32: protected abstract void saveSettings(IDialogSettings settings);
33:
34: protected void initializeCombo(IDialogSettings settings,
35: String key, Combo combo) {
36: for (int i = 0; i < 6; i++) {
37: String 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 key,
47: Combo combo) {
48: if (combo.getText().trim().length() > 0) {
49: settings.put(key + String.valueOf(0), combo.getText()
50: .trim());
51: String[] items = combo.getItems();
52: int nEntries = Math.min(items.length, 5);
53: for (int i = 0; i < nEntries; i++) {
54: settings.put(key + String.valueOf(i + 1), items[i]
55: .trim());
56: }
57: }
58: }
59:
60: protected void chooseFile(Combo combo, String filter) {
61: FileDialog dialog = new FileDialog(fPage.getShell(), SWT.SAVE);
62: String path = combo.getText();
63: if (path.trim().length() == 0)
64: path = PDEPlugin.getWorkspace().getRoot().getLocation()
65: .toString();
66: dialog.setFileName(path);
67: dialog.setFilterExtensions(new String[] { filter });
68: String res = dialog.open();
69: if (res != null) {
70: if (combo.indexOf(res) == -1)
71: combo.add(res, 0);
72: combo.setText(res);
73: }
74: }
75:
76: }
|