/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package tool.editors.plan;
import java.util.Set;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
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.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ExpandBar;
import org.eclipse.swt.widgets.ExpandItem;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.dialogs.ListSelectionDialog;
import org.eclipse.ui.dialogs.PropertyPage;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.ResourceManager;
import tool.ToolProjectSupport;
import tool.model.ToolPlan;
import tool.model.grammar.IErrorReporter;
import tool.navigator.common.LabelProvider;
public class PlanProperties extends PropertyPage {
private DataBindingContext m_bindingContext;
private Text nameText;
private Text libraryNameText;
private Text txtStartclass;
private Text txtStartmethod;
private TreeViewer supplierPlanTreeViewer;
private Button btnCheckButton;
private Button btnMultithreaded;
private Button btnInternal;
private Combo combo;
private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
protected ToolPlan model;
private IFolder planFolder;
private Text uuidText;
protected ModifyListener dirtyListener = new ModifyListener() {
public void modifyText(ModifyEvent event) {
model.setDirty(true);
}
};
private Spinner compatabilitySpinner;
public PlanProperties() {
setImageDescriptor(ResourceManager.getPluginImageDescriptor("Tool", "icons/package.gif"));
setTitle("Plan Properties");
}
@Override
protected Control createContents(Composite parent) {
noDefaultAndApplyButton();
Composite control = new Composite(parent, SWT.NONE);
control.setLayout(new FillLayout(SWT.VERTICAL));
ExpandBar expandBar = new ExpandBar(control, SWT.NONE);
ExpandItem projectPropertiesExpanditem = new ExpandItem(expandBar, SWT.NONE);
projectPropertiesExpanditem.setExpanded(true);
projectPropertiesExpanditem.setText("Project Properties");
Composite composite = new Composite(expandBar, SWT.NONE);
projectPropertiesExpanditem.setControl(composite);
composite.setLayout(new GridLayout(2, false));
Label lblName = new Label(composite, SWT.NONE);
lblName.setAlignment(SWT.RIGHT);
lblName.setSize(594, 59);
lblName.setText("Name");
nameText = new Text(composite, SWT.BORDER);
GridData gd_nameText = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_nameText.widthHint = 300;
nameText.setLayoutData(gd_nameText);
nameText.setSize(594, 67);
nameText.setEditable(false);
Label lblLibraryName = new Label(composite, SWT.NONE);
lblLibraryName.setAlignment(SWT.RIGHT);
lblLibraryName.setSize(594, 79);
lblLibraryName.setText("Library Name");
libraryNameText = new Text(composite, SWT.BORDER);
libraryNameText.setEditable(false);
GridData gd_libraryNameText = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_libraryNameText.widthHint = 95;
libraryNameText.setLayoutData(gd_libraryNameText);
libraryNameText.setSize(594, 94);
Label lblType = new Label(composite, SWT.NONE);
lblType.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblType.setText("Type");
combo = new Combo(composite, SWT.NONE);
combo.setVisibleItemCount(3);
combo.setItems(new String[] {"APPLICATION", "LIBRARY", "SERVER"});
GridData gd_combo = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_combo.widthHint = 198;
combo.setLayoutData(gd_combo);
new Label(composite, SWT.NONE);
btnCheckButton = new Button(composite, SWT.CHECK);
btnCheckButton.setSize(594, 118);
btnCheckButton.setText("Restricted Availability");
new Label(composite, SWT.NONE);
btnMultithreaded = new Button(composite, SWT.CHECK);
btnMultithreaded.setText("Multithreaded");
new Label(composite, SWT.NONE);
btnInternal = new Button(composite, SWT.CHECK);
btnInternal.setEnabled(false);
btnInternal.setText("Internal");
Label lblCompatibilityLevel = new Label(composite, SWT.NONE);
lblCompatibilityLevel.setSize(594, 158);
lblCompatibilityLevel.setText("Compatibility Level");
compatabilitySpinner = new Spinner(composite, SWT.BORDER);
compatabilitySpinner.addModifyListener(dirtyListener);
GridData gd_compatabilitySpinner = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_compatabilitySpinner.widthHint = 37;
compatabilitySpinner.setLayoutData(gd_compatabilitySpinner);
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);
uuidText.setEditable(false);
uuidText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblStart = new Label(composite, SWT.NONE);
lblStart.setText("Start");
new Label(composite, SWT.NONE);
Label lblStartClass = new Label(composite, SWT.NONE);
lblStartClass.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblStartClass.setBounds(0, 0, 49, 13);
lblStartClass.setText("Class");
txtStartclass = new Text(composite, SWT.BORDER);
txtStartclass.addModifyListener(dirtyListener);
GridData gd_txtStartclass = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_txtStartclass.widthHint = 300;
txtStartclass.setLayoutData(gd_txtStartclass);
Label lblStartMethod = new Label(composite, SWT.NONE);
lblStartMethod.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblStartMethod.setText("Method");
txtStartmethod = new Text(composite, SWT.BORDER);
txtStartmethod.addModifyListener(dirtyListener);
GridData gd_txtStartmethod = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd_txtStartmethod.widthHint = 300;
txtStartmethod.setLayoutData(gd_txtStartmethod);
projectPropertiesExpanditem.setHeight(projectPropertiesExpanditem.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
ExpandItem supplierPlansExpanditem = new ExpandItem(expandBar, SWT.NONE);
supplierPlansExpanditem.setExpanded(true);
supplierPlansExpanditem.setImage(ResourceManager.getPluginImage("Tool", "icons/package.gif"));
supplierPlansExpanditem.setText("Supplier Plans");
Composite composite_1 = new Composite(expandBar, SWT.NONE);
supplierPlansExpanditem.setControl(composite_1);
Button editSuppButton = new Button(composite_1, SWT.NONE);
editSuppButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Set<ToolPlan> allPlans = ToolProjectSupport.getAllPlansForProject(model.getProject());
Set<ToolPlan> supplierPlans = model.getSupplierPlansAsToolPlans();
ListSelectionDialog supplierDialog = new ListSelectionDialog(getShell(),
allPlans,
new IStructuredContentProvider(){
@Override
public void dispose() {
}
@Override
public void inputChanged(Viewer arg0, Object arg1,
Object arg2) {
}
@Override
public Object[] getElements(Object parent) {
if (parent instanceof Set<?>){
return ((Set<?>)parent).toArray();
}
return null;
}
},
new LabelProvider(),
"Select suppier plans from list");
supplierDialog.setInitialSelections(supplierPlans.toArray());
supplierDialog.setTitle("Supplier Plans");
int act = supplierDialog.open();
switch (act){
case Dialog.OK:
/*
* 1. clear the existing suppliers,
* 2. write the selected ones
* 3. rewrite the prx file
*/
Object[] sups = supplierDialog.getResult();
model.clearSuppliers();
for (Object elem : sups){
String name = ((ToolPlan)elem).getToolName();
model.addSupplierPlan(name);
}
model.setDirty(true);
supplierPlanTreeViewer.setInput(model.getSupplierPlansAsToolPlans());
break;
case Dialog.CANCEL:
break;
}
}
});
editSuppButton.setBounds(0, 0, 94, 30);
formToolkit.adapt(editSuppButton, true, true);
editSuppButton.setText("Edit");
composite_1.setLayout(new GridLayout(2, false));
supplierPlanTreeViewer = new TreeViewer(composite_1, SWT.BORDER);
Tree supplierPlanTree = supplierPlanTreeViewer.getTree();
supplierPlanTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
new Label(composite_1, SWT.NONE);
new Label(composite_1, SWT.NONE);
supplierPlanTreeViewer.setContentProvider(new ITreeContentProvider() {
@Override
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
}
@Override
public void dispose() {
}
@Override
public boolean hasChildren(Object parent) {
return false;
}
@Override
public Object getParent(Object child) {
return null;
}
@Override
public Object[] getElements(Object parent) {
if (parent instanceof Set<?>){
return ((Set<?>)parent).toArray();
}
return null;
}
@Override
public Object[] getChildren(Object parent) {
return getElements(parent);
}
});
supplierPlanTreeViewer.setLabelProvider(new LabelProvider());
supplierPlansExpanditem.setHeight(supplierPlansExpanditem.getControl().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
if (this.model != null){
bind();
}
m_bindingContext = initDataBindings();
return control;
}
private void bind() {
m_bindingContext = initDataBindings();
supplierPlanTreeViewer.setInput(this.model.getSupplierPlansAsToolPlans());
}
public IErrorReporter getModel() {
return model;
}
public void setModel(ToolPlan model) {
if (m_bindingContext != null){
m_bindingContext.dispose();
m_bindingContext = null;
}
this.model = model;
if (this.model != null && nameText != null){
bind();
}
}
@Override
public void setElement(IAdaptable element) {
super.setElement(element);
planFolder = (IFolder)element;
if (ToolProjectSupport.isPlanFolder(planFolder)){
ToolPlan plan = ToolProjectSupport.getPlanFromFolder(planFolder);
if (plan != null){
setModel(plan);
}
}
}
@Override
public boolean performOk() {
boolean result = super.performOk();
if (this.model.isDirty()){
this.model.writePrxFile();
this.model.setDirty(false);
}
return result;
}
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
IObservableValue nameTextObserveTextObserveWidget = SWTObservables.observeText(nameText, SWT.Modify);
IObservableValue modelNameObserveValue = BeansObservables.observeValue(model, "toolName");
bindingContext.bindValue(nameTextObserveTextObserveWidget, modelNameObserveValue, null, null);
//
IObservableValue libraryNameTextObserveTextObserveWidget = SWTObservables.observeText(libraryNameText, SWT.Modify);
IObservableValue modelLibraryNameObserveValue = BeansObservables.observeValue(model, "libraryName");
bindingContext.bindValue(libraryNameTextObserveTextObserveWidget, modelLibraryNameObserveValue, null, null);
//
IObservableValue txtStartclassObserveTextObserveWidget = SWTObservables.observeText(txtStartclass, SWT.FocusOut);
IObservableValue modelStartClassObserveValue = BeansObservables.observeValue(model, "startClass");
bindingContext.bindValue(txtStartclassObserveTextObserveWidget, modelStartClassObserveValue, null, null);
//
IObservableValue txtStartmethodObserveTextObserveWidget = SWTObservables.observeText(txtStartmethod, SWT.FocusOut);
IObservableValue modelStartMethodObserveValue = BeansObservables.observeValue(model, "startMethod");
bindingContext.bindValue(txtStartmethodObserveTextObserveWidget, modelStartMethodObserveValue, null, null);
//
IObservableValue btnCheckButtonObserveSelectionObserveWidget = SWTObservables.observeSelection(btnCheckButton);
IObservableValue modelRestrictedObserveValue = BeansObservables.observeValue(model, "restricted");
bindingContext.bindValue(btnCheckButtonObserveSelectionObserveWidget, modelRestrictedObserveValue, null, null);
//
IObservableValue btnMultithreadedObserveSelectionObserveWidget = SWTObservables.observeSelection(btnMultithreaded);
IObservableValue modelMultiThreadedObserveValue = BeansObservables.observeValue(model, "multiThreaded");
bindingContext.bindValue(btnMultithreadedObserveSelectionObserveWidget, modelMultiThreadedObserveValue, null, null);
//
IObservableValue btnInternalObserveSelectionObserveWidget = SWTObservables.observeSelection(btnInternal);
IObservableValue modelInternalObserveValue = BeansObservables.observeValue(model, "internal");
bindingContext.bindValue(btnInternalObserveSelectionObserveWidget, modelInternalObserveValue, null, null);
//
IObservableValue comboObserveSelectionObserveWidget = SWTObservables.observeSelection(combo);
IObservableValue modelProjectTypeObserveValue = BeansObservables.observeValue(model, "projectType");
bindingContext.bindValue(comboObserveSelectionObserveWidget, modelProjectTypeObserveValue, null, null);
//
IObservableValue uuidTextObserveTextObserveWidget = SWTObservables.observeText(uuidText, SWT.Modify);
IObservableValue modelUUIDObserveValue = BeansObservables.observeValue(model, "UUID");
bindingContext.bindValue(uuidTextObserveTextObserveWidget, modelUUIDObserveValue, null, null);
//
IObservableValue compatabilitySpinnerObserveSelectionObserveWidget = SWTObservables.observeSelection(compatabilitySpinner);
IObservableValue modelCompatibilityLevelObserveValue = BeansObservables.observeValue(model, "compatibilityLevel");
bindingContext.bindValue(compatabilitySpinnerObserveSelectionObserveWidget, modelCompatibilityLevelObserveValue, null, null);
//
return bindingContext;
}
}