Commit b62bb88b authored by Christoph Döbber's avatar Christoph Döbber
Browse files

fix

refs 751
parent 53ec20f7
......@@ -54,8 +54,8 @@ import org.fortiss.tooling.kernel.service.IPersistencyService;
* @version $Rev: 18709 $
* @ConQAT.Rating GREEN Hash: 0077A4C9EB79518CC4EF5027034AB656
*/
public abstract class DataStateEditorBase<T extends IDataStateVariableProvider>
extends FormsEditorBase<T> {
public abstract class DataStateEditorBase<T extends IDataStateVariableProvider> extends
FormsEditorBase<T> {
/** Stores the table viewer. */
private TableViewer viewer;
......@@ -69,13 +69,18 @@ public abstract class DataStateEditorBase<T extends IDataStateVariableProvider>
/** Creates the data state edit section. */
private void createEditDataStateSection() {
final Composite client = createNewSection("Data State Variables",
"This section defines the data state variables of the specification.");
final Composite client =
createNewSection("Data State Variables",
"This section defines the data state variables of the specification.");
client.setLayout(new GridLayout(2, false));
final DataStateTableViewer tableViewer = new DataStateTableViewer();
viewer = tableViewer.createTableViewer(client);
// TODO CD: workaround for bug #751 - re-enable sorting later when there is time.
// https://af3.fortiss.org/issues/751
viewer.setSorter(null);
Button b = toolkit.createButton(client, "Add", SWT.PUSH);
b.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
b.addSelectionListener(new SelectionAdapter() {
......@@ -108,47 +113,43 @@ public abstract class DataStateEditorBase<T extends IDataStateVariableProvider>
/** {@inheritDoc} */
@Override
protected int compare(Viewer viewer, Object o1, Object o2) {
return ((DataStateVariable) o1).getIdentifier().compareTo(
((DataStateVariable) o2).getIdentifier());
return ((DataStateVariable)o1).getIdentifier().compareTo(
((DataStateVariable)o2).getIdentifier());
}
/** {@inheritDoc} */
@Override
protected void createColumns(TableViewer viewer) {
// name column
createColumn(viewer, getBounds()[0], getTitles()[0],
getTooltips()[0], new ColumnLabelProvider() {
createColumn(viewer, getBounds()[0], getTitles()[0], getTooltips()[0],
new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((DataStateVariable) element)
.getIdentifier();
return ((DataStateVariable)element).getIdentifier();
}
}, new DataStateVariableNameEditingSupport(viewer, dbc,
getContentObject()));
}, new DataStateVariableNameEditingSupport(viewer, dbc, getContentObject()));
// type column
createColumn(viewer, getBounds()[1], getTitles()[1],
getTooltips()[1], new ColumnLabelProvider() {
createColumn(viewer, getBounds()[1], getTitles()[1], getTooltips()[1],
new ColumnLabelProvider() {
@Override
public String getText(Object element) {
final IType t = ((DataStateVariable) element)
.getType();
final IType t = ((DataStateVariable)element).getType();
return t != null ? t.toString() : "";
}
}, new DataStateTypeEditingSupport(viewer, dbc,
getContentObject()));
}, new DataStateTypeEditingSupport(viewer, dbc, getContentObject()));
// initial value column
createColumn(viewer, getBounds()[2], getTitles()[2],
getTooltips()[2], new ColumnLabelProvider() {
createColumn(viewer, getBounds()[2], getTitles()[2], getTooltips()[2],
new ColumnLabelProvider() {
@Override
public String getText(Object element) {
final ITerm t = ((DataStateVariable) element)
.getInitialValue();
final ITerm t = ((DataStateVariable)element).getInitialValue();
return t != null ? t.toString() : "";
}
}, new DataStateValueEditingSupport(viewer, dbc,
getContentObject()));
}, new DataStateValueEditingSupport(viewer, dbc, getContentObject()));
}
/** {@inheritDoc} */
......@@ -165,29 +166,26 @@ public abstract class DataStateEditorBase<T extends IDataStateVariableProvider>
/** Table column titles. */
protected String[] getTitles() {
return new String[] { "Variable", "Type", "Initial Value" };
return new String[] {"Variable", "Type", "Initial Value"};
}
/** Table column tool tips. */
protected String[] getTooltips() {
return new String[] { "Variable Name", "Variable Type",
"Initial Value" };
return new String[] {"Variable Name", "Variable Type", "Initial Value"};
}
/** Table column widths. */
protected int[] getBounds() {
return new int[] { 120, 120, 120 };
return new int[] {120, 120, 120};
}
}
/** Adds a new variable to the specification. */
private void addNewVariable() {
String vName = "v"
+ (getEditedObject().getDataStateVariablesList().size() + 1);
final DataStateVariable dsvar = createDataStateVariable(vName,
intType(), intConst(0));
final ITopLevelElement topLevel = IPersistencyService.INSTANCE
.getTopLevelElementFor(getEditedObject());
String vName = "v" + (getEditedObject().getDataStateVariablesList().size() + 1);
final DataStateVariable dsvar = createDataStateVariable(vName, intType(), intConst(0));
final ITopLevelElement topLevel =
IPersistencyService.INSTANCE.getTopLevelElementFor(getEditedObject());
topLevel.runAsCommand(new Runnable() {
@Override
public void run() {
......@@ -200,14 +198,14 @@ public abstract class DataStateEditorBase<T extends IDataStateVariableProvider>
/** Removes the selected variable from the specification. */
private void removeSelectedVariable() {
final DataStateVariable dsv = checkAndPickFirstSafe(
viewer.getSelection(), DataStateVariable.class);
if (dsv == null) {
final DataStateVariable dsv =
checkAndPickFirstSafe(viewer.getSelection(), DataStateVariable.class);
if(dsv == null) {
return;
}
final ITopLevelElement topLevel = IPersistencyService.INSTANCE
.getTopLevelElementFor(getEditedObject());
final ITopLevelElement topLevel =
IPersistencyService.INSTANCE.getTopLevelElementFor(getEditedObject());
topLevel.runAsCommand(new Runnable() {
@Override
public void run() {
......@@ -219,8 +217,7 @@ public abstract class DataStateEditorBase<T extends IDataStateVariableProvider>
/** Registers model listeners. */
private void registerAtModel() {
getEditedObject().eAdapters().add(changeListener);
for (DataStateVariable dsv : getEditedObject()
.getDataStateVariablesList()) {
for(DataStateVariable dsv : getEditedObject().getDataStateVariablesList()) {
dsv.eAdapters().add(changeListener);
}
}
......@@ -228,8 +225,7 @@ public abstract class DataStateEditorBase<T extends IDataStateVariableProvider>
/** {@inheritDoc} */
@Override
public void dispose() {
for (DataStateVariable dsv : getEditedObject()
.getDataStateVariablesList()) {
for(DataStateVariable dsv : getEditedObject().getDataStateVariablesList()) {
dsv.eAdapters().remove(changeListener);
}
getEditedObject().eAdapters().remove(changeListener);
......@@ -240,17 +236,16 @@ public abstract class DataStateEditorBase<T extends IDataStateVariableProvider>
private final Adapter changeListener = new AdapterImpl() {
@Override
public void notifyChanged(Notification notification) {
if (notification.getNewValue() instanceof DataStateVariable) {
DataStateVariable dsv = (DataStateVariable) notification
.getNewValue();
if(notification.getNewValue() instanceof DataStateVariable) {
DataStateVariable dsv = (DataStateVariable)notification.getNewValue();
if (notification.getEventType() == Notification.ADD) {
if(notification.getEventType() == Notification.ADD) {
dsv.eAdapters().add(changeListener);
} else if (notification.getEventType() == Notification.REMOVE) {
} else if(notification.getEventType() == Notification.REMOVE) {
dsv.eAdapters().remove(changeListener);
}
}
if (!viewer.getTable().isDisposed()) {
if(!viewer.getTable().isDisposed()) {
viewer.refresh();
}
}
......
......@@ -52,6 +52,9 @@ public class INamedColumnLabelProvider extends ColumnLabelProvider {
@Override
public Image getImage(Object element) {
element = adapt(element);
if(element == null) {
return null;
}
if(IModelElementHandlerService.INSTANCE.getModelElementHandler((EObject)element) != null) {
return IModelElementHandlerService.INSTANCE.getModelElementHandler((EObject)element)
.getIcon();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment