KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.resources.IFile;
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.jface.dialogs.IDialogSettings;
16 import org.eclipse.pde.internal.ui.IPDEUIConstants;
17 import org.eclipse.pde.internal.ui.PDEUIMessages;
18 import org.eclipse.pde.internal.ui.util.SWTUtil;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.widgets.Button;
23 import org.eclipse.swt.widgets.Combo;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Control;
26 import org.eclipse.swt.widgets.Group;
27
28 public class ProductDestinationGroup extends ExportDestinationTab {
29
30     public ProductDestinationGroup(ProductExportWizardPage page) {
31         super(page);
32     }
33
34     public Control createControl(Composite parent) {
35         Group group = new Group(parent, SWT.NONE);
36         group.setText(PDEUIMessages.ExportWizard_destination);
37         group.setLayout(new GridLayout(3, false));
38         group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
39
40         fDirectoryButton = new Button(group, SWT.RADIO);
41         fDirectoryButton.setText(PDEUIMessages.ExportWizard_directory);
42
43         fDirectoryCombo = new Combo(group, SWT.BORDER);
44         fDirectoryCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
45
46         fBrowseDirectory = new Button(group, SWT.PUSH);
47         fBrowseDirectory.setText(PDEUIMessages.ExportWizard_browse);
48         fBrowseDirectory.setLayoutData(new GridData());
49         SWTUtil.setButtonDimensionHint(fBrowseDirectory);
50
51         fArchiveFileButton = new Button(group, SWT.RADIO);
52         fArchiveFileButton.setText(PDEUIMessages.ExportWizard_archive);
53
54         fArchiveCombo = new Combo(group, SWT.BORDER);
55         fArchiveCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
56
57         fBrowseFile = new Button(group, SWT.PUSH);
58         fBrowseFile.setText(PDEUIMessages.ExportWizard_browse);
59         fBrowseFile.setLayoutData(new GridData());
60         SWTUtil.setButtonDimensionHint(fBrowseFile);
61
62         return group;
63     }
64     
65     protected void initialize(IDialogSettings settings, IFile file) {
66         try {
67             String JavaDoc toDirectory =
68                     (file != null)
69                     ? file.getPersistentProperty(IPDEUIConstants.DEFAULT_PRODUCT_EXPORT_DIR)
70                     : null;
71             if (toDirectory == null)
72                 toDirectory = settings.get(S_EXPORT_DIRECTORY);
73             boolean useDirectory = toDirectory == null || "true".equals(toDirectory); //$NON-NLS-1$
74
fDirectoryButton.setSelection(useDirectory);
75             fArchiveFileButton.setSelection(!useDirectory);
76             toggleDestinationGroup(useDirectory);
77             
78             initializeCombo(settings, S_DESTINATION, fDirectoryCombo);
79             initializeCombo(settings, S_ZIP_FILENAME, fArchiveCombo);
80             
81             updateDestination(file);
82             hookListeners();
83         } catch (CoreException e) {
84         }
85     }
86     
87     protected void updateDestination(IFile file) {
88         try {
89             if (file == null)
90                 return;
91             String JavaDoc toDirectory = file.getPersistentProperty(IPDEUIConstants.DEFAULT_PRODUCT_EXPORT_DIR);
92             if (toDirectory == null)
93                 return;
94             boolean useDirectory = "true".equals(toDirectory); //$NON-NLS-1$
95
fArchiveFileButton.setSelection(!useDirectory);
96             fDirectoryButton.setSelection(useDirectory);
97             toggleDestinationGroup(useDirectory);
98             
99             Combo combo = useDirectory? fDirectoryCombo : fArchiveCombo;
100             String JavaDoc destination = file.getPersistentProperty(IPDEUIConstants.DEFAULT_PRODUCT_EXPORT_LOCATION);
101             if (destination != null) {
102                 if (combo.indexOf(destination) == -1)
103                     combo.add(destination, 0);
104                 combo.setText(destination);
105             }
106         } catch (CoreException e) {
107         }
108     }
109     
110     protected void saveSettings(IDialogSettings settings) {
111         super.saveSettings(settings);
112         IFile file = ((ProductExportWizardPage)fPage).getProductFile();
113         try {
114             if (file != null && file.exists()) {
115                 file.setPersistentProperty(IPDEUIConstants.DEFAULT_PRODUCT_EXPORT_DIR,
116                                         Boolean.toString(doExportToDirectory()));
117                 file.setPersistentProperty(IPDEUIConstants.DEFAULT_PRODUCT_EXPORT_LOCATION,
118                         doExportToDirectory() ? fDirectoryCombo.getText().trim() : fArchiveCombo.getText().trim());
119             }
120         } catch (CoreException e) {
121         }
122     }
123     
124
125 }
126
Popular Tags