| //------------------------------------------------------------------------------ |
| // 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.export.xml.wizards; |
| |
| import java.io.File; |
| |
| import org.eclipse.epf.export.xml.XmlExportPlugin; |
| import org.eclipse.epf.export.xml.XmlExportResources; |
| import org.eclipse.jface.wizard.IWizardPage; |
| import org.eclipse.jface.wizard.WizardPage; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.events.FocusEvent; |
| import org.eclipse.swt.events.FocusListener; |
| import org.eclipse.swt.events.SelectionAdapter; |
| import org.eclipse.swt.events.SelectionEvent; |
| 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.Display; |
| import org.eclipse.swt.widgets.FileDialog; |
| import org.eclipse.swt.widgets.Group; |
| import org.eclipse.swt.widgets.Label; |
| import org.eclipse.swt.widgets.Text; |
| |
| /** |
| * A wizard page that prompts the user to select a directory that contains the |
| * method plug-ins to import. |
| * |
| * @author JJinhua Xi |
| * @since 1.0 |
| */ |
| public class SelectXmlFilePage extends WizardPage { |
| |
| public static final String PAGE_NAME = SelectXmlFilePage.class.getName(); |
| |
| private Text ctrl_path; |
| |
| private String path; |
| |
| /** |
| * Creates a new instance. |
| */ |
| public SelectXmlFilePage() { |
| super(PAGE_NAME); |
| setTitle(XmlExportResources.selectDestinationPage_title); //$NON-NLS-1$ |
| setDescription(XmlExportResources.selectDestinationPage_desc); //$NON-NLS-1$ |
| setImageDescriptor(XmlExportPlugin.getDefault().getImageDescriptor( |
| "full/wizban/ImportRPWLayout.gif")); //$NON-NLS-1$ |
| } |
| |
| public void createControl(Composite parent) { |
| Composite container = new Composite(parent, SWT.NONE); |
| GridLayout layout = new GridLayout(); |
| container.setLayout(layout); |
| |
| Group layoutGroup = new Group(container, SWT.None); |
| layoutGroup.setLayout(new GridLayout(3, false)); |
| layoutGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| layoutGroup.setText("Select xml file"); //$NON-NLS-1$ |
| |
| Label fileLabel = new Label(layoutGroup, SWT.NONE); |
| fileLabel.setText("File"); //$NON-NLS-1$ |
| |
| ctrl_path = new Text(layoutGroup, SWT.BORDER); |
| ctrl_path.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
| ctrl_path.addFocusListener(new FocusListener() { |
| |
| public void focusGained(FocusEvent e) { |
| setPageComplete(isValidPath()); |
| } |
| |
| public void focusLost(FocusEvent e) { |
| path = ctrl_path.getText(); |
| setPageComplete(isValidPath()); |
| } |
| }); |
| |
| Button browseButton = new Button(layoutGroup, SWT.PUSH); |
| browseButton.setLayoutData(new GridData(GridData.END)); |
| browseButton.setText("Browse"); //$NON-NLS-1$ |
| browseButton.addSelectionListener(new SelectionAdapter() { |
| public void widgetSelected(SelectionEvent e) { |
| handleBrowse(); |
| } |
| }); |
| |
| setControl(container); |
| |
| setPageComplete(isValidPath()); |
| } |
| |
| private boolean isValidPath() { |
| if (path == null || path.trim().length() == 0) { |
| return false; |
| } |
| |
| File f = new File(path); |
| if (!f.exists()) { |
| f.getParentFile().mkdirs(); |
| // f.createNewFile(); |
| } |
| |
| return true; |
| } |
| |
| private void handleBrowse() { |
| FileDialog fd = new FileDialog(Display.getCurrent().getActiveShell(), |
| SWT.OPEN); |
| fd.setFilterExtensions(new String[] { "*.xml", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$ |
| // fd.setFilterPath( getLayoutMgr().getLayoutRoot() ); |
| String path = fd.open(); |
| boolean ok = false; |
| if (path != null) { |
| ctrl_path.setText(path); |
| this.path = path; |
| ok = isValidPath(); |
| } |
| setPageComplete(ok); |
| getWizard().getContainer().updateButtons(); |
| } |
| |
| // private void updateStatus(String message) { |
| // setErrorMessage(message); |
| // setPageComplete(message == null); |
| // } |
| // |
| // |
| // private void applyToStatusLine() { |
| // if (status != OK_STATUS) |
| // setErrorMessage(status.getMessage()); |
| // else { |
| // setErrorMessage(null); |
| // } |
| // } |
| |
| public IWizardPage getNextPage() { |
| return null; // no more page |
| } |
| |
| public String getPath() { |
| return this.path; |
| } |
| |
| } |