/** SpagoBI, the Open Source Business Intelligence suite Copyright (C) 2012 Engineering Ingegneria Informatica S.p.A. - SpagoBI Competency Center This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. **/ package it.eng.spagobi.studio.core.importWizards; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.jface.preference.FileFieldEditor; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.dialogs.WizardNewFileCreationPage; public class ImportWizardPage extends WizardNewFileCreationPage { protected FileFieldEditor editor; public ImportWizardPage(String pageName, IStructuredSelection selection) { super(pageName, selection); setTitle(pageName); //NON-NLS-1 setDescription("Import a file from the local file system into the workspace"); //NON-NLS-1 } /* (non-Javadoc) * @see org.eclipse.ui.dialogs.WizardNewFileCreationPage#createAdvancedControls(org.eclipse.swt.widgets.Composite) */ protected void createAdvancedControls(Composite parent) { Composite fileSelectionArea = new Composite(parent, SWT.NONE); GridData fileSelectionData = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL); fileSelectionArea.setLayoutData(fileSelectionData); GridLayout fileSelectionLayout = new GridLayout(); fileSelectionLayout.numColumns = 3; fileSelectionLayout.makeColumnsEqualWidth = false; fileSelectionLayout.marginWidth = 0; fileSelectionLayout.marginHeight = 0; fileSelectionArea.setLayout(fileSelectionLayout); editor = new FileFieldEditor("fileSelect","Select File: ",fileSelectionArea); //NON-NLS-1 //NON-NLS-2 editor.getTextControl(fileSelectionArea).addModifyListener(new ModifyListener(){ public void modifyText(ModifyEvent e) { IPath path = new Path(ImportWizardPage.this.editor.getStringValue()); setFileName(path.lastSegment()); } }); String[] extensions = new String[] { "*.*" }; //NON-NLS-1 editor.setFileExtensions(extensions); fileSelectionArea.moveAbove(null); } /* (non-Javadoc) * @see org.eclipse.ui.dialogs.WizardNewFileCreationPage#createLinkTarget() */ protected void createLinkTarget() { } /* (non-Javadoc) * @see org.eclipse.ui.dialogs.WizardNewFileCreationPage#getInitialContents() */ protected InputStream getInitialContents() { try { return new FileInputStream(new File(editor.getStringValue())); } catch (FileNotFoundException e) { return null; } } /* (non-Javadoc) * @see org.eclipse.ui.dialogs.WizardNewFileCreationPage#getNewFileLabel() */ protected String getNewFileLabel() { return "New File Name:"; //NON-NLS-1 } /* (non-Javadoc) * @see org.eclipse.ui.dialogs.WizardNewFileCreationPage#validateLinkedResource() */ protected IStatus validateLinkedResource() { return new Status(IStatus.OK, "it.eng.spagobi.studio.core", IStatus.OK, "", null); //NON-NLS-1 //NON-NLS-2 } }