Package de.innovationgate.eclipse.wgadesigner.dialogs

Source Code of de.innovationgate.eclipse.wgadesigner.dialogs.WGAEditDeploymentDialog

/*******************************************************************************
* 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.wgadesigner.dialogs;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
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.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import de.innovationgate.eclipse.utils.WorkbenchUtils;
import de.innovationgate.eclipse.utils.ui.DynamicListControl;
import de.innovationgate.eclipse.utils.ui.ValidatedDialog;
import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;
import de.innovationgate.eclipse.wgadesigner.editors.helpers.WGADeployment;



public class WGAEditDeploymentDialog extends ValidatedDialog {

  private WGADeployment _deployment;
  private DynamicListControl _lstDefaultPlugins;
  private Label _lblSymbolicName;
    private Text _txtUpdateURL;
    private String _updateURL;
 
  public WGAEditDeploymentDialog(Shell parentShell) {
    super(parentShell);
    init(null);
  }
 
  public WGAEditDeploymentDialog(Shell parentShell, WGADeployment deployment) {
    super(parentShell);   
    init(deployment);
  }
 
  private void init(WGADeployment deployment){
    setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.APPLICATION_MODAL);
    setStatusLineAboveButtons(true);
    setHelpAvailable(false);     
    _deployment = deployment;     
  }

  @Override
  protected Control createDialogArea(Composite parent) {
    Composite composite = new Composite(parent, SWT.None);
    composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    GridLayout layout = new GridLayout(3, false);
    composite.setLayout(layout);
   
    GridData txtStyle = new GridData(GridData.FILL_HORIZONTAL);
    txtStyle.minimumWidth = convertWidthInCharsToPixels(60);

   
    Label lblSymbolicName = new Label(composite, SWT.None);
    lblSymbolicName.setText("Symbolic name:");
    _lblSymbolicName = new Label(composite, SWT.BORDER);   
    _lblSymbolicName.setLayoutData(txtStyle);
    _lblSymbolicName.setText(_deployment.getName());
     
   
    Label filler = new Label(composite, SWT.None);
    filler.setText("");
   

    Label lblDefaultPlugins = new Label(composite, SWT.None);
    lblDefaultPlugins.setText("Default Plugins:");
    GridData lblLayout = new GridData();
    lblLayout.verticalAlignment = SWT.TOP;
    lblDefaultPlugins.setLayoutData(lblLayout);
   
    _lstDefaultPlugins = new DynamicListControl(composite, SWT.None);
    List<String> pluginNames = _deployment.getDefaultPluginNames();
    Collections.sort(pluginNames);
    _lstDefaultPlugins.init(pluginNames.toArray(new String[0]));

    GridData listLayout = new GridData(GridData.FILL_HORIZONTAL);
    listLayout.horizontalSpan = 2;
    _lstDefaultPlugins.setLayoutData(listLayout);
   
    _lstDefaultPlugins.getButton(DynamicListControl.BUTTON_ADD).addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        handleAddDefaultPlugin();
      }       
    });
   
    _lstDefaultPlugins.getButton(DynamicListControl.BUTTON_REMOVE).addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        handleRemoveDefaultPlugin();
      }       
    });
   
   
    Label lblUpdateURL = new Label(composite, SWT.None);
    lblUpdateURL.setText("Update URL:");
    //lblUpdateURL.setLayoutData(GridDataFactory.copyData(txtStyle));
   
    _txtUpdateURL = new Text(composite, SWT.BORDER);
    _txtUpdateURL.setLayoutData(GridDataFactory.copyData(txtStyle));
   
    if (_deployment.isWorkspaceDeployment()) {
        _txtUpdateURL.setEnabled(false);       
    }
   
    if (_deployment.getUpdateURL() != null) {
        _txtUpdateURL.setText(_deployment.getUpdateURL());
    }
   
    return composite;
  }

  protected void handleRemoveDefaultPlugin() {
    if (_lstDefaultPlugins.getList().getSelectionCount() > 0) {
      boolean delete = MessageDialog.openConfirm(getShell(), "Remove selected default plugins?", "Are you sure you want to remove the selected default plugins? This will also delete the selected files from filesystem.");
      if (delete) {
        String[] fileNames = _lstDefaultPlugins.getList().getSelection();
        for (int i=0; i < fileNames.length; i++) {
          if (!_deployment.removeDefaultPlugin(fileNames[i])) {
            MessageDialog.openWarning(getShell(), "Deletion failed.", "Unable to delete default plugin '" + fileNames[i] + "'.");
          }
        }
      }
    }
    List<String> pluginNames = _deployment.getDefaultPluginNames();
    Collections.sort(pluginNames);
    _lstDefaultPlugins.setItems(pluginNames.toArray(new String[0]));
   
  }

  protected void handleAddDefaultPlugin() {
    FileDialog dialog = new FileDialog(getShell(), SWT.MULTI);
    dialog.setText("Select plugin files to add");
    dialog.setFilterExtensions(new String[] {"*.wgaplugin"});
    String selectedFile = dialog.open();
    if (selectedFile != null) {
      String[] fileNames = dialog.getFileNames();
      File dir = new File(dialog.getFilterPath());
      for (int i = 0; i < fileNames.length; i++) {
        String filename = fileNames[i];
        try {         
          _deployment.addDefaultPlugin(new File(dir, filename));           
        } catch (IOException e) {
          WorkbenchUtils.showErrorDialog(getShell(), "Adding default plugin failed", e);
        }
      }
      List<String> pluginNames = _deployment.getDefaultPluginNames();
      Collections.sort(pluginNames);
      _lstDefaultPlugins.setItems(pluginNames.toArray(new String[0]));
    }   
  }

  @Override
  public List<String> validate() {
    List<String> messages = new ArrayList<String>()
    return messages;
  }

  @Override
  public void computeResponse() {
      _updateURL = _txtUpdateURL.getText();
  }

  @Override
  public void create() {
    super.create();
  }

    @Override
    protected void okPressed() {
        super.okPressed();
        _deployment.setUpdateURL(_updateURL);
    }

 
 
}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.dialogs.WGAEditDeploymentDialog

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.