Jump to: navigation, search

Pave/Tutorials/Add UI

This tutorial explains how you can provide input information for the pattern that was created in the previous tutorial. You will create a simple page and add it to the pattern selection wizard.


Create a DataModelWizardPage

Add a plug-in dependency to org.eclipse.wst.common.frameworks.ui Open plugin.xml with Plug-in Manifest Editor (just double click by default). Go to the Dependencies tab. Choose the Add button and select plugin org.eclipse.wst.common.frameworks.ui

Create a new class with the name com.sap.ide.pattern.simple.ui.SimplePatternWizardPage

In the context menu of your project, choose New > Class.

Enter org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage in the Superclass field.

TUTORIAL2 1.JPG

Complete the wizard.

Now add a single text field for the user to enter the project name that will be created through your pattern. The class should look like this:

package com.sap.ide.pattern.simple.ui;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage;

import com.sap.ide.pattern.simple.SimpleProperties;

public class SimplePatternWizardPage extends DataModelWizardPage {

     private Text projectName;

     protected SimplePatternWizardPage(IDataModel model, String pageName) {
          super(model, pageName);
     }

     @Override
     protected Composite createTopLevelComposite(Composite parent) {
          Composite composite = new Composite(parent, SWT.NULL);
          composite.setLayout(new GridLayout());
          GridData data = new GridData(GridData.FILL_BOTH);
          data.widthHint = 300;
          composite.setLayoutData(data);

          createNameDescription(composite);

          projectName.setFocus();

         Dialog.applyDialogFont(parent);
          return composite;
     }


     protected void createNameDescription(Composite parent) {
          Composite composite = new Composite(parent, SWT.NULL);
          composite.setLayout(new GridLayout(2, false));
          composite.setLayoutData(new GridData(GridData.FILL_BOTH));
          // display name
          Label projectNameLabel = new Label(composite, SWT.LEFT);
          projectNameLabel.setText("Project name");
          projectNameLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
          projectName = new Text(composite, SWT.SINGLE | SWT.BORDER);
          projectName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
          synchHelper.synchText(projectName, SimpleProperties.PROJECT_NAME
                    , null);
     }
     @Override
     protected String[] getValidationPropertyNames() {
          return null;
     }
}


Create a DMWizardExtensionFactory

Create a class SimplePatternWizardExt that extends com.sap.ide.pattern.application.framework.ui.wizard.PGWizardPageFactory.

It describes the pages that are added to the pattern wizard.

Edit the class to look like this:

package com.sap.ide.pattern.simple.ui;

import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage;
import org.eclipse.wst.common.frameworks.internal.operation.extensionui.DMWizardExtensionFactory;

import com.sap.ide.pattern.application.framework.IPattern;
import com.sap.ide.pattern.application.framework.ui.wizard.PGWizardPageFactory;

public class SimplePatternWizardExt extends PGWizardPageFactory {

	@Override
	public DataModelWizardPage[] createPageGroup(IDataModel dataModel,
			String pageGroupID) {
			return new DataModelWizardPage[]{new SimplePatternWizardPage(dataModel,"Project Name Page")};
	}

	@Override
	public String[] getStepsDescription() {
		return new String[]{"Project Data."};
	}
}


Register a pattern User Interface in the plugin.xml file

Register an extension to extension point com.sap.ide.pattern.application.framework.ui.PatternUI.

Enter SimpleProjectCreation for the targetPatternId, which is the ID of the pattern created in the previous tutorial.

Enter com.sap.ide.pattern.simple.ui.SimplePatternWizardExt for the factoryClass.

TUTORIAL2 2.JPG


Test it!

Now when you select your simple pattern from the patterns list, the Next button becomes enabled and after you choose your page for editing, the project name is displayed.

TUTORIAL2 3.JPG