Revision 46068 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/evalexpression/EvaluateExpressionPanel.java

View differences:

EvaluateExpressionPanel.java
11 11
import javax.swing.JEditorPane;
12 12
import javax.swing.JLabel;
13 13
import javax.swing.JPanel;
14
import javax.swing.SwingUtilities;
14 15
import org.gvsig.andami.ui.mdiManager.IWindow;
15 16
import org.gvsig.app.ApplicationLocator;
16 17
import org.gvsig.app.ApplicationManager;
......
126 127
        private final ViewPortListener viewPortListener;
127 128
        private final MutableSymbolTable symbolTable;
128 129
        private final ActionListenerSupport actionListener;
130
		private boolean isProcessing;
131
		private Thread lastUpdate = null;
129 132
        
130 133
        public MyPanel(ActionListenerSupport actionListener, MutableSymbolTable symbolTable, Expression expression, String contentType) {
131 134
            this.actionListener = actionListener;
......
133 136
            this.symbolTable = symbolTable;
134 137
            this.expression = expression;
135 138
            this.contentType = contentType;
139
			this.isProcessing = false;
136 140
            this.actionListener.addActionListener(new ActionListener() {
137 141
                @Override
138 142
                public void actionPerformed(ActionEvent e) {
......
176 180
            });
177 181
        }
178 182
        
179
        private void doUpdate() {
180
            Object value;
181
            try {
182
                value = this.expression.execute(this.symbolTable);
183
            } catch(Throwable th) {
184
                LOGGER.warn("",th);
185
                return; //???
186
            }
187
            this.setValue(value);
183
        private synchronized void doUpdate() {
184
			Thread th = new Thread(() -> {
185
				isProcessing = true;
186
				Object value = null;
187
				
188
				try {
189
					value = this.expression.execute(this.symbolTable);
190
				} catch (Throwable tt) {
191
					LOGGER.warn("", tt);
192
					return; //???
193
				}
194
				this.setValue(value);
195
				if(lastUpdate!=null) {
196
					lastUpdate.start();
197
					lastUpdate = null;
198
				} else {
199
					isProcessing = false;
200
				}
201
			});
202
			if (isProcessing==true) {
203
				lastUpdate = th;
204
				return;
205
			}
206
			th.start();
207

  
188 208
        }
189 209
        
190 210
        public void setValue(Object value) {
211
			if (!SwingUtilities.isEventDispatchThread()) {
212
				Object v = value;
213
				SwingUtilities.invokeLater(() -> {
214
					setValue(v);
215
				});
216
				return;
217
			}
191 218
            if( value == null ) {
192 219
                this.removeAll();
193 220
                this.revalidate();
......
217 244
            this.setLayout(new BorderLayout());
218 245
            this.add(component);
219 246
            this.revalidate();
247
			
220 248
        }
221 249
        
222 250
        public void setWindow(IWindow window) {

Also available in: Unified diff