Package tool.wizards

Source Code of tool.wizards.NewSourceFolderWizardPage

package tool.wizards;

import org.eclipse.core.resources.IProject;
import org.eclipse.jface.preference.DirectoryFieldEditor;
import org.eclipse.jface.wizard.WizardPage;
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.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;

public class NewSourceFolderWizardPage extends WizardPage {

  private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
  private Text projectText;
  private Text folderNameText;
  private IProject project;
  private String newFolderName;
  private DirectoryFieldEditor dirField;

  public NewSourceFolderWizardPage(IProject project) {
    super("Source Folder");
    setTitle("Source Folder");
    setDescription("This wizard creates a new source folder.");
    this.project = project;
  }

  @Override
  public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NO_BACKGROUND);
    setControl(container);
    container.setLayout(new GridLayout(3, false));
   
    Label lblProject = new Label(container, SWT.NONE);
    lblProject.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblProject.setText("Project");
   
    projectText = new Text(container, SWT.NONE);
    projectText.setEditable(false);
    projectText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    formToolkit.adapt(projectText, true, true);
    if (this.project != null)
      projectText.setText(project.getName());
    new Label(container, SWT.NONE);
    new Label(container, SWT.NONE);
    new Label(container, SWT.NONE);
    new Label(container, SWT.NONE);
   
    Label lblFolderName = new Label(container, SWT.NONE);
    lblFolderName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    formToolkit.adapt(lblFolderName, true, true);
    lblFolderName.setText("Folder Name");
   
    folderNameText = new Text(container, SWT.BORDER);
    folderNameText.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent event) {
        setNewFolderName(folderNameText.getText());
      }
    });
    folderNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    formToolkit.adapt(folderNameText, true, true);
   
    Button lookupButton = new Button(container, SWT.NONE);
    lookupButton.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        Shell shell = Display.getDefault().getActiveShell();
        DirectoryDialog dlg = new DirectoryDialog(shell);

            dlg.setFilterPath(project.getLocation().toOSString());

            // Change the title bar text
            dlg.setText("Source Folder");

            // Customizable message displayed in the dialog
            dlg.setMessage("Select a folder");

            // Calling open() will open and run the dialog.
            // It will return the selected directory, or
            // null if user cancels
            String dir = dlg.open();
            if (dir != null) {
              // Set the text box to the new selection
              folderNameText.setText(dir);
            }
      }
    });
    formToolkit.adapt(lookupButton, true, true);
    lookupButton.setText("...");
//    dirField = new DirectoryFieldEditor("dirField",
//                "Folder",
//                container);
  }

  public String getNewFolderName() {
    return newFolderName;
  }

  public void setNewFolderName(String newFolderName) {
    this.newFolderName = newFolderName;
  }
 
}
TOP

Related Classes of tool.wizards.NewSourceFolderWizardPage

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.