Revision 44855 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/java/org/gvsig/expressionevaluator/swing/impl/AbstractAutomaticExpressionChecker.java
AbstractAutomaticExpressionChecker.java | ||
---|---|---|
6 | 6 |
import java.awt.event.ActionListener; |
7 | 7 |
import java.awt.event.KeyAdapter; |
8 | 8 |
import java.awt.event.KeyEvent; |
9 |
import java.util.Collection; |
|
9 | 10 |
import java.util.Objects; |
11 |
import javax.swing.Action; |
|
12 |
import javax.swing.JComponent; |
|
10 | 13 |
import javax.swing.JEditorPane; |
11 | 14 |
import javax.swing.JMenuItem; |
12 | 15 |
import javax.swing.JOptionPane; |
... | ... | |
19 | 22 |
import org.apache.commons.lang3.StringUtils; |
20 | 23 |
import org.apache.commons.lang3.mutable.Mutable; |
21 | 24 |
import org.apache.commons.lang3.mutable.MutableObject; |
25 |
import org.gvsig.configurableactions.ConfigurableActionsMamager; |
|
22 | 26 |
import org.gvsig.expressionevaluator.Code; |
23 | 27 |
import org.gvsig.expressionevaluator.Code.Identifier; |
24 | 28 |
import org.gvsig.expressionevaluator.Expression; |
... | ... | |
40 | 44 |
import org.gvsig.tools.visitor.VisitCanceledException; |
41 | 45 |
import org.gvsig.tools.visitor.Visitor; |
42 | 46 |
import org.gvsig.expressionevaluator.Code.Callable; |
47 |
import static org.gvsig.expressionevaluator.swing.JExpressionBuilder.CONFIGURABLE_PANEL_ID; |
|
48 |
import org.gvsig.tools.util.ToolsUtilLocator; |
|
43 | 49 |
|
44 | 50 |
/** |
45 | 51 |
* |
... | ... | |
49 | 55 |
public abstract class AbstractAutomaticExpressionChecker { |
50 | 56 |
|
51 | 57 |
private static final Color COLOR_ERROR = new Color(255,225,232); |
58 |
private static final Color COLOR_SUGGESTION = new Color(255,255,159); |
|
52 | 59 |
|
53 | 60 |
private final JTextComponent text; |
54 | 61 |
private final ExpressionBuilderConfig builderConfig; |
... | ... | |
85 | 92 |
JPopupMenu popupMenu = this.text.getComponentPopupMenu(); |
86 | 93 |
|
87 | 94 |
this.menuItemShowTip = new JMenuItem(i18n.getTranslation("_Show_tip")); |
88 |
this.menuItemShowTip.addActionListener(new ActionListener() { |
|
89 |
@Override |
|
90 |
public void actionPerformed(ActionEvent e) { |
|
91 |
if( StringUtils.isBlank(tip) ) { |
|
92 |
return; |
|
93 |
} |
|
94 |
JOptionPane.showMessageDialog( |
|
95 |
text.getParent(), |
|
96 |
tip, |
|
97 |
i18n.getTranslation("Tip"), |
|
98 |
JOptionPane.INFORMATION_MESSAGE |
|
99 |
); |
|
100 |
} |
|
95 |
this.menuItemShowTip.addActionListener((ActionEvent e) -> { |
|
96 |
if( StringUtils.isBlank(tip) ) { |
|
97 |
return; |
|
98 |
} |
|
99 |
JOptionPane.showMessageDialog( |
|
100 |
text.getParent(), |
|
101 |
toHTML(tip), |
|
102 |
i18n.getTranslation("Tip"), |
|
103 |
JOptionPane.INFORMATION_MESSAGE |
|
104 |
); |
|
101 | 105 |
}); |
102 | 106 |
popupMenu.add(this.menuItemShowTip); |
103 | 107 |
|
104 | 108 |
this.menuItemShowPreview = new JMenuItem(i18n.getTranslation("_Show_preview")); |
105 |
this.menuItemShowPreview.addActionListener(new ActionListener() { |
|
106 |
@Override |
|
107 |
public void actionPerformed(ActionEvent e) { |
|
108 |
showMessageDialog( |
|
109 |
i18n.getTranslation("_Preview_value"), |
|
110 |
preview |
|
111 |
); |
|
112 |
} |
|
109 |
this.menuItemShowPreview.addActionListener((ActionEvent e) -> { |
|
110 |
showMessageDialog(i18n.getTranslation("_Preview_value"),preview); |
|
113 | 111 |
}); |
114 | 112 |
popupMenu.add(this.menuItemShowPreview); |
115 | 113 |
|
116 | 114 |
this.menuItemShowMessage = new JMenuItem(i18n.getTranslation("_Show_message")); |
117 |
this.menuItemShowMessage.addActionListener(new ActionListener() { |
|
118 |
@Override |
|
119 |
public void actionPerformed(ActionEvent e) { |
|
120 |
showMessageDialog( |
|
121 |
i18n.getTranslation("_Message"), |
|
122 |
message |
|
123 |
); |
|
124 |
} |
|
115 |
this.menuItemShowMessage.addActionListener((ActionEvent e) -> { |
|
116 |
showMessageDialog(i18n.getTranslation("_Message"),message+"\n\n"+tip); |
|
125 | 117 |
}); |
126 | 118 |
popupMenu.add(this.menuItemShowMessage); |
119 |
|
|
120 |
ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager(); |
|
121 |
Collection<Action> actions = cfgActionsManager.getConfigurableActions(CONFIGURABLE_PANEL_ID); |
|
122 |
if( !actions.isEmpty() ) { |
|
123 |
popupMenu.addSeparator(); |
|
124 |
for( Action action : actions) { |
|
125 |
JMenuItem item = new JMenuItem(action); |
|
126 |
item.addActionListener((ActionEvent e) -> { |
|
127 |
e.setSource(this); |
|
128 |
action.actionPerformed(e); |
|
129 |
}); |
|
130 |
popupMenu.add(item); |
|
131 |
} |
|
132 |
} |
|
127 | 133 |
|
128 |
this.timelistener = new ActionListener() { |
|
129 |
@Override |
|
130 |
public void actionPerformed(ActionEvent e) { |
|
131 |
doCheckExpression(); |
|
132 |
} |
|
134 |
this.timelistener = (ActionEvent e) -> { |
|
135 |
doCheckExpression(); |
|
133 | 136 |
}; |
134 | 137 |
this.doclistener = new DocumentListener() { |
135 | 138 |
@Override |
... | ... | |
233 | 236 |
} catch (BaseException ex) { |
234 | 237 |
} |
235 | 238 |
} |
239 |
String suggestion = this.getSuggestion(); |
|
240 |
if( suggestion!=null ) { |
|
241 |
if( StringUtils.isBlank(theTip.getValue()) ) { |
|
242 |
theTip.setValue(suggestion); |
|
243 |
} else { |
|
244 |
theTip.setValue(suggestion+"\n\n"+theTip.getValue()); |
|
245 |
} |
|
246 |
} |
|
236 | 247 |
if( !StringUtils.isBlank(theTip.getValue()) ) { |
237 | 248 |
this.setTip(theTip.getValue()); |
249 |
if( this.text.getBackground()==this.color_ok ) { |
|
250 |
this.text.setBackground(COLOR_SUGGESTION); |
|
251 |
} |
|
252 |
// this.setMessage(JOptionPane.INFORMATION_MESSAGE, theTip.getValue()); |
|
238 | 253 |
} |
239 | 254 |
} |
240 | 255 |
|
... | ... | |
286 | 301 |
scroll.setPreferredSize(new Dimension(500, 300)); |
287 | 302 |
toolsSwingManager.setDefaultPopupMenu(textMessage); |
288 | 303 |
textMessage.setContentType("text/html"); |
289 |
textMessage.setText("<html>"+msg+"</html>");
|
|
304 |
textMessage.setText(toHTML(msg));
|
|
290 | 305 |
textMessage.setCaretPosition(0); |
291 | 306 |
WindowManager_v2 winmgr = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
292 | 307 |
Dialog dialog = winmgr.createDialog( |
... | ... | |
301 | 316 |
protected void setPreview(Object value) { |
302 | 317 |
this.preview = Objects.toString(value, null); |
303 | 318 |
this.text.setToolTipText( |
304 |
"<html>" + |
|
305 |
StringUtils.abbreviate(Objects.toString(this.preview,""),100) + |
|
306 |
"</html>" |
|
319 |
toHTML(StringUtils.abbreviate(Objects.toString(this.preview,""),100)) |
|
307 | 320 |
); |
308 | 321 |
this.menuItemShowPreview.setEnabled(this.isPreviewEnabled()); |
309 | 322 |
this.text.setBackground(color_ok); |
310 | 323 |
} |
311 | 324 |
|
312 | 325 |
protected void setMessage(int mode, String text) { |
313 |
this.message = text; |
|
314 | 326 |
if( StringUtils.isBlank(text) ) { |
327 |
this.message = ""; |
|
315 | 328 |
this.text.setToolTipText(""); |
316 | 329 |
this.menuItemShowMessage.setEnabled(false); |
317 |
} else {
|
|
318 |
this.text.setToolTipText(
|
|
319 |
"<html>" +
|
|
320 |
StringUtils.abbreviate(Objects.toString(text,""),100) +
|
|
321 |
"</html>"
|
|
322 |
);
|
|
323 |
this.menuItemShowMessage.setEnabled(true);
|
|
324 |
}
|
|
330 |
this.text.setBackground(color_ok);
|
|
331 |
return;
|
|
332 |
}
|
|
333 |
this.message = text;
|
|
334 |
this.text.setToolTipText(
|
|
335 |
toHTML(StringUtils.abbreviate(Objects.toString(text,""),100))
|
|
336 |
); |
|
337 |
this.menuItemShowMessage.setEnabled(true);
|
|
325 | 338 |
switch (mode) { |
326 | 339 |
case JOptionPane.INFORMATION_MESSAGE: |
327 |
this.text.setBackground(color_ok);
|
|
340 |
this.text.setBackground(COLOR_SUGGESTION);
|
|
328 | 341 |
break; |
329 | 342 |
case JOptionPane.WARNING_MESSAGE: |
330 | 343 |
case JOptionPane.ERROR_MESSAGE: |
... | ... | |
340 | 353 |
} |
341 | 354 |
|
342 | 355 |
protected abstract Expression getExpression(); |
356 |
|
|
357 |
protected abstract String getSuggestion(); |
|
358 |
|
|
359 |
protected String toHTML(String s) { |
|
360 |
s = StringUtils.replace(s, "<html>", ""); |
|
361 |
s = StringUtils.replace(s, "</html>", ""); |
|
362 |
s = StringUtils.replace(s, "\n", "<br>"); |
|
363 |
s = "<html>"+s+"</html>"; |
|
364 |
return s; |
|
365 |
} |
|
343 | 366 |
} |
Also available in: Unified diff