Package de.innovationgate.eclipse.editors.design.pages

Source Code of de.innovationgate.eclipse.editors.design.pages.PluginConfigurationPage

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



import java.io.IOException;
import java.util.List;

import net.java.dev.genesis.annotation.ViewHandler;
import net.java.dev.genesis.ui.swt.SWTBinder;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.widgets.ColumnLayout;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;

import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.editors.ResourceIDs;
import de.innovationgate.eclipse.editors.design.WGADesignEditor;
import de.innovationgate.eclipse.utils.SWTBotIDs;
import de.innovationgate.eclipse.utils.ui.GenesisBoundFormPage;
import de.innovationgate.eclipse.utils.ui.WidgetFactory;
import de.innovationgate.eclipse.utils.ui.model.BeanListTableModelCellModifier;
import de.innovationgate.eclipse.utils.ui.model.BeanListTableModelContentProvider;
import de.innovationgate.eclipse.utils.ui.model.BeanListTableModelLabelProvider;
import de.innovationgate.wga.common.beans.csconfig.v1.PluginID;
import de.innovationgate.wga.common.beans.csconfig.v1.Version;
import de.innovationgate.wga.model.BeanListTableModel;
import de.innovationgate.wga.model.BeanListTableModelListener;
import de.innovationgate.wga.model.Model;
import de.innovationgate.wga.model.PluginDependenciesModel;
import de.innovationgate.wga.model.WGADesignConfigurationModel;

@ViewHandler
public class PluginConfigurationPage extends GenesisBoundFormPage {

  public static final String PAGE_TITLE = "Plugin Configuration";
 
  private static final String EMPTY_PLUGIN_UNAME = "<plugin unique name>";

  private static final String EMPTY_PLUGIN_VERSION = "0.0.0";

  private WGADesignConfigurationModel _model;

  //private Button _chkAllowContentAuthoring;

  private Button _chkUsageContentStore;

  private Button _chkUsageAuthSource;

  private Button _chkUsageDesignProvider;

  private Combo _comboAuthenticationSource;

  private Combo _comboPersMode;

  private Text _txtPluginHomepage;

  private Text _txtDescription;

  private Text _txtVendorHomepage;

  private Text _txtVendor;

  private Text _txtTitle;

  private Button _btnCreatePluginConfig;

  private Text _txtUniqueName;

  private Text _txtVersion;

  private Text _txtBuild;

  private Text _txtMinWGAVersion;

  private Text _txtMinJavaVersion;

  private Table _tblDependencies;

  private TableColumn _uniqueNameColumn;

  private TableColumn _minVersionColumn;

  private Button _btnAddDependency;

  private Button _btnRemoveDependency;

  private TableViewer _tblViewerPluginDependencies;

  private BeanListTableModel<PluginID> _pluginDependenciesModel;

  private FormEditor _editor;

  private Button _chkClearPluginDatabaseOnUpdate;

  private Button _chkDisableInit;
 
  public PluginConfigurationPage(FormEditor editor) {
    super(editor, ResourceIDs.EDITORPAGE_WGA_DESIGN_PLUGINCONFIGURATION, PAGE_TITLE);
    _editor = editor;
  }
 
  public void setModel(Model model) {
    _model = (WGADesignConfigurationModel) model;
  }

  public Model getModel() {
    return _model;
  }


  @Override
  protected void createFormContent(IManagedForm managedForm) {
    ScrolledForm form = managedForm.getForm();
    FormToolkit toolkit = managedForm.getToolkit();
    toolkit.decorateFormHeading(form.getForm());
   
    WidgetFactory factory = new WidgetFactory(toolkit);
   
    form.setText(PAGE_TITLE);

    ColumnLayout layout = new ColumnLayout();
    layout.maxNumColumns = 2;
    form.getBody().setLayout(layout);
   
   
    if (!_model.hasPluginConfig()) {
      GridLayout gridLayout = new GridLayout(1, false);
      form.getBody().setLayout(gridLayout);
      toolkit.createLabel(form.getBody(), "This design is currently not configured to be used as WGA Plugin.");
      _btnCreatePluginConfig = toolkit.createButton(form.getBody(), "Create WGA Plugin Configuration", SWT.PUSH);
      _btnCreatePluginConfig.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
          handleCreatePluginConfig();
        }
      });
    } else {         
      // registration section
      Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION|Section.TITLE_BAR|Section.TWISTIE|Section.EXPANDED);
      section.setText("Registration");
 
          Composite sectionClient = toolkit.createComposite(section);
          section.setClient(sectionClient);
          GridLayout sectionLayout = new GridLayout();
          GridData fillHSpan = new GridData(GridData.FILL_HORIZONTAL);
          fillHSpan.horizontalSpan = 4;
          GridData fillH = new GridData(GridData.FILL_HORIZONTAL);
         
          GridData prefSize = new GridData();
          prefSize.widthHint = 50;
         
          sectionLayout.numColumns = 5;
          sectionClient.setLayout(sectionLayout);                     
       
          _txtUniqueName = factory.createText(sectionClient, "Unique Name:", "pluginUniqueName");
          _txtUniqueName.setLayoutData(fillHSpan);
          registerField("pluginUniqueName", _txtUniqueName);
         
          _txtVersion = factory.createText(sectionClient, "Version:", "pluginVersion");
          _txtVersion.setLayoutData(prefSize);
          registerField("pluginVersion", _txtVersion);
         
          _txtBuild = factory.createText(sectionClient, "Build", "pluginBuild");
          _txtBuild.setLayoutData(prefSize);
          registerField("pluginBuild", _txtBuild);
          factory.addFiller(sectionClient);
         
          _txtMinWGAVersion = factory.createText(sectionClient, "Minimum WGA Version:", "pluginWGAVersion");
          _txtMinWGAVersion.setLayoutData(prefSize);
          registerField("pluginWGAVersion", _txtMinWGAVersion);
          factory.addFiller(sectionClient, 3);
         
          _txtMinJavaVersion = factory.createText(sectionClient, "Minimum Java Version:", "pluginJavaVersion");
          _txtMinJavaVersion.setLayoutData(prefSize);
          registerField("pluginJavaVersion", _txtMinJavaVersion);
          factory.addFiller(sectionClient, 3);
       
        // information section
        section = toolkit.createSection(form.getBody(), Section.DESCRIPTION|Section.TITLE_BAR|Section.TWISTIE|Section.EXPANDED);
      section.setText("Information and Functionality");
 
          sectionClient = toolkit.createComposite(section);
          section.setClient(sectionClient);
          sectionLayout = new GridLayout();       
          sectionLayout.numColumns = 2;
          sectionClient.setLayout(sectionLayout);
         
          _txtTitle = factory.createText(sectionClient, "Title:", "pluginTitle");
          _txtTitle.setLayoutData(fillH);
          registerField("pluginTitle", _txtTitle);
         
          _txtVendor = factory.createText(sectionClient, "Vendor:", "pluginVendor");
          _txtVendor.setLayoutData(fillH)
          registerField("pluginVendor", _txtVendor);
         
          _txtVendorHomepage = factory.createText(sectionClient, "Vendor Homepage:", "pluginVendorHomepage");
          _txtVendorHomepage.setLayoutData(fillH);
          registerField("pluginVendorHomepage", _txtVendorHomepage);
         
          _txtDescription = factory.createTextArea(sectionClient, "Description:", "pluginDescription");
           GridData textBox = new GridData(GridData.FILL_BOTH);
           textBox.minimumHeight = 100;
          _txtDescription.setLayoutData(textBox);
          registerField("pluginDescription", _txtDescription)
         
          _txtPluginHomepage = factory.createText(sectionClient, "Plugin Homepage:", "pluginHomepage");
          _txtPluginHomepage.setLayoutData(fillH);
          registerField("pluginHomepage", _txtPluginHomepage);
         
          _comboAuthenticationSource = factory.createCombo(sectionClient, "Authentication source:", "pluginAuthenticationSource");
          registerField("pluginAuthenticationSource", _comboAuthenticationSource);
         
          _comboPersMode = factory.createCombo(sectionClient, "Personalisation mode:", "pluginPersonalisationMode");
          registerField("pluginPersonalisationMode", _comboPersMode);
         
          toolkit.createLabel(sectionClient, "Usage:");
         
          _chkUsageDesignProvider = toolkit.createButton(sectionClient, "Design Provider", SWT.CHECK);
          _chkUsageDesignProvider.setData("pluginUsageAsDesignProvider");
          registerField("pluginUsageAsDesignProvider", _chkUsageDesignProvider);
       
         
          toolkit.createLabel(sectionClient, "")
          _chkUsageAuthSource = toolkit.createButton(sectionClient, "Authentication Source", SWT.CHECK);
        _chkUsageAuthSource.setData("pluginUsageAsAuthenticationSource");
        registerField("pluginUsageAsAuthenticationSource", _chkUsageAuthSource);
       
        toolkit.createLabel(sectionClient, "");
        _chkUsageContentStore = toolkit.createButton(sectionClient, "Published WGA Content Store", SWT.CHECK);
          _chkUsageContentStore.setData("pluginUsageAsContentStore");
          _chkUsageContentStore.setData(SWTBotIDs.WIDGET_KEY, ResourceIDs.BUTTON_IN_DESGINPLUGIN_EDITOR);
          registerField("pluginUsageAsContentStore", _chkUsageContentStore);
         
//          _chkAllowContentAuthoring = factory.createCheckBox(sectionClient, "Further options:", "Allow Content Authoring", "allowContentAuthoring");
//          registerField("allowContentAuthoring", _chkAllowContentAuthoring);
         
          _chkClearPluginDatabaseOnUpdate = factory.createCheckBox(sectionClient, "", "Clear plugin database on update", "pluginClearDatabaseOnUpdate");
          registerField("pluginClearDatabaseOnUpdate", _chkClearPluginDatabaseOnUpdate);
         
          _chkDisableInit = factory.createCheckBox(sectionClient, "", "Do not execute init/ connect functionalities on plugin itself", "pluginDisableInit");
          registerField("pluginDisableInit", _chkDisableInit);
         
          // dependencies section
      section = toolkit.createSection(form.getBody(), Section.DESCRIPTION|Section.TITLE_BAR|Section.TWISTIE|Section.COMPACT);
      section.setText("Dependencies");
 
          sectionClient = toolkit.createComposite(section);
          section.setClient(sectionClient);
          sectionLayout = new GridLayout();                                     
          sectionLayout.numColumns = 2;
          sectionClient.setLayout(sectionLayout);
         

          _tblDependencies = toolkit.createTable(sectionClient, SWT.BORDER|SWT.FULL_SELECTION);
          _tblDependencies.setHeaderVisible(true);         
          GridData tblLayoutData = new GridData(GridData.FILL_BOTH);
          tblLayoutData.verticalSpan = 2;
          tblLayoutData.minimumHeight = 200;
          _tblDependencies.setLayoutData(tblLayoutData);  
          registerField("pluginDependencies", _tblDependencies);
         
          int tableWidth = 450;         
          _uniqueNameColumn = new TableColumn(_tblDependencies, SWT.NONE)
          _uniqueNameColumn.setText("Plugin unique name");
          _uniqueNameColumn.setWidth((int)(tableWidth * 0.8));
         
          _minVersionColumn = new TableColumn(_tblDependencies, SWT.NONE);
          _minVersionColumn.setText("Minimum version");
          _minVersionColumn.setWidth((int)(tableWidth * 0.2));         

          _pluginDependenciesModel = new PluginDependenciesModel(_model.getPluginDependencies());
          _pluginDependenciesModel.addListener(new BeanListTableModelListener() {

        public void add(Object bean) {
          _model.fireModelChanged();         
        }

        public void remove(Object bean) {
          _model.fireModelChanged();       
        }

        public void update(Object bean) {
          _model.fireModelChanged();         
        }
       

        @SuppressWarnings("unchecked")
        public void refresh(List beans) {
          _model.fireModelChanged();       
        }
           
          });
         
          _tblViewerPluginDependencies = new TableViewer(_tblDependencies);
         
          // text editors for both columns
          CellEditor[] editors = new CellEditor[2];
          editors[0] = new TextCellEditor(_tblDependencies);
          editors[1] = new TextCellEditor(_tblDependencies);         
          _tblViewerPluginDependencies.setCellEditors(editors);
         
          _tblViewerPluginDependencies.setCellModifier(new BeanListTableModelCellModifier(_tblViewerPluginDependencies, _pluginDependenciesModel));                                       
          _tblViewerPluginDependencies.setContentProvider(new BeanListTableModelContentProvider());
          _tblViewerPluginDependencies.setLabelProvider(new BeanListTableModelLabelProvider(_pluginDependenciesModel));
          _tblViewerPluginDependencies.setInput(_pluginDependenciesModel);
               

          GridData btnLayout = new GridData(GridData.HORIZONTAL_ALIGN_FILL, GridData.VERTICAL_ALIGN_FILL, false, false);
          _btnAddDependency = toolkit.createButton(sectionClient, "add", SWT.PUSH);
          _btnAddDependency.setLayoutData(btnLayout);
          _btnAddDependency.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
          handleAddDependency();
        }

      });
         
          //factory.addFiller(sectionClient);
         
          _btnRemoveDependency = toolkit.createButton(sectionClient, "remove", SWT.PUSH);
          _btnRemoveDependency.setLayoutData(btnLayout);
          _btnRemoveDependency.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
          handleRemoveDependency();
        }
      });
         

          WGADesignExportSection.create(form, toolkit, _editor, "menu:" + WGADesignEditor.ID + ".exportPlugin");
       
          ((WGADesignEditor)_editor).createPageToolbar(form.getForm());
         
        bind(form, SWTBinder.BINDING_STRATEGY_AS_YOU_TYPE);
    }
  }
 
 
  private void handleCreatePluginConfig() {
    _model.createPluginConfig()
    int index = getIndex();
    getEditor().removePage(index);
    try {
      PluginConfigurationPage page = new PluginConfigurationPage(getEditor());     
      page.setModel(_model);
      getEditor().addPage(index, page);
      getEditor().setActivePage(page.getId());
    } catch (PartInitException e) {
      Plugin.getDefault().logError(e.getMessage(), e);
    }
  }
 

  private void handleAddDependency() {
    PluginID id = new PluginID();
    id.setUniqueName(EMPTY_PLUGIN_UNAME);
    id.setVersion(new Version(EMPTY_PLUGIN_VERSION));
    _pluginDependenciesModel.add(id);
  }

  private void handleRemoveDependency() {
    if (_tblDependencies.getSelectionCount() > 0) {
      _pluginDependenciesModel.remove((PluginID)_tblDependencies.getSelection()[0].getData());
    }
  }

  @Override
  public void refresh() throws IOException {
    super.refresh();
    if (_pluginDependenciesModel != null && _model != null && _model.getPluginDependencies() != null) {
      _pluginDependenciesModel.refresh(_model.getPluginDependencies());
    }
  }
}
TOP

Related Classes of de.innovationgate.eclipse.editors.design.pages.PluginConfigurationPage

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.