KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > dialogs > AbstractPreferenceImportExportPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.dialogs;
13
14 import java.net.URL JavaDoc;
15
16 import org.eclipse.jface.dialogs.IDialogConstants;
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.jface.wizard.WizardPage;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.widgets.Button;
21 import org.eclipse.ui.PlatformUI;
22 import org.eclipse.ui.internal.WorkbenchMessages;
23 import org.eclipse.ui.internal.util.BundleUtility;
24
25
26 /**
27  * An abstract class with some utility methods and common values to share
28  * between preference import/export wizard pages.
29  *
30  * @since 3.0
31  */

32 abstract class AbstractPreferenceImportExportPage extends WizardPage {
33     
34     /**
35      * The title for all pages involved in the export operation.
36      */

37     protected static final String JavaDoc EXPORT_TITLE = WorkbenchMessages.getString("ImportExportPages.exportTitle"); //$NON-NLS-1$
38
/**
39      * The title for all pages involved in the export operation.
40      */

41     protected static final String JavaDoc IMPORT_TITLE = WorkbenchMessages.getString("ImportExportPages.importTitle"); //$NON-NLS-1$
42
/**
43      * The default extension for preferences files.
44      */

45     protected static final String JavaDoc PREFERENCE_EXT = ".epf"; //$NON-NLS-1$
46

47     /**
48      * Retrieves the image descriptor from the given relative path. The path is
49      * relative from the "icons/full" directory.
50      * @param relativePath The relative path; should not be <code>null</code>.
51      * @return The image descriptor if it can be found; otherwise, the "missing
52      * image" descriptor.
53      */

54     protected static ImageDescriptor getImageDescriptor(String JavaDoc relativePath) {
55         String JavaDoc path = "icons/full/" + relativePath; //$NON-NLS-1$
56
URL JavaDoc url = BundleUtility.find(PlatformUI.PLUGIN_ID, path);
57
58         return url != null
59                 ? ImageDescriptor.createFromURL(url)
60                 : ImageDescriptor.getMissingImageDescriptor();
61     }
62
63     /**
64      * Whether this page was opened in export or import mode. Since there is a
65      * significant amount of overlap, the import and export pages are not
66      * separate classes.
67      */

68     protected final boolean export;
69     
70     /**
71      * Constructs a new instance of a preference import/export page with the
72      * given name.
73      * @param name The name of the page to be constructed; must not be
74      * <code>null</code>.
75      * @param exportWizard Whether this page should be opened in export mode.
76      */

77     protected AbstractPreferenceImportExportPage(final String JavaDoc name, final boolean exportWizard) {
78         super(name);
79         
80         export = exportWizard;
81     }
82     
83     /**
84      * Computes the width hint for the given button. The width hint is the
85      * maximum of the default width and the minimum width to display the button
86      * text.
87      * @param pushButton The push button for which to compute the width hint.
88      * @return The width hint, which should be a positive integer capable of
89      * displaying all the text in the button.
90      */

91     protected int computePushButtonWidthHint(Button pushButton) {
92         final int defaultWidth = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
93         final int minimumWidth = pushButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x;
94         return Math.max(defaultWidth, minimumWidth) + 5;
95     }
96 }
97
Popular Tags