Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

PAVE/Tutorials/Create Simple Pattern

< PAVE
Revision as of 10:43, 26 May 2009 by Unnamed Poltroon (Talk) (New page: == Overview == This tutorial explains how you can create step by step a simple Pattern that will generate a project resource in your workspace. First, you have to define a pattern. To do t...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Overview

This tutorial explains how you can create step by step a simple Pattern that will generate a project resource in your workspace. First, you have to define a pattern. To do that you have to create an extension point containing the following information:

Id
the id has to be unique for the pattern.


Name
which will be shown in the default wizard.


Description
this is a long description of what the pattern does; it is aimed to inform the end
user of what operations will be executed when the pattern is applied.


Enablement
which will show if the action can be executed in the current context.


Pattern generator class
this class will actually manage the model and it will return the generator itself.


Create Plug-in project

You need a new plug-in project, for example com.sap.ide.pattern.simple.

Select New > Project > Plug-in Project

TUTORIAL1 1.gif

Enter a name for the project: com.sap.ide.pattern.simple

TUTORIAL2.gif

Complete the wizard.

TUTORIAL1 2.gif

The next thing you have to do is to setup the plug-in dependencies.

These are the dependencies that you need during the entire tutorial, so you do not have to edit them again.

TUTORIAL1 3.gif

org.eclipse.ui,
org.eclipse.core.runtime,
com.sap.ide.pattern.application.framework,
org.eclipse.jst.common.frameworks,
org.eclipse.wst.common.frameworks,
org.eclipse.core.resources,
org.eclipse.core.expressions,
org.junit

Having prepared your environment, you can start the pattern implementation.

Create DataModelProvider Next thing you have to do is to generate the main operation files of the pattern.

These are the DataModelProvider and DataModelOperation.

Let's start with DataModelProvider.

You need to create new class called: SimplePatternDataModelProvider, which will extend AbstractDataModelProvider

TUTORIAL1 4.gif

Next you have to override some methods from the abstract class.

TUTORIAL1 5.gif

You have to override:

   * getDefaultOperation() - this is generator, whose execute method will be called when finishing.
   * getDefaultProperty(propertyName) - this is a method, which will return default values for the metadata stored in the model. This is particularly useful when a pattern can be executed entirely with default values, without user interaction.
   * getPropertyNames(propertyName) - this method shows the framework, which properties its model will use. These properties will be passed to the validate method and getDefaultProperty method will be called on them.
   * validate(propertyName) - validation method, where you need to validate the properties that you have specified in the getPropertyNames method.

Next, you have to specify the properties. It is recommended that you create a separate interface for them and let the SimplePatternDataModelProvider to implement this interface.

Create SimpleProperties interface and place one property in it.

TUTORIAL1 6.gif

It is recommended that the properties' values are formed with the <ClassName>.<PropertyName>. This is done for uniqueness when more complex operations are done.

TUTORIAL1 7.gif

Now make the SimplePatternDataModelProvider implement the SimpleProperies.

TUTORIAL1 8.gif

To add the property into getPropertyNames

implement getDefaultProperty, so that it returns simpleProject value.

Implement validation, so that the property has a valid name.

 package com.sap.ide.pattern.simple;

import java.util.Set;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider;
import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation;

public class SimplePatternDataModelProvider extends AbstractDataModelProvider implements SimpleProperties {

	@Override
	public IDataModelOperation getDefaultOperation() {
		return new SimpleOperation(getDataModel());
	}

	@Override
	public Set getPropertyNames() {
		Set propertyNames = super.getPropertyNames();
		propertyNames.add(PROJECT_NAME);
		return propertyNames;
	}

	@Override
	public Object getDefaultProperty(String propertyName) {
		if (PROJECT_NAME.equals(propertyName)){
			return "simpleProject";
		}
		return super.getDefaultProperty(propertyName);
	}

	@Override
	public IStatus validate(String name) {
		if (PROJECT_NAME.equals(name)){
			return ResourcesPlugin.getWorkspace().validateName(
					getDataModel().getStringProperty(name), IResource.PROJECT);
		}
		return super.validate(name);
	}


}

Back to the top