private IWorkbenchSite site;\r
private Button deleteExpression, newExpression;\r
private WidgetSupportImpl support;\r
+ private ExpressionComposite expressionComposite;\r
private final WidgetSupportImpl expressionSupport = new WidgetSupportImpl();\r
\r
@Override\r
GridDataFactory.fillDefaults().grab(true, false).align(SWT.END, SWT.FILL).applyTo(isOutput.getWidget());\r
\r
// The actual expression\r
- ExpressionComposite expressionComposite = new ExpressionComposite(composite, SWT.NONE);\r
+ expressionComposite = new ExpressionComposite(composite, SWT.NONE);\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(expressionComposite);\r
expressionWidget = new ExpressionWidget(expressionComposite, expressionSupport, SWT.NONE);\r
expressionWidget.setVariableTable(shortcutTabWidget.getVariableTable());\r
if(focusLostListener != null && site != null)\r
site.getPage().removePartListener(focusLostListener);\r
super.dispose();\r
+ if(expressionComposite != null && !expressionComposite.isDisposed())\r
+ expressionComposite.dispose();\r
}\r
\r
/**\r
*******************************************************************************/\r
package org.simantics.sysdyn.ui.properties.widgets.expressions;\r
\r
-import java.util.HashMap;\r
+import gnu.trove.THashMap;\r
\r
import org.eclipse.jface.text.source.ISharedTextColors;\r
import org.eclipse.swt.graphics.Color;\r
\r
public class ColorManager implements ISharedTextColors {\r
\r
- protected HashMap<RGB, Color> colorTable = new HashMap<RGB, Color>();\r
+ THashMap<RGB,Color> map = new THashMap<RGB,Color>();\r
\r
@Override\r
public void dispose() {\r
- for(Color c : colorTable.values())\r
+ for(Color c : map.values())\r
c.dispose();\r
- colorTable.clear();\r
+ map.clear();\r
}\r
\r
@Override\r
public Color getColor(RGB rgb) {\r
- Color color = colorTable.get(rgb);\r
+ Color color = map.get(rgb);\r
if (color == null) {\r
color = new Color(Display.getCurrent(), rgb);\r
- colorTable.put(rgb, color);\r
+ map.put(rgb, color);\r
}\r
return color;\r
\r
\r
import org.eclipse.jface.layout.GridDataFactory;\r
import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.resource.JFaceResources;\r
+import org.eclipse.jface.resource.LocalResourceManager;\r
import org.eclipse.jface.text.Document;\r
import org.eclipse.jface.text.IDocument;\r
import org.eclipse.jface.text.PaintManager;\r
import org.eclipse.swt.graphics.Point;\r
import org.eclipse.swt.graphics.RGB;\r
import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Display;\r
import org.eclipse.swt.widgets.Table;\r
import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;\r
import org.simantics.sysdyn.ui.utils.SyntaxError;\r
\r
String oldExpression;\r
\r
- ColorManager cManager = new ColorManager();\r
-\r
IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();\r
\r
ExpressionFieldConfiguration expressionFieldConfiguration;\r
\r
+ private final LocalResourceManager resourceManager;\r
+ private final RGB warningRGB = new RGB(255,215,0);\r
+ private final RGB errorRGB = new RGB(255,0,0);\r
+\r
/**\r
* Create a new expression field\r
* @param parent\r
public ExpressionField(Composite parent, int style, Table allowedVariables, boolean allowFunctions) {\r
super(parent, style);\r
\r
+ // Create a ResourceManager to dispose images when the widget is disposed.\r
+ this.resourceManager = new LocalResourceManager(JFaceResources.getResources(), this);\r
+ \r
GridLayoutFactory.fillDefaults().applyTo(this);\r
\r
int styles = SWT.V_SCROLL\r
styles);\r
\r
// Configuration for color management\r
- expressionFieldConfiguration = new ExpressionFieldConfiguration(cManager, allowedVariables, allowFunctions);\r
+ expressionFieldConfiguration = new ExpressionFieldConfiguration(\r
+ new LocalResourceManager(JFaceResources.getResources(), _sourceViewer.getControl()), \r
+ allowedVariables, allowFunctions);\r
_sourceViewer.configure(expressionFieldConfiguration);\r
AnnotationPainter painter = new AnnotationPainter(_sourceViewer, annotationAccess);\r
_sourceViewer.addPainter(painter);\r
\r
// Annotation types\r
+ Color warningColor = resourceManager.createColor(warningRGB);\r
+ Color errorColor = resourceManager.createColor(errorRGB);\r
painter.addAnnotationType(MISSING_LINK);\r
- painter.setAnnotationTypeColor(MISSING_LINK, new Color(this.getDisplay(), 255,215,0));\r
+ painter.setAnnotationTypeColor(MISSING_LINK, warningColor);\r
painter.addAnnotationType(NO_SUCH_VARIABLE);\r
- painter.setAnnotationTypeColor(NO_SUCH_VARIABLE, new Color(this.getDisplay(), 255,0,0));\r
+ painter.setAnnotationTypeColor(NO_SUCH_VARIABLE, errorColor);\r
painter.addAnnotationType(SYNTAX_ERROR);\r
- painter.setAnnotationTypeColor(SYNTAX_ERROR, new Color(this.getDisplay(), 255,0,0)); \r
+ painter.setAnnotationTypeColor(SYNTAX_ERROR, errorColor); \r
painter.addAnnotationType(SYNTAX_WARNING);\r
- painter.setAnnotationTypeColor(SYNTAX_WARNING, new Color(this.getDisplay(), 255,215,0));\r
+ painter.setAnnotationTypeColor(SYNTAX_WARNING, warningColor);\r
\r
_sourceViewer.setDocument(_document, _annotationModel);\r
\r
PaintManager paintManager = new PaintManager(_sourceViewer);\r
MatchingCharacterPainter matchingCharacterPainter = new MatchingCharacterPainter(_sourceViewer,\r
new DefaultCharacterPairMatcher( new char[] {'(', ')', '{', '}', '[', ']'} ));\r
- matchingCharacterPainter.setColor(new Color(Display.getCurrent(), new RGB(160, 160, 160)));\r
+ matchingCharacterPainter.setColor(resourceManager.createColor(new RGB(160, 160, 160)));\r
paintManager.addPainter(matchingCharacterPainter);\r
\r
\r
package org.simantics.sysdyn.ui.properties.widgets.expressions;\r
\r
import org.eclipse.jface.internal.text.html.HTMLTextPresenter;\r
+import org.eclipse.jface.resource.ResourceManager;\r
import org.eclipse.jface.text.DefaultInformationControl;\r
import org.eclipse.jface.text.DefaultTextHover;\r
import org.eclipse.jface.text.IDocument;\r
\r
private final long WAIT_BEFORE_STATUS_CHANGE = 100;\r
\r
- ColorManager colorManager;\r
Table allowedVariables;\r
boolean allowFunctions;\r
boolean assistSessionActive; \r
CompletionProcessor completionProcessor;\r
+ ResourceManager resourceManager;\r
+\r
\r
- public ExpressionFieldConfiguration(ColorManager colorManager, Table allowedVariables, boolean allowFunctions) {\r
+ public ExpressionFieldConfiguration(ResourceManager resourceManager, Table allowedVariables, boolean allowFunctions) {\r
super();\r
- this.colorManager = colorManager;\r
+ this.resourceManager = resourceManager;\r
this.allowedVariables = allowedVariables;\r
this.allowFunctions = allowFunctions;\r
this.assistSessionActive = false;\r
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {\r
PresentationReconciler reconciler = new PresentationReconciler();\r
\r
- DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getSclTokenScanner());\r
+ DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getTokenScanner());\r
\r
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);\r
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);\r
}\r
\r
\r
- ITokenScanner getSclTokenScanner() {\r
+ ITokenScanner getTokenScanner() {\r
RuleBasedScanner scanner = new RuleBasedScanner();\r
\r
final Token reserved = new Token(\r
new TextAttribute(\r
- colorManager.getColor(new RGB(127, 0, 85)),\r
+ resourceManager.createColor(new RGB(127, 0, 85)),\r
null,\r
SWT.BOLD\r
));\r
- final Token defaultToken = new Token(new TextAttribute(colorManager.getColor(new RGB(0, 0, 0))));\r
+ final Token defaultToken = new Token(new TextAttribute(resourceManager.createColor(new RGB(0, 0, 0))));\r
\r
- final Token comment = new Token(new TextAttribute(colorManager.getColor(new RGB(63, 127, 95))));\r
+ final Token comment = new Token(new TextAttribute(resourceManager.createColor(new RGB(63, 127, 95))));\r
\r
\r
WordRule reservedWord = new WordRule(new IWordDetector() { \r