| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2006 IBM Corporation and others. |
| // All rights reserved. This program and the accompanying materials |
| // are made available under the terms of the Eclipse Public License v1.0 |
| // which accompanies this distribution, and is available at |
| // http://www.eclipse.org/legal/epl-v10.html |
| // |
| // Contributors: |
| // IBM Corporation - initial implementation |
| //------------------------------------------------------------------------------ |
| package org.eclipse.epf.publishing.ui.preferences; |
| |
| import org.eclipse.epf.authoring.ui.AuthoringUIText; |
| import org.eclipse.epf.authoring.ui.preferences.CommonPrefPage; |
| import org.eclipse.epf.library.LibraryPlugin; |
| import org.eclipse.epf.publishing.PublishingPlugin; |
| import org.eclipse.epf.publishing.ui.PublishingUIResources; |
| import org.eclipse.jface.preference.IPreferenceStore; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.events.ModifyEvent; |
| import org.eclipse.swt.events.ModifyListener; |
| import org.eclipse.swt.events.SelectionAdapter; |
| import org.eclipse.swt.events.SelectionEvent; |
| import org.eclipse.swt.events.SelectionListener; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.layout.GridLayout; |
| import org.eclipse.swt.widgets.Button; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Control; |
| import org.eclipse.swt.widgets.DirectoryDialog; |
| import org.eclipse.swt.widgets.Group; |
| import org.eclipse.swt.widgets.Label; |
| import org.eclipse.swt.widgets.Text; |
| import org.eclipse.ui.IWorkbench; |
| import org.eclipse.ui.IWorkbenchPreferencePage; |
| |
| |
| /** |
| * The Preference page for the Publishing UI. |
| * |
| * @author Kelvin Low |
| * @since 1.0 |
| */ |
| public class PublishingPreferencePage extends CommonPrefPage implements |
| IWorkbenchPreferencePage, SelectionListener, ModifyListener { |
| |
| private Composite composite; |
| |
| private Text destinationPathText; |
| |
| private Text feedbackURLText; |
| |
| private Button browseButton; |
| |
| protected Control createContents(Composite parent) { |
| composite = new Composite(parent, SWT.NULL); |
| composite.setLayout(new GridLayout(1, false)); |
| |
| // Create the Destination Path group. |
| Group destinationGroup = new Group(composite, SWT.NULL); |
| destinationGroup.setLayout(new GridLayout(3, false)); |
| destinationGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| destinationGroup |
| .setText(PublishingUIResources |
| .getString("PublishingUI.publishConfigWizard.destinationGroup.text")); //$NON-NLS-1$ |
| |
| createLabel(destinationGroup, PublishingUIResources |
| .getString("PublishingUI.preferencePage.defaultPath.text")); //$NON-NLS-1$ |
| destinationPathText = createEditableText(destinationGroup, ""); //$NON-NLS-1$ |
| destinationPathText.setText(PublishingUIPreferences.getPublishPath()); |
| browseButton = new Button(destinationGroup, SWT.NONE); |
| browseButton.setText(AuthoringUIText.BROWSE_BUTTON_TEXT); |
| |
| // Create the Published Website group. |
| Group webSiteGroup = new Group(composite, SWT.NULL); |
| webSiteGroup.setLayout(new GridLayout(2, false)); |
| webSiteGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| webSiteGroup.setText(PublishingUIResources |
| .getString("PublishingUI.publishConfigWizard.webSite.text")); //$NON-NLS-1$ |
| |
| createLabel(webSiteGroup, PublishingUIResources |
| .getString("PublishingUI.publishConfigWizard.feedbackURL.text")); //$NON-NLS-1$ |
| feedbackURLText = createEditableText(webSiteGroup, ""); //$NON-NLS-1$ |
| feedbackURLText.setText(PublishingUIPreferences.getFeedbackURL()); |
| createLabel(webSiteGroup, ""); //$NON-NLS-1$ |
| |
| initializeValues(); |
| |
| browseButton.addSelectionListener(new SelectionAdapter() { |
| public void widgetSelected(SelectionEvent e) { |
| openDirectoryDialog(); |
| } |
| }); |
| |
| return composite; |
| } |
| |
| public void init(IWorkbench workbench) { |
| } |
| |
| public void widgetSelected(SelectionEvent e) { |
| } |
| |
| public void widgetDefaultSelected(SelectionEvent e) { |
| } |
| |
| public void modifyText(ModifyEvent e) { |
| } |
| |
| /** |
| * Method declared on PreferencePage |
| */ |
| protected void performDefaults() { |
| super.performDefaults(); |
| initializeDefaults(); |
| } |
| |
| /** |
| * Method declared on PreferencePage |
| */ |
| public boolean performOk() { |
| storeValues(); |
| LibraryPlugin.getDefault().savePluginPreferences(); |
| return true; |
| } |
| |
| /** |
| * Stores the values of the controls back to the preference store. |
| */ |
| private void storeValues() { |
| PublishingUIPreferences.setPublishPath(destinationPathText.getText() |
| .trim()); |
| PublishingUIPreferences |
| .setFeedbackURL(feedbackURLText.getText().trim()); |
| } |
| |
| private void initializeDefaults() { |
| destinationPathText.setText(PublishingUIPreferences.getDefaultPublishPath()); |
| feedbackURLText.setText(PublishingUIPreferences.getDefaultFeedbackURL()); |
| |
| } |
| |
| /** |
| * Initializes states of the controls from the preference store. |
| */ |
| private void initializeValues() { |
| } |
| |
| protected IPreferenceStore doGetPreferenceStore() { |
| return PublishingPlugin.getDefault().getPreferenceStore(); |
| } |
| |
| protected Label createLabel(Composite parent, String text) { |
| Label label = new Label(parent, SWT.NONE); |
| label.setLayoutData(new GridData()); |
| label.setText(text); |
| return label; |
| } |
| |
| protected Text createEditableText(Composite parent, String defaultText) { |
| Text text = new Text(parent, SWT.BORDER); |
| text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| return text; |
| } |
| |
| private void openDirectoryDialog() { |
| try { |
| DirectoryDialog dd = new DirectoryDialog(composite.getShell(), |
| SWT.NONE); |
| |
| String destination = dd.open(); |
| if (destination != null) { |
| destinationPathText.setText(destination); |
| } |
| |
| } catch (Exception ex) { |
| ex.printStackTrace(); |
| } |
| } |
| } |