Package de.innovationgate.eclipse.editors.design.wizards

Source Code of de.innovationgate.eclipse.editors.design.wizards.ExportWGADesignLocalPage

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* 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:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.editors.design.wizards;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.SWT;
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.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.editors.Preferences;
import de.innovationgate.eclipse.utils.ui.ValidatedWizardPage;
import de.innovationgate.wga.model.WGADesignConfigurationModel;

/**
* wizard page to export a wga design as plugin
*
*
*/
public class ExportWGADesignLocalPage extends ValidatedWizardPage {

  private IContainer _design;
  private Text _txtExportLocation;
  private Button _btnBrowse;
  private Text _txtComment;

  private WGADesignConfigurationModel _model;

  private String _exportLocation;
  private Properties _buildProperties;

  protected ExportWGADesignLocalPage(IContainer design) {
    super("Export WGA Design");   
    _design = design;
    setPageComplete(false);
    setTitle("Export WGA Design");
    setDescription("This wizard exports a WGA Design to the local filesystem.");
  }

  public void createControl(Composite parent) {   
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    container.setLayout(layout);
   
    Label lblFolder = new Label(container, SWT.None);
    lblFolder.setText("Design folder:");
    Label lblPath = new Label(container, SWT.None);
    lblPath.setText(_design.getLocation().toFile().getAbsolutePath());
    new Label(container, SWT.None);
   
    Label lblExportLocation = new Label(container, SWT.None);
    lblExportLocation.setText("Export directory:");
    _txtExportLocation = new Text(container, SWT.BORDER|SWT.READ_ONLY);
    _txtExportLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
   
   
    String exportLocation = Plugin.getDefault().getPreferenceStore().getString(Preferences.DESIGN_EXPORT_LOCATION);
    _txtExportLocation.setText(new File(exportLocation, _model.getDesignKey() + ".wgadesign").getAbsolutePath());
   
    _txtExportLocation.addModifyListener(this);
   
    _btnBrowse = new Button(container, SWT.None);
    _btnBrowse.setText("...");
    _btnBrowse.addSelectionListener(new SelectionAdapter() {

      @Override
      public void widgetSelected(SelectionEvent e) {
        handleBrowse();
      }
     
    });
   
   
    Label lblBuild = new Label(container, SWT.None);
    lblBuild.setText("Signature:");   
    Label lblSignatureValue = new Label(container, SWT.None);
    _buildProperties = _model.createBuildProperties();
    lblSignatureValue.setText(_buildProperties.getProperty(WGADesignConfigurationModel.BUILD_PROP_SIGNATURE));
    new Label(container, SWT.None);
   
   
    Label lblComment = new Label(container, SWT.None);
    lblComment.setText("Comment:");   
    _txtComment = new Text(container, SWT.BORDER);
    _txtComment.setLayoutData(new GridData(GridData.FILL_HORIZONTAL))
    _txtComment.addModifyListener(this);
    new Label(container, SWT.None);
       
    setControl(container);
    performValidation();
  }

  private void handleBrowse() {
    FileDialog dialog = new FileDialog(getShell(), SWT.SINGLE);
    dialog.setText("Choose an export file");
    dialog.setFilterExtensions(new String[]{"*.wgadesign"});
    dialog.setFilterPath(new File(_txtExportLocation.getText()).getParentFile().getAbsolutePath());
    dialog.setFilterIndex(0);
    String selectedFile = dialog.open();
    if (selectedFile != null) {
      _txtExportLocation.setText(selectedFile);
      Plugin.getDefault().getPreferenceStore().putValue(Preferences.DESIGN_EXPORT_LOCATION, new File(_txtExportLocation.getText()).getParentFile().getAbsolutePath());
    }
  }

  public WGADesignConfigurationModel getModel() {
    return _model;
  }

  public void setModel(WGADesignConfigurationModel model) {
    _model = model;
  }

  public String getExportLocation() {
    return _exportLocation;
  }

  public Properties getBuildProperties() {
    return _buildProperties;
  }

  @Override
  public List<IStatus> validate() {
    List<IStatus> messages = new ArrayList<IStatus>();
    String location = _txtExportLocation.getText();
    if (location == null || location.trim().equals("")) {
      messages.add(new Status(Status.ERROR, Plugin.PLUGIN_ID, "Please choose a destination file for the design export."));
    } else if (!location.trim().endsWith(".wgadesign")) {
      messages.add(new Status(Status.ERROR, Plugin.PLUGIN_ID, "Destination file must have '.wgadesign' as file extension."));     
    }
   
    return messages;
  }

  @Override
  public void computeResponse() {
    _exportLocation = _txtExportLocation.getText();
    _buildProperties.setProperty(WGADesignConfigurationModel.BUILD_PROP_COMMENT, _txtComment.getText());   
  }

}
TOP

Related Classes of de.innovationgate.eclipse.editors.design.wizards.ExportWGADesignLocalPage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.