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

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

/*******************************************************************************
* 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.File;
import java.io.IOException;

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

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
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.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ListDialog;
import org.eclipse.ui.forms.HyperlinkGroup;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.widgets.ColumnLayout;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ImageHyperlink;
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.actions.RunValidation;
import de.innovationgate.eclipse.editors.design.WGADesignEditor;
import de.innovationgate.eclipse.utils.WorkbenchUtils;
import de.innovationgate.eclipse.utils.ui.FileLabelProvider;
import de.innovationgate.eclipse.utils.ui.FileStructuredContentProvider;
import de.innovationgate.eclipse.utils.ui.GenesisBoundFormPage;
import de.innovationgate.eclipse.utils.ui.WidgetFactory;
import de.innovationgate.eclipse.utils.ui.model.WGADesignConfigurationModelWrapper;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
import de.innovationgate.wga.model.Model;

@ViewHandler
public class GeneralConfigurationPage extends GenesisBoundFormPage {

  public static final String ID = "de.innovationgate.eclipse.wgadesigner.pages.GeneralConfigurationPage";
  public static final String PAGE_TITLE = "Design Configuration";
 
  private Label _lblDirectory;
  private Label _lblDesignKey;
  private Text _txtInitScript;
  private Text _txtConnectionScript;
  private Text _txtDisconnectionScript;
  private Combo _comboDefaultAccessLevel;
  private Combo _comboAnonymousAccessLevel;
  private Combo _comboVersionCompliance;
  private Button _btnBrowseConnectionScript;
  private Button _btnBrowseInitScript;
  private WGADesignConfigurationModelWrapper _model;
  private List _lstLibraries;
  private Button _btnAddLibrary;
  private Button _btnRemoveLibrary;
  private Text _txtHomePage;
  private Text _loginPage;
  //private Text _defaultMediaKey;
  private Combo _comboDefaultTMLOutputEncoding;
  private Combo _comboDesignEncoding;
  //private Combo _comboDefaultExpressionLanguage;
  private Button _chkMultiLanguageContent;
  //private Button _chkDirectAccessDefault;
  private Button _chkUsesHDB;
  private FormEditor _editor;
  private Button _btnBrowseDisconnectionScript;
  private Button _chkStaticClasspath;
    private Button _chkAdminApp;
    private Combo _comboBrowsingSecurity;
 
  public GeneralConfigurationPage(FormEditor editor) {
    super(editor, ID, PAGE_TITLE);
    _editor = editor;
  }
 
  public void setModel(Model model) {
    if (!(model instanceof WGADesignConfigurationModelWrapper)) {
      throw new IllegalArgumentException("Unsupported model type '" + model.getClass().getName() + "'.");
    }
    _model = (WGADesignConfigurationModelWrapper) 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);
   
    // general section
    Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION|Section.TITLE_BAR|Section.TWISTIE|Section.EXPANDED);
    section.setText("General");

        Composite sectionClient = toolkit.createComposite(section);
        section.setClient(sectionClient);
        GridLayout sectionLayout = new GridLayout();
        GridData fillHSpan = new GridData(GridData.FILL_HORIZONTAL);
        fillHSpan.horizontalSpan = 2;
        GridData fillH = new GridData(GridData.FILL_HORIZONTAL);
       
        sectionLayout.numColumns = 3;
        sectionClient.setLayout(sectionLayout);
       
       
        _lblDirectory = factory.createLabel(sectionClient, "Directory", "designDirectory");       
        _lblDirectory.setLayoutData(fillHSpan);
       
//      _lblDesignKey = factory.createLabel(sectionClient, "Design key:", "designKey");
//      _lblDesignKey.setLayoutData(fillHSpan);
     
      _txtInitScript= factory.createText(sectionClient, "Initialisation script:", "initScript");
      _txtInitScript.setLayoutData(fillH);
      registerField("initScript", _txtInitScript);
     
      _btnBrowseInitScript = toolkit.createButton(sectionClient, "...", SWT.PUSH);
      _btnBrowseInitScript.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
      public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
        handleBrowseInitScript();
      }
    });
     
      _txtConnectionScript= factory.createText(sectionClient, "Connection script:", "connectionScript");
      _txtConnectionScript.setLayoutData(fillH);
      registerField("connectionScript", _txtConnectionScript);
     
      _btnBrowseConnectionScript = toolkit.createButton(sectionClient, "...", SWT.PUSH);
      _btnBrowseConnectionScript.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
      public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
        handleBrowseConnectionScript();
      }
    });
     
      _txtDisconnectionScript= factory.createText(sectionClient, "Disconnection script:", "disconnectionScript");
      _txtDisconnectionScript.setLayoutData(fillH);
      registerField("disconnectionScript", _txtDisconnectionScript);
           
      _btnBrowseDisconnectionScript = toolkit.createButton(sectionClient, "...", SWT.PUSH);
      _btnBrowseDisconnectionScript.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
      public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
        handleBrowseDisconnectionScript();
      }
    });     
      _txtDisconnectionScript.addPaintListener(new PaintListener() {

      public void paintControl(PaintEvent e) {
        _btnBrowseDisconnectionScript.setEnabled(_txtDisconnectionScript.isEnabled());       
      }
       
      });

     
      _comboDefaultAccessLevel = factory.createCombo(sectionClient, "Default access level:", "defaultAccessLevel");
      factory.addFiller(sectionClient);
      registerField("defaultAccessLevel", _comboDefaultAccessLevel);
         
      _comboAnonymousAccessLevel = factory.createCombo(sectionClient, "Anonymous access level:", "anonymousAccessLevel");
      factory.addFiller(sectionClient);
      registerField("anonymousAccessLevel", _comboAnonymousAccessLevel);
     
      _comboVersionCompliance = factory.createCombo(sectionClient, "Developed for WGA version:", "versionCompliance");
      factory.addFiller(sectionClient)
      registerField("versionCompliance", _comboVersionCompliance);     
     
      // libraries section
      section = toolkit.createSection(form.getBody(), Section.DESCRIPTION|Section.TITLE_BAR|Section.TWISTIE|Section.COMPACT);
    section.setText("Libraries");

        sectionClient = toolkit.createComposite(section);
        section.setClient(sectionClient);
        sectionLayout = new GridLayout();       
        sectionLayout.numColumns = 3;
        sectionClient.setLayout(sectionLayout);
     
        _chkStaticClasspath = factory.createCheckBox(sectionClient, "Prevent reloading of java libraries", "Enabled", "staticClasspath");
      registerField("staticClasspath", _chkStaticClasspath);
       
        GridData fillBoth = new GridData(GridData.FILL_BOTH);
        fillBoth.minimumHeight = 100;
        fillBoth.verticalSpan = 2;
        fillBoth.horizontalSpan = 2;
        _lstLibraries = new List(sectionClient, SWT.BORDER|SWT.MULTI);
        _lstLibraries.setLayoutData(fillBoth);
        _lstLibraries.setItems(_model.getLibraryNames());
       
        _btnAddLibrary = toolkit.createButton(sectionClient, "add...", SWT.PUSH);
        _btnAddLibrary.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
      public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
        handleAddLibrary();
      }
    });
       
        GridData btnLayout = new GridData(GridData.HORIZONTAL_ALIGN_FILL, GridData.VERTICAL_ALIGN_FILL, false, false);
        _btnAddLibrary.setLayoutData(btnLayout);
       
        //factory.addFiller(sectionClient);
       
        _btnRemoveLibrary = toolkit.createButton(sectionClient, "remove...", SWT.PUSH);
       
        _btnRemoveLibrary.setLayoutData(btnLayout);       
        _btnRemoveLibrary.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
      public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
        handleRemoveLibrary();
      }
    });
       

       
       
        // publishing section
      section = toolkit.createSection(form.getBody(), Section.DESCRIPTION|Section.TITLE_BAR|Section.TWISTIE|Section.EXPANDED);
    section.setText("Publishing");

        sectionClient = toolkit.createComposite(section);
        section.setClient(sectionClient);
        sectionLayout = new GridLayout();       
        sectionLayout.numColumns = 2;
        sectionClient.setLayout(sectionLayout);
       
      _txtHomePage= factory.createText(sectionClient, "Home Page:", "homePage");
      _txtHomePage.setLayoutData(fillH);
      registerField("homePage", _txtHomePage);
     
      _loginPage= factory.createText(sectionClient, "Login Page:", "loginPage");
      _loginPage.setLayoutData(fillH)
      registerField("loginPage", _loginPage);
     
//      _defaultMediaKey= factory.createText(sectionClient, "Default Media Key:", "defaultMediaKey");
//      _defaultMediaKey.setLayoutData(fillH);
//      registerField("defaultMediaKey", _defaultMediaKey);
     
      _comboDefaultTMLOutputEncoding = factory.createCombo(sectionClient, "Default WebTML Output Encoding:", "defaultItemEncoding");
      registerField("defaultItemEncoding", _comboDefaultTMLOutputEncoding);
     
      _comboDesignEncoding = factory.createCombo(sectionClient, "Design encoding:", "designEncoding");
      registerField("designEncoding", _comboDesignEncoding);
     
      HyperlinkGroup group = new HyperlinkGroup(sectionClient.getDisplay());     
      factory.addFiller(sectionClient);
      ImageHyperlink linkEnforceEncoding = new ImageHyperlink(sectionClient, SWT.None);
      linkEnforceEncoding.setText("Enforce design encoding");
      final Shell fShell = getSite().getShell();
      linkEnforceEncoding.addHyperlinkListener(new HyperlinkAdapter() {
      public void linkActivated(HyperlinkEvent e) {
        if (_editor.isDirty()) {
          MessageDialog.openInformation(fShell, "Save changes", "Please save your changes on this design first.");
          return;
        }
        boolean result = MessageDialog.openQuestion(fShell, "Enforce design encoding", "Enforcing design encoding will change encoding resource settings and perform a revalidation of the design. Continue?");
        if (result) {
          try {
            new WGADesignStructureHelper(_model.getDesignContainer()).enforceDesignEncoding();
            RunValidation.call(_model.getDesignContainer(), fShell);
          } catch (CoreException e1) {
            WorkbenchUtils.showErrorDialog(Plugin.getDefault(), fShell, "Error", "Enforce design encoding failed.", e1);
          }         
        }
      }
    });   
      group.add(linkEnforceEncoding);
     
//      _comboDefaultExpressionLanguage = factory.createCombo(sectionClient, "Default Expression Language:", "expressionDefault");
//      registerField("expressionDefault", _comboDefaultExpressionLanguage);
     
      _chkMultiLanguageContent = factory.createCheckBox(sectionClient, "Multi Language Content", "Enabled", "multiLanguageContent");
      registerField("multiLanguageContent", _chkMultiLanguageContent);
     
//      _chkDirectAccessDefault = factory.createCheckBox(sectionClient, "WebTML Direct Access by default", "Allowed", "directAccessDefault");
//      registerField("directAccessDefault", _chkDirectAccessDefault);
     
      _chkUsesHDB = factory.createCheckBox(sectionClient, "Uses HDB interface", "Enabled", "usesHDB");
      registerField("usesHDB", _chkUsesHDB);
     
        _chkAdminApp = factory.createCheckBox(sectionClient, "Only accessible with administrative login", "Enabled", "adminApp");
        registerField("adminApp", _chkAdminApp);
       
        _comboBrowsingSecurity = factory.createCombo(sectionClient, "Browsing security", "browsingSecurity");
        registerField("browsingSecurity", _comboBrowsingSecurity);
     
      //WGADesignExportSection.create(form, toolkit, _editor, "menu:" + WGADesignEditor.ID + ".exportDesign");
     
      ((WGADesignEditor)_editor).createPageToolbar(form.getForm());

      bind(form, SWTBinder.BINDING_STRATEGY_AS_YOU_TYPE);
  }

  private void handleAddLibrary() {
    Shell shell = getManagedForm().getForm().getShell();
    FileDialog dialog = new FileDialog(shell, SWT.MULTI);
    dialog.setText("Select libraries to add");
    dialog.setFilterExtensions(new String[] {"*.jar"});
    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];
        boolean overwrite = true;
        if (_model.hasLibrary(filename)) {
          overwrite = MessageDialog.openConfirm(shell, "Overwrite?", "Library '" + filename + "' already exists, overwrite?");
        }
        if (overwrite) {
          try {         
            _model.addLibrary(new File(dir, filename));
          } catch (IOException e) {
            WorkbenchUtils.showErrorDialog(Plugin.getDefault(), shell, "Error", "Unable to add library '" + filename + "'", e);
          }
        }
      }
      _lstLibraries.setItems(_model.getLibraryNames());
    }
  }
 
  private void handleRemoveLibrary() {
    Shell shell = getManagedForm().getForm().getShell();
    if (_lstLibraries.getSelectionCount() > 0) {
      boolean delete = MessageDialog.openConfirm(shell, "Remove selected libraries?", "Are you sure you want to remove the selected libraries? This will also delete the selected files from filesystem.");
      if (delete) {
        String[] fileNames = _lstLibraries.getSelection();
        for (int i=0; i < fileNames.length; i++) {
          if (!_model.deleteLibrary(fileNames[i])) {
            MessageDialog.openWarning(shell, "Deletion failed.", "Unable to delete library '" + fileNames[i] + "'.");
          }
        }
      }
    }
    _lstLibraries.setItems(_model.getLibraryNames());   
 

  private String computePathToScriptFrom(IPath base, IPath file){
        if(base.isPrefixOf(file)){
            file = file.removeFirstSegments(base.segmentCount());            
            file = file.removeFileExtension();
            return file.toString().replace('/', ':');
        }
        else{
            return file.toString();
        }   
  }
 
 
 
  private void handleBrowseInitScript() {
    ListDialog dialog = new ListDialog(getManagedForm().getForm().getShell());
    dialog.setContentProvider(new FileStructuredContentProvider(".tmlscript"));
    dialog.setLabelProvider(new FileLabelProvider());
    dialog.setInput(_model.getTMLScriptDirectory());
    dialog.setTitle("Please select an initialisation script");
   
    int result = dialog.open();
    if (result == ListDialog.OK) {
      IFile selectedScript = (IFile) dialog.getResult()[0];
      IPath selectedScriptPath = selectedScript.getLocation();
      IPath tmlScriptDirectoryPath = new Path(_model.getTMLScriptDirectory().getAbsolutePath());     
      _txtInitScript.setText(computePathToScriptFrom(tmlScriptDirectoryPath,selectedScriptPath));
         
    }   
  }

  private void handleBrowseConnectionScript() {
    ListDialog dialog = new ListDialog(getManagedForm().getForm().getShell());
    dialog.setContentProvider(new FileStructuredContentProvider(".tmlscript"));
    dialog.setLabelProvider(new FileLabelProvider());
    dialog.setInput(_model.getTMLScriptDirectory());
    dialog.setTitle("Please select an connection script");
   
    int result = dialog.open();
    if (result == ListDialog.OK) {
        IFile selectedScript = (IFile) dialog.getResult()[0];
          IPath selectedScriptPath = selectedScript.getLocation();
          IPath tmlScriptDirectoryPath = new Path(_model.getTMLScriptDirectory().getAbsolutePath());         
          _txtConnectionScript.setText(computePathToScriptFrom(tmlScriptDirectoryPath,selectedScriptPath));
   
  }
 
  private void handleBrowseDisconnectionScript() {
    ListDialog dialog = new ListDialog(getManagedForm().getForm().getShell());
    dialog.setContentProvider(new FileStructuredContentProvider(".tmlscript"));
    dialog.setLabelProvider(new FileLabelProvider());
    dialog.setInput(_model.getTMLScriptDirectory());
    dialog.setTitle("Please select a disconnection script");
   
    int result = dialog.open();
    if (result == ListDialog.OK) {
        IFile selectedScript = (IFile) dialog.getResult()[0];
          IPath selectedScriptPath = selectedScript.getLocation();
          IPath tmlScriptDirectoryPath = new Path(_model.getTMLScriptDirectory().getAbsolutePath());         
          _txtDisconnectionScript.setText(computePathToScriptFrom(tmlScriptDirectoryPath,selectedScriptPath));
   
  }


}
TOP

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

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.