Package tool.properties

Source Code of tool.properties.ProjectPropertyPage

package tool.properties;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
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.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ListDialog;
import org.eclipse.ui.dialogs.PropertyPage;

import tool.ToolPlugin;
import tool.ToolProjectSupport;
import tool.model.ToolComponent;
import tool.repository.InvalidToolRepositoryException;
import tool.repository.FScript;
import tool.repository.ToolSystemException;

public class ProjectPropertyPage extends PropertyPage implements IWizardPage {
  private DataBindingContext m_bindingContext;


  private static final int TEXT_FIELD_WIDTH = 50;

  private String forteRepository;
  private String forteRoot;
  private String forteLogger;
  private String forteWorkspace;
  private String[] workspaces;
  public String forteWorkspacePassword;
 
  private IWizardPage prevPage;
 
  private IWizard wizard;
 
  private IProject project;

  private Text repositoryText;

  private Text forteLoggerFlagsValueText;

  private Text workspaceText;

  protected Text workspacePasswordText;
 

  /**
   * Constructor for ProjectPropertyPage.
   * @wbp.parser.constructor
   */
  public ProjectPropertyPage() {
    super();
    setTitle("Tool Properties");
    setDescription(",,,,,,");
  }
  public ProjectPropertyPage(String string, IStructuredSelection selection) {
    this();
    Object firstSelection = selection.getFirstElement();
    if (firstSelection instanceof IProject){
      project = (IProject)firstSelection;
    } else if (firstSelection instanceof IResource){
      project = ((IResource)firstSelection).getProject();
    } else if (firstSelection instanceof ToolComponent){
      project = ((ToolComponent)firstSelection).getProject();
    }
  }
  @Override
  public void setElement(IAdaptable element) {
    super.setElement(element);
    if (this.project == null)
      this.project = (IProject)getElement();
  }
  /**
   * @see PreferencePage#createContents(Composite)
   */
  protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    composite.setLayout(layout);
    GridData data = new GridData(GridData.FILL);
    data.grabExcessHorizontalSpace = true;
    composite.setLayoutData(data);
    new Label(composite, SWT.NONE);
    new Label(composite, SWT.NONE);
   
    Label lblNewLabel = new Label(composite, SWT.NONE);
   
    //Label for forteLoggerFlags field
    Label forteLoggerFlagsLabel = new Label(composite, SWT.NONE);
    forteLoggerFlagsLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    forteLoggerFlagsLabel.setText("Logger Flags");

    forteLoggerFlagsValueText = new Text(composite, SWT.SINGLE | SWT.BORDER);
    forteLoggerFlagsValueText.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent arg0) {
        setForteLogger(forteLoggerFlagsValueText.getText());
      }
    });
    forteLoggerFlagsValueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
   
    Label lblNewLabel_1 = new Label(composite, SWT.NONE);

    // Label for repository field
    Label repositoryLabel = new Label(composite, SWT.NONE);
    repositoryLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    repositoryLabel.setText("Repository");

    // repository text field
    repositoryText = new Text(composite, SWT.SINGLE | SWT.BORDER);
    repositoryText.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent arg0) {
        setForteRepository(repositoryText.getText());
      }
    });
    GridData gd = new GridData();
    gd.widthHint = convertWidthInCharsToPixels(TEXT_FIELD_WIDTH);
    repositoryText.setLayoutData(gd);
   
    Label lblNewLabel_2 = new Label(composite, SWT.NONE);
   
    // Label for workspace field
    Label workspaceLabel = new Label(composite, SWT.NONE);
    workspaceLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    workspaceLabel.setText("Workspace");

    // workspace text field
    workspaceText = new Text(composite, SWT.SINGLE | SWT.BORDER);
    workspaceText.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent event) {
        forteWorkspace = workspaceText.getText();
      }
    });
    GridData gd2 = new GridData();
    gd2.horizontalAlignment = SWT.FILL;
    gd2.widthHint = 224;
    workspaceText.setLayoutData(gd2);
   
    Button button = new Button(composite, SWT.NONE);
    button.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        if (repositoryText.getText().trim().isEmpty())
          return;
        FScript repos = new FScript(ToolProjectSupport.getForteRoot(),
            repositoryText.getText().trim(),
            "", "", forteLoggerFlagsValueText.getText(), true);
        try {
          workspaces = repos.ListWorkspaces();
        } catch (ToolSystemException e1) {
          ToolPlugin.showError("Tool repository error", e1);
        } catch (InvalidToolRepositoryException e1) {
          ToolPlugin.showError("Tool repository error", e1);
        }

        ListDialog wsListDialog = new ListDialog(getShell());
        wsListDialog.setAddCancelButton(true);
        wsListDialog.setContentProvider(new ArrayContentProvider());
        wsListDialog.setLabelProvider(new LabelProvider());
        if (workspaces != null)
          wsListDialog.setInput(workspaces);
        wsListDialog.setInitialSelections(workspaces);
        wsListDialog.setTitle("Select workspace");
        wsListDialog.open();
        Object[] result = wsListDialog.getResult();
        if (result != null && result.length > 0){
          workspaceText.setText((String)result[0]);
        }

      }     
    });
    button.setText("...");

    // Label for workspacePassword field
    Label workspacePasswordLabel = new Label(composite, SWT.NONE);
    workspacePasswordLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    workspacePasswordLabel.setText("Password");

    // workspace text field
    workspacePasswordText = new Text(composite, SWT.SINGLE | SWT.BORDER);
    workspacePasswordText.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent arg0) {
        setForteWorkspacePassword(workspacePasswordText.getText());
      }
    });
    workspacePasswordText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    new Label(composite, SWT.NONE);

    performDefaults();
    // Populate text fields
    if (this.project != null)
    try {
      forteRepository =
        project.getPersistentProperty(ToolProjectSupport.reposQualifiedName);
      repositoryText.setText((forteRepository != null) ? forteRepository : "");
      forteWorkspace =
        project.getPersistentProperty(ToolProjectSupport.workspaceQualifiedName);
      workspaceText.setText((forteWorkspace != null) ? forteWorkspace : "");
      forteWorkspacePassword =
        project.getPersistentProperty(ToolProjectSupport.worspacePasswordQualifiedName);
      workspacePasswordText.setText((forteWorkspacePassword != null) ? forteWorkspacePassword : "");
    } catch (CoreException e) {
      repositoryText.setText("");
      workspaceText.setText("");
      workspacePasswordText.setText("");
    }
   
    if (this.project != null){
      try {
        // logger
        forteLogger =
          project.getPersistentProperty(ToolProjectSupport.loggerQualifiedName);
        forteLoggerFlagsValueText.setText((forteLogger != null) ? forteLogger : ToolPlugin.getForteLogger());
      } catch (CoreException e) {
        forteLoggerFlagsValueText.setText(ToolPlugin.getForteLogger());
      }
    }
    return composite;
  }


 




  protected void performDefaults() {
    super.performDefaults();
    performValueDefaults();
    performControlDefaults();
  }
 
  public void performControlDefaults(){
    forteLoggerFlagsValueText.setText(forteLogger);
//    repositoryText.setText("");
//    workspaceText.setText("");
//    workspacePasswordText.setText("");
  }
 
  public void performValueDefaults(){
    forteRoot = ToolPlugin.getForteRoot();
    forteLogger = ToolPlugin.getForteLogger();
   
  }
 
  public boolean performOk() {
    // store the value in the owner text field
    try {
      // logger
      forteLogger = forteLoggerFlagsValueText.getText();
      ((IResource) getElement()).setPersistentProperty(ToolProjectSupport.loggerQualifiedName,
          forteLogger);
      // repos
      forteRepository = repositoryText.getText();
      ((IResource) getElement()).setPersistentProperty(ToolProjectSupport.reposQualifiedName,
        forteRepository);
      // workspace
      forteWorkspace = workspaceText.getText();
      ((IResource) getElement()).setPersistentProperty(ToolProjectSupport.workspaceQualifiedName,
        forteWorkspace);
      // workspacePassword
      forteWorkspacePassword = workspacePasswordText.getText();
      ((IResource) getElement()).setPersistentProperty(ToolProjectSupport.worspacePasswordQualifiedName,
        forteWorkspacePassword);
    } catch (CoreException e) {
      return false;
    }
    return true;
  }
  @Override
  public boolean canFlipToNextPage() {
    return isPageComplete();
  }
  @Override
  public String getName() {
    return "Tool properties";
  }
  @Override
  public IWizardPage getNextPage() {
    return null;
  }
  @Override
  public IWizardPage getPreviousPage() {
    return prevPage;
  }
  @Override
  public IWizard getWizard() {
    return this.wizard;
  }
  @Override
  public boolean isPageComplete() {
//    return ((forteRoot != null && !forteRoot.isEmpty()) &&
//        (forteLogger != null && !forteLogger.isEmpty()) &&
//        (forteRepository != null && !forteRepository.isEmpty()) &&
//        (forteWorkspace != null && !forteWorkspace.isEmpty()));
    return true;
  }
  @Override
  public void setPreviousPage(IWizardPage prevPage) {
    this.prevPage = prevPage;
   
  }
  @Override
  public void setWizard(IWizard wizard) {
    this.wizard = wizard;
  }
  public String getForteRepository() {
    return forteRepository;
  }
  public String getForteRoot() {
    return forteRoot;
  }
  public String getForteLogger() {
    return forteLogger;
  }
  public String getForteWorkspace() {
    return forteWorkspace;
  }
  public String getForteWorkspacePassword() {
    return forteWorkspacePassword;
  }
 
 
 
  public void setForteRepository(String forteRepository) {
    this.forteRepository = forteRepository;
  }
  public void setForteLogger(String forteLogger) {
    this.forteLogger = forteLogger;
  }
  public void setForteWorkspace(String forteWorkspace) {
    this.forteWorkspace = forteWorkspace;
  }
  public void setForteWorkspacePassword(String forteWorkspacePassword) {
    this.forteWorkspacePassword = forteWorkspacePassword;
  }
  public IProject getProject() {
    return project;
  }
 
}
TOP

Related Classes of tool.properties.ProjectPropertyPage

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.