/******************************************************************************* * This file is part of the Coporate Semantic Web Project. * * This work has been partially supported by the ``InnoProfile-Corporate Semantic Web" project funded by the German Federal * Ministry of Education and Research (BMBF) and the BMBF Innovation Initiative for the New German Laender - Entrepreneurial Regions. * * http://www.corporate-semantic-web.de/ * * * Freie Universitaet Berlin * Copyright (c) 2007-2013 * * * Institut fuer Informatik * Working Group Coporate Semantic Web * Koenigin-Luise-Strasse 24-26 * 14195 Berlin * * http://www.mi.fu-berlin.de/en/inf/groups/ag-csw/ * * * * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or see <http://www.gnu.org/licenses/> ******************************************************************************/ package de.fuberlin.agcsw.heraclitus.backend.ui.wizards; 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 OntologyImportWizardPage extends WizardNewFileCreationPage{ protected FileFieldEditor editor; protected OntologyImportWizardPage(String name, IStructuredSelection selection) { super(name, selection); setTitle(name); //NON-NLS-1 setDescription("Import a file from the local file system into the workspace"); } /* (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(OntologyImportWizardPage.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, "de.fuberlin.agcsw.ontoEclipse", IStatus.OK, "", null); //NON-NLS-1 //NON-NLS-2 } }