import org.simantics.db.common.request.UniqueRead;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.request.combinations.Combinators;
-import org.simantics.db.request.Read;
import org.simantics.layer0.Layer0;
import org.simantics.scl.ui.editor.SCLSourceViewerConfigurationNew;
import org.simantics.structural.stubs.StructuralResource2;
import org.simantics.ui.workbench.IResourceEditorInput;
import org.simantics.ui.workbench.TitleUpdater;
import org.simantics.ui.workbench.ToolTipRequest;
+import org.simantics.utils.ui.ExceptionUtils;
/**
* @author Hannu Niemistö
*/
public class ComponentTypeScriptEditor extends SCLModuleEditor {
+ protected ComponentTypeScriptDocumentProvider docProvider;
+ protected String scriptType = "";
+ protected int scriptTypeIndex = 0;
+
public ComponentTypeScriptEditor() {
super();
}
@Override
protected void preInitialize() {
- setDocumentProvider(new ComponentTypeScriptDocumentProvider(this));
+ docProvider = new ComponentTypeScriptDocumentProvider(this);
+ setDocumentProvider(docProvider);
SCLSourceViewerConfigurationNew sourceViewerConfiguration = new SCLSourceViewerConfigurationNew(resourceManager);
setSourceViewerConfiguration(sourceViewerConfiguration);
-
}
protected ParametrizedRead<IResourceEditorInput, Boolean> getInputValidator() {
- return new ParametrizedRead<IResourceEditorInput, Boolean>() {
- @Override
- public Read<Boolean> get(IResourceEditorInput parameter) {
- return Combinators.constant(Boolean.TRUE);
- }
- };
+ // No-op validator that always returns true
+ return param -> Combinators.constant(Boolean.TRUE);
}
@Override
"analogAutomation", //$NON-NLS-1$
"binaryAutomation", //$NON-NLS-1$
"preparation", //$NON-NLS-1$
- "post-preparation" //$NON-NLS-1$
+ "post-preparation", //$NON-NLS-1$
+ "cleanup", //$NON-NLS-1$
};
private static final String[] EXECUTION_PHASE_LABELS = new String[] {
Messages.ComponentTypeScriptEditor_ExecuteAnalogAutomation,
Messages.ComponentTypeScriptEditor_ExecuteBinaryAutomation,
Messages.ComponentTypeScriptEditor_ExecuteBeforePreparation,
- Messages.ComponentTypeScriptEditor_ExecuteAfterPreparation
+ Messages.ComponentTypeScriptEditor_ExecuteAfterPreparation,
+ Messages.ComponentTypeScriptEditor_ExecuteBeforeRemoval,
};
@Override
@Override
public void run(ReadGraph graph) throws DatabaseException {
StructuralResource2 STR = StructuralResource2.getInstance(graph);
- final String type = graph.getPossibleRelatedValue(script, STR.ComponentTypeScript_type);
+ String type = graph.getPossibleRelatedValue(script, STR.ComponentTypeScript_type);
if(type != null)
+ scriptType = type;
combo.getDisplay().asyncExec(() -> {
for(int i=0;i<EXECUTION_PHASES.length;++i)
if(EXECUTION_PHASES[i].equals(type)) {
combo.select(i);
+ scriptTypeIndex = i;
return;
}
});
}
combo.addSelectionListener(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter(e -> {
int id = combo.getSelectionIndex();
+ if (id == scriptTypeIndex)
+ return;
+ if (docProvider.isReadOnly(getEditorInput())) {
+ // Return configured selection
+ combo.select(scriptTypeIndex);
+ return;
+ }
+ String newType = EXECUTION_PHASES[id];
Simantics.getSession().asyncRequest((WriteGraph graph) -> {
StructuralResource2 STR = StructuralResource2.getInstance(graph);
String currentType = graph.getPossibleRelatedValue(script, STR.ComponentTypeScript_type);
- String newType = EXECUTION_PHASES[id];
if(!newType.equals(currentType))
graph.claimLiteral(script, STR.ComponentTypeScript_type, newType, Bindings.STRING);
+ }, exc -> {
+ if (exc == null) {
+ scriptType = newType;
+ scriptTypeIndex = id;
+ } else {
+ ExceptionUtils.logError(exc);
+ }
});
}));
GridDataFactory.fillDefaults().grab(true, false).applyTo(combo);