org.activiti.designer.eclipse.ui.AbstractInputFieldWizardPage Maven / Gradle / Ivy
The newest version!
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.designer.eclipse.ui;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.resource.ImageDescriptor;
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.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
/**
* The Class AbstractInputFieldWizardPage.
*/
public abstract class AbstractInputFieldWizardPage extends AbstractWizardPage {
// constants
private static final int SIZING_TEXT_FIELD_WIDTH = 250;
// widgets
/**
* The text field.
*/
Text textField;
private Listener nameModifyListener = new Listener() {
public void handleEvent(Event e) {
boolean valid = validatePage();
setPageComplete(valid);
}
};
/**
* Instantiates a new abstract input field wizard page.
*
* @param pageName
* the page name
* @param title
* the title
* @param titleImage
* the title image
*/
public AbstractInputFieldWizardPage(String pageName, String title, ImageDescriptor titleImage) {
super(pageName, title, titleImage);
}
/**
* Instantiates a new abstract input field wizard page.
*
* @param pageName
* the page name
*/
protected AbstractInputFieldWizardPage(String pageName) {
super(pageName);
}
/*
* (non-Javadoc)
*
* @seeorg.eclipse.graphiti.examples.testview.wizard.AbstractWizardPage#
* createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NULL);
composite.setFont(parent.getFont());
initializeDialogUnits(parent);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
createWizardContents(composite);
setPageComplete(validatePage());
// Show description on opening
setErrorMessage(null);
setMessage(null);
setControl(composite);
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.graphiti.examples.testview.wizard.ITextProvider#getText()
*/
public String getText() {
if (textField == null) {
return getInitialTextFieldValue();
}
return getTextFieldValue();
}
/**
* Validate page.
*
* @return true, if successful
*/
protected boolean validatePage() {
String text = getTextFieldValue();
if (text.equals("")) { //$NON-NLS-1$
setErrorMessage(null);
setMessage(getMessageText());
return false;
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IStatus status = doWorkspaceValidation(workspace, text);
if (!status.isOK()) {
setErrorMessage(status.getMessage());
return false;
}
setErrorMessage(null);
setMessage(null);
return true;
}
/**
* Do workspace validation.
*
* @param workspace
* the workspace
* @param text
* the text
*
* @return the i status
*/
abstract IStatus doWorkspaceValidation(IWorkspace workspace, String text);
/**
* Gets the initial text field value.
*
* @return the initial text field value
*/
abstract String getInitialTextFieldValue();
/**
* Gets the label text.
*
* @return the label text
*/
abstract String getLabelText();
/**
* Gets the message text.
*
* @return the message text
*/
abstract String getMessageText();
/*
* (non-Javadoc)
*
* @seeorg.eclipse.graphiti.samples.testview.wizard.AbstractWizardPage#
* createWizardContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected void createWizardContents(Composite parent) {
createProjectNameGroup(parent);
}
private final void createProjectNameGroup(Composite parent) {
// project specification group
Composite projectGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
projectGroup.setLayout(layout);
projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// new project label
Label projectLabel = new Label(projectGroup, SWT.NONE);
projectLabel.setText(getLabelText());
projectLabel.setFont(parent.getFont());
// new project name entry field
textField = new Text(projectGroup, SWT.BORDER);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = SIZING_TEXT_FIELD_WIDTH;
textField.setLayoutData(data);
textField.setFont(parent.getFont());
// Set the initial value first before listener
// to avoid handling an event during the creation.
if (getInitialTextFieldValue() != null) {
textField.setText(getInitialTextFieldValue());
}
textField.addListener(SWT.Modify, nameModifyListener);
}
private String getTextFieldValue() {
if (textField == null) {
return ""; //$NON-NLS-1$
}
return textField.getText().trim();
}
}