package tool.editors.cdf;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPartConstants;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.ResourceManager;
import tool.ToolPlugin;
import tool.model.ToolClass;
import tool.model.ToolServiceObject;
import tool.model.ToolType;
import tool.model.validation.ToolNameValidator;
import tool.search.SelectType;
public class ServiceObjectEditor extends FormPage implements PropertyChangeListener{
private DataBindingContext m_bindingContext;
public static final String ID = "tool.editors.cdf.ServiceObjectEditor";
private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
private ToolServiceObject so;
private Text soNameText;
private Text soClassText;
private Combo visabilityCombo;
private Combo dialogDurationCombo;
private Text UUIDText;
private Button btnLoadBalanced;
private Text searchPathText;
private Text resourceNameText;
private Text userNameText;
private Text userPasswordText;
private Text managerText;
private Label lblSuperClass;
private Button lookupButton;
private Label lblResourceManager;
private Label lblUserName;
private Label lblUserPassword;
private Label lblManager;
public ServiceObjectEditor(){
this(ID, "Service Object");
}
/**
* Create the form page.
* @param id
* @param title
*/
public ServiceObjectEditor(String id, String title) {
super(id, title);
}
/**
* Create the form page.
* @param editor
* @param id
* @param title
* @wbp.parser.constructor
* @wbp.eval.method.parameter id "Some id"
* @wbp.eval.method.parameter title "Some title"
*/
public ServiceObjectEditor(FormEditor editor, String id, String title) {
super(editor, id, title);
}
@Override
public void createPartControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout gl_composite = new GridLayout(3, false);
gl_composite.horizontalSpacing = 8;
composite.setLayout(gl_composite);
Label lblName = new Label(composite, SWT.NONE);
lblName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblName.setText("Name");
soNameText = new Text(composite, SWT.BORDER);
GridData gd_classNameText = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd_classNameText.widthHint = 224;
soNameText.setLayoutData(gd_classNameText);
toolkit.adapt(soNameText, true, true);
new Label(composite, SWT.NONE);
lblSuperClass = new Label(composite, SWT.NONE);
lblSuperClass.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblSuperClass.setText("Class");
soClassText = new Text(composite, SWT.BORDER);
GridData gd_superClassText = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd_superClassText.widthHint = 226;
soClassText.setLayoutData(gd_superClassText);
toolkit.adapt(soClassText, true, true);
lookupButton = new Button(composite, SWT.NONE);
lookupButton.setImage(ResourceManager.getPluginImage("Tool", "icons/look_up.gif"));
lookupButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ToolType typeClass = ToolClass.fetch(so.getProject(), so.getType());
ToolType newClass = (ToolType) SelectType.select(so, typeClass);
if (newClass != null)
so.setType(newClass.getFullName());
}
});
lookupButton.setToolTipText("Class lookup");
toolkit.adapt(lookupButton, true, true);
Label lblVisability = new Label(composite, SWT.NONE);
lblVisability.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblVisability.setText("Visability");
visabilityCombo = new Combo(composite, SWT.READ_ONLY);
visabilityCombo.setItems(new String[] {"ENVIRONMENT", "USER"});
visabilityCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
toolkit.adapt(visabilityCombo);
toolkit.paintBordersFor(visabilityCombo);
new Label(composite, SWT.NONE);
Label lblDialogDuration = new Label(composite, SWT.NONE);
lblDialogDuration.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblDialogDuration.setText("Dialog Duration");
dialogDurationCombo = new Combo(composite, SWT.READ_ONLY);
dialogDurationCombo.setItems(new String[] {"MESSAGE", "TRANSACTION", "SESSION"});
dialogDurationCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
toolkit.adapt(dialogDurationCombo);
toolkit.paintBordersFor(dialogDurationCombo);
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
btnLoadBalanced = new Button(composite, SWT.CHECK);
btnLoadBalanced.setText("Load Balance");
new Label(composite, SWT.NONE);
new Label(composite, SWT.NONE);
Button btnFailOver = new Button(composite, SWT.CHECK);
btnFailOver.setText("Fail Over");
new Label(composite, SWT.NONE);
Label lblUuid = new Label(composite, SWT.NONE);
lblUuid.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblUuid.setText("UUID");
UUIDText = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
GridData gd_UUIDText = new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1);
gd_UUIDText.widthHint = 262;
UUIDText.setLayoutData(gd_UUIDText);
toolkit.adapt(UUIDText, true, true);
new Label(composite, SWT.NONE);
Label lblNewLabel = new Label(composite, SWT.NONE);
lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblNewLabel .setText("Search Path");
searchPathText = new Text(composite, SWT.BORDER);
searchPathText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
toolkit.adapt(searchPathText, true, true);
new Label(composite, SWT.NONE);
lblManager = new Label(composite, SWT.NONE);
lblManager.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblManager.setText("Manager");
managerText = new Text(composite, SWT.BORDER);
managerText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
toolkit.adapt(managerText, true, true);
new Label(composite, SWT.NONE);
lblResourceManager = new Label(composite, SWT.NONE);
lblResourceManager.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblResourceManager.setText("Resource");
resourceNameText = new Text(composite, SWT.BORDER);
resourceNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
toolkit.adapt(resourceNameText, true, true);
new Label(composite, SWT.NONE);
lblUserName = new Label(composite, SWT.NONE);
lblUserName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblUserName.setText("User Name");
userNameText = new Text(composite, SWT.BORDER);
userNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
toolkit.adapt(userNameText, true, true);
new Label(composite, SWT.NONE);
lblUserPassword = new Label(composite, SWT.NONE);
lblUserPassword.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
toolkit.adapt(lblUserPassword, true, true);
lblUserPassword.setText("User Password");
userPasswordText = new Text(composite, SWT.BORDER);
userPasswordText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
toolkit.adapt(userPasswordText, true, true);
new Label(composite, SWT.NONE);
if (so != null)
m_bindingContext = initDataBindings();
}
@Override
public Image getTitleImage() {
return ToolPlugin.getImage("icons/service_object.gif");
}
public boolean isSaveAsAllowed() {
return false;
}
public ToolServiceObject getSo() {
return so;
}
public void setSo(ToolServiceObject so) {
if (m_bindingContext != null){
m_bindingContext.dispose();
m_bindingContext = null;
}
this.so = so;
this.so.setDirty(false);
this.so.addPropertyChangeListener("dirty", this);
if (this.so != null && this.soNameText != null){
m_bindingContext = initDataBindings();
}
}
@Override
public void doSave(IProgressMonitor monitor) {
this.so.toSource();
super.doSave(monitor);
}
public void init(IEditorSite site, IEditorInput editorInput) {
super.init(site, editorInput);
IFileEditorInput ifei = (IFileEditorInput)editorInput;
IFile modelFile = ifei.getFile();
ToolServiceObject so = ToolServiceObject.fetch(modelFile);
setPartName(so.getToolName());
this.setSo(so);
}
@Override
public boolean isDirty() {
return this.so.isDirty();
}
@Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getPropertyName().equalsIgnoreCase("dirty")){
firePropertyChange(IWorkbenchPartConstants.PROP_DIRTY);
}
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
IObservableValue soClassTextObserveTextObserveWidget = SWTObservables.observeText(soClassText, SWT.Modify);
IObservableValue soTypeObserveValue = BeansObservables.observeValue(so, "type");
bindingContext.bindValue(soClassTextObserveTextObserveWidget, soTypeObserveValue, null, null);
//
IObservableValue dialogDurationComboObserveSelectionObserveWidget = SWTObservables.observeSelection(dialogDurationCombo);
IObservableValue soDialogDurationObserveValue = BeansObservables.observeValue(so, "dialogDuration");
bindingContext.bindValue(dialogDurationComboObserveSelectionObserveWidget, soDialogDurationObserveValue, null, null);
//
IObservableValue uUIDTextObserveTextObserveWidget = SWTObservables.observeText(UUIDText, SWT.NONE);
IObservableValue soUuidObserveValue = BeansObservables.observeValue(so, "uuid");
bindingContext.bindValue(uUIDTextObserveTextObserveWidget, soUuidObserveValue, null, null);
//
IObservableValue visabilityComboObserveSelectionObserveWidget = SWTObservables.observeSelection(visabilityCombo);
IObservableValue soVisabilityObserveValue = BeansObservables.observeValue(so, "visability");
bindingContext.bindValue(visabilityComboObserveSelectionObserveWidget, soVisabilityObserveValue, null, null);
//
IObservableValue btnLoadBalancedObserveSelectionObserveWidget = SWTObservables.observeSelection(btnLoadBalanced);
IObservableValue soLoadBalanceObserveValue = BeansObservables.observeValue(so, "loadBalance");
bindingContext.bindValue(btnLoadBalancedObserveSelectionObserveWidget, soLoadBalanceObserveValue, null, null);
//
IObservableValue soNameTextObserveTextObserveWidget = SWTObservables.observeText(soNameText, SWT.Modify);
IObservableValue soToolNameObserveValue = BeansObservables.observeValue(so, "toolName");
UpdateValueStrategy strategy = new UpdateValueStrategy();
strategy.setAfterConvertValidator(new ToolNameValidator(soNameText));
bindingContext.bindValue(soNameTextObserveTextObserveWidget, soToolNameObserveValue, strategy, null);
//
IObservableValue searchPathTextObserveTextObserveWidget = SWTObservables.observeText(searchPathText, SWT.Modify);
IObservableValue soSearchPathObserveValue = BeansObservables.observeValue(so, "searchPath");
bindingContext.bindValue(searchPathTextObserveTextObserveWidget, soSearchPathObserveValue, null, null);
//
IObservableValue resourceNameTextObserveTextObserveWidget = SWTObservables.observeText(resourceNameText, SWT.Modify);
IObservableValue soResourceNameObserveValue = BeansObservables.observeValue(so, "resourceName");
bindingContext.bindValue(resourceNameTextObserveTextObserveWidget, soResourceNameObserveValue, null, null);
//
IObservableValue userNameTextObserveTextObserveWidget = SWTObservables.observeText(userNameText, SWT.Modify);
IObservableValue soUserNameObserveValue = BeansObservables.observeValue(so, "userName");
bindingContext.bindValue(userNameTextObserveTextObserveWidget, soUserNameObserveValue, null, null);
//
IObservableValue userPasswordTextObserveTextObserveWidget = SWTObservables.observeText(userPasswordText, SWT.Modify);
IObservableValue soUserPasswordObserveValue = BeansObservables.observeValue(so, "userPassword");
bindingContext.bindValue(userPasswordTextObserveTextObserveWidget, soUserPasswordObserveValue, null, null);
//
IObservableValue managerTextObserveTextObserveWidget = SWTObservables.observeText(managerText, SWT.Modify);
IObservableValue soExternalManagerObserveValue = BeansObservables.observeValue(so, "externalManager");
bindingContext.bindValue(managerTextObserveTextObserveWidget, soExternalManagerObserveValue, null, null);
//
IObservableValue lookupButtonObserveVisibleObserveWidget = SWTObservables.observeVisible(lookupButton);
IObservableValue soToolSOObserveValue = BeansObservables.observeValue(so, "toolSO");
bindingContext.bindValue(lookupButtonObserveVisibleObserveWidget, soToolSOObserveValue, null, null);
//
IObservableValue soClassTextObserveEditableObserveWidget = SWTObservables.observeEditable(soClassText);
bindingContext.bindValue(soClassTextObserveEditableObserveWidget, soToolSOObserveValue, null, null);
//
IObservableValue lblManagerObserveVisibleObserveWidget = SWTObservables.observeVisible(lblManager);
IObservableValue soDatabaseSOObserveValue = BeansObservables.observeValue(so, "databaseSO");
bindingContext.bindValue(lblManagerObserveVisibleObserveWidget, soDatabaseSOObserveValue, null, null);
//
IObservableValue managerTextObserveVisibleObserveWidget = SWTObservables.observeVisible(managerText);
bindingContext.bindValue(managerTextObserveVisibleObserveWidget, soDatabaseSOObserveValue, null, null);
//
IObservableValue lblUserNameObserveVisibleObserveWidget = SWTObservables.observeVisible(lblUserName);
IObservableValue soDBSessionSOObserveValue = BeansObservables.observeValue(so, "DBSessionSO");
bindingContext.bindValue(lblUserNameObserveVisibleObserveWidget, soDBSessionSOObserveValue, null, null);
//
IObservableValue userNameTextObserveVisibleObserveWidget = SWTObservables.observeVisible(userNameText);
bindingContext.bindValue(userNameTextObserveVisibleObserveWidget, soDBSessionSOObserveValue, null, null);
//
IObservableValue lblUserPasswordObserveVisibleObserveWidget = SWTObservables.observeVisible(lblUserPassword);
bindingContext.bindValue(lblUserPasswordObserveVisibleObserveWidget, soDBSessionSOObserveValue, null, null);
//
IObservableValue userPasswordTextObserveVisibleObserveWidget = SWTObservables.observeVisible(userPasswordText);
bindingContext.bindValue(userPasswordTextObserveVisibleObserveWidget, soDBSessionSOObserveValue, null, null);
//
IObservableValue lblResourceManagerObserveVisibleObserveWidget = SWTObservables.observeVisible(lblResourceManager);
bindingContext.bindValue(lblResourceManagerObserveVisibleObserveWidget, soDBSessionSOObserveValue, null, null);
//
IObservableValue resourceNameTextObserveVisibleObserveWidget = SWTObservables.observeVisible(resourceNameText);
bindingContext.bindValue(resourceNameTextObserveVisibleObserveWidget, soDBSessionSOObserveValue, null, null);
//
return bindingContext;
}
}