org.eclipse.ocl.examples.emf.validation.validity.ui.ripoffs
Class ResourceAndContainerGroup

java.lang.Object
  extended by org.eclipse.ocl.examples.emf.validation.validity.ui.ripoffs.ResourceAndContainerGroup
All Implemented Interfaces:
org.eclipse.swt.widgets.Listener

public class ResourceAndContainerGroup
extends java.lang.Object
implements org.eclipse.swt.widgets.Listener

Workbench-level composite for resource and container specification by the user. Services such as field validation are performed by the group. The group can be configured to accept existing resources, or only new resources.


Field Summary
static int PROBLEM_CONTAINER_EMPTY
          Constant for empty container.
static int PROBLEM_NAME_INVALID
          Constant for invalid name.
static int PROBLEM_NONE
          Constant for no problem.
static int PROBLEM_PATH_INVALID
          Constant for invalid path.
static int PROBLEM_PATH_OCCUPIED
          Constant for path already occupied.
static int PROBLEM_PROJECT_DOES_NOT_EXIST
          Constant for project does not exist.
static int PROBLEM_RESOURCE_EMPTY
          Constant for empty resource.
static int PROBLEM_RESOURCE_EXIST
          Constant for resource already exists.
 
Constructor Summary
ResourceAndContainerGroup(org.eclipse.swt.widgets.Composite parent, org.eclipse.swt.widgets.Listener client, java.lang.String resourceFieldLabel, java.lang.String resourceType, boolean showClosedProjects, int heightHint)
          Create an instance of the group to allow the user to enter/select a container and specify a resource name.
 
Method Summary
 boolean areAllValuesValid()
          Returns a boolean indicating whether all controls in this group contain valid values.
protected  void createContents(org.eclipse.swt.widgets.Composite parent, java.lang.String resourceLabelString, int heightHint)
          Creates this object's visual components.
 boolean getAllowExistingResources()
          Returns the flag indicating whether existing resources are permitted.
 org.eclipse.core.runtime.IPath getContainerFullPath()
          Returns the path of the currently selected container or null if no container has been selected.
 java.lang.String getProblemMessage()
          Returns an error message indicating the current problem with the value of a control in the group, or an empty message if all controls in the group contain valid values.
 int getProblemType()
          Returns the type of problem with the value of a control in the group.
 java.lang.String getResource()
          Returns a string that is the name of the chosen resource, or an empty string if no resource has been entered.
 void handleEvent(org.eclipse.swt.widgets.Event e)
          Handles events for all controls in the group.
 void setAllowExistingResources(boolean value)
          Sets the flag indicating whether existing resources are permitted.
 void setContainerFullPath(org.eclipse.core.runtime.IPath path)
          Sets the value of this page's container.
 void setFocus()
          Gives focus to the resource name field and selects its contents
 void setResource(java.lang.String value)
          Sets the value of this page's resource name.
 void setResourceExtension(java.lang.String value)
          Set the only file extension allowed for the resource name field.
protected  boolean validateContainer()
          Returns a boolean indicating whether a container name represents a valid container resource in the workbench.
protected  boolean validateControls()
          Validates the values for each of the group's controls.
protected  boolean validateFullResourcePath(org.eclipse.core.runtime.IPath resourcePath)
          Returns a boolean indicating whether the specified resource path represents a valid new resource in the workbench.
protected  boolean validateResourceName()
          Returns a boolean indicating whether the resource name rep- resents a valid resource name in the workbench.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROBLEM_NONE

public static final int PROBLEM_NONE
Constant for no problem.

See Also:
Constant Field Values

PROBLEM_RESOURCE_EMPTY

public static final int PROBLEM_RESOURCE_EMPTY
Constant for empty resource.

See Also:
Constant Field Values

PROBLEM_RESOURCE_EXIST

public static final int PROBLEM_RESOURCE_EXIST
Constant for resource already exists.

See Also:
Constant Field Values

PROBLEM_PATH_INVALID

public static final int PROBLEM_PATH_INVALID
Constant for invalid path.

See Also:
Constant Field Values

PROBLEM_CONTAINER_EMPTY

public static final int PROBLEM_CONTAINER_EMPTY
Constant for empty container.

See Also:
Constant Field Values

PROBLEM_PROJECT_DOES_NOT_EXIST

public static final int PROBLEM_PROJECT_DOES_NOT_EXIST
Constant for project does not exist.

See Also:
Constant Field Values

PROBLEM_NAME_INVALID

public static final int PROBLEM_NAME_INVALID
Constant for invalid name.

See Also:
Constant Field Values

PROBLEM_PATH_OCCUPIED

public static final int PROBLEM_PATH_OCCUPIED
Constant for path already occupied.

See Also:
Constant Field Values
Constructor Detail

ResourceAndContainerGroup

public ResourceAndContainerGroup(org.eclipse.swt.widgets.Composite parent,
                                 org.eclipse.swt.widgets.Listener client,
                                 java.lang.String resourceFieldLabel,
                                 java.lang.String resourceType,
                                 boolean showClosedProjects,
                                 int heightHint)
Create an instance of the group to allow the user to enter/select a container and specify a resource name.

Parameters:
parent - composite widget to parent the group
client - object interested in changes to the group's fields value
resourceFieldLabel - label to use in front of the resource name field
resourceType - one word, in lowercase, to describe the resource to the user (file, folder, project)
showClosedProjects - whether or not to show closed projects
heightHint - height hint for the container selection widget group
Method Detail

areAllValuesValid

public boolean areAllValuesValid()
Returns a boolean indicating whether all controls in this group contain valid values.

Returns:
boolean

createContents

protected void createContents(org.eclipse.swt.widgets.Composite parent,
                              java.lang.String resourceLabelString,
                              int heightHint)
Creates this object's visual components.

Parameters:
parent - org.eclipse.swt.widgets.Composite
heightHint - height hint for the container selection widget group

getContainerFullPath

public org.eclipse.core.runtime.IPath getContainerFullPath()
Returns the path of the currently selected container or null if no container has been selected. Note that the container may not exist yet if the user entered a new container name in the field.

Returns:
The path of the container, or null

getProblemMessage

public java.lang.String getProblemMessage()
Returns an error message indicating the current problem with the value of a control in the group, or an empty message if all controls in the group contain valid values.

Returns:
java.lang.String

getProblemType

public int getProblemType()
Returns the type of problem with the value of a control in the group.

Returns:
one of the PROBLEM_* constants

getResource

public java.lang.String getResource()
Returns a string that is the name of the chosen resource, or an empty string if no resource has been entered.

The name will include the resource extension if the preconditions are met.

Returns:
The resource name
Since:
3.3
See Also:
setResourceExtension(String)

handleEvent

public void handleEvent(org.eclipse.swt.widgets.Event e)
Handles events for all controls in the group.

Specified by:
handleEvent in interface org.eclipse.swt.widgets.Listener
Parameters:
e - org.eclipse.swt.widgets.Event

setAllowExistingResources

public void setAllowExistingResources(boolean value)
Sets the flag indicating whether existing resources are permitted.

Parameters:
value -

setContainerFullPath

public void setContainerFullPath(org.eclipse.core.runtime.IPath path)
Sets the value of this page's container.

Parameters:
path - Full path to the container.

setFocus

public void setFocus()
Gives focus to the resource name field and selects its contents


setResource

public void setResource(java.lang.String value)
Sets the value of this page's resource name.

Parameters:
value - new value

setResourceExtension

public void setResourceExtension(java.lang.String value)
Set the only file extension allowed for the resource name field.

If a resource extension is specified, then it will always be appended with a '.' to the text from the resource name field for validation when the following conditions are met:

(1) Resource extension length is greater than 0
(2) Resource name field text length is greater than 0
(3) Resource name field text does not already end with a '.' and the resource extension specified (case sensitive)

The resource extension will not be reflected in the actual resource name field until the resource name field loses focus.

Parameters:
value - The resource extension without the '.' prefix (e.g. 'java', 'xml')
Since:
3.3

validateContainer

protected boolean validateContainer()
Returns a boolean indicating whether a container name represents a valid container resource in the workbench. An error message is stored for future reference if the name does not represent a valid container.

Returns:
boolean indicating validity of the container name

validateControls

protected boolean validateControls()
Validates the values for each of the group's controls. If an invalid value is found then a descriptive error message is stored for later reference. Returns a boolean indicating the validity of all of the controls in the group.


validateFullResourcePath

protected boolean validateFullResourcePath(org.eclipse.core.runtime.IPath resourcePath)
Returns a boolean indicating whether the specified resource path represents a valid new resource in the workbench. An error message is stored for future reference if the path does not represent a valid new resource path.

Parameters:
resourcePath - the path to validate
Returns:
boolean indicating validity of the resource path

validateResourceName

protected boolean validateResourceName()
Returns a boolean indicating whether the resource name rep- resents a valid resource name in the workbench. An error message is stored for future reference if the name does not represent a valid resource name.

Returns:
boolean indicating validity of the resource name

getAllowExistingResources

public boolean getAllowExistingResources()
Returns the flag indicating whether existing resources are permitted.

Returns:
The allow existing resources flag.
Since:
3.4
See Also:
setAllowExistingResources(boolean)