20 package net.sf.gridarta.gui.dialog.errorview;
22 import java.awt.Component;
23 import java.awt.Dialog;
24 import java.awt.Dimension;
25 import java.lang.reflect.InvocationTargetException;
26 import java.util.EnumMap;
28 import java.util.concurrent.Semaphore;
29 import javax.swing.JButton;
30 import javax.swing.JOptionPane;
31 import javax.swing.JScrollPane;
32 import javax.swing.JTree;
33 import javax.swing.SwingUtilities;
34 import javax.swing.tree.DefaultMutableTreeNode;
35 import javax.swing.tree.DefaultTreeModel;
36 import javax.swing.tree.TreePath;
40 import net.
sf.japi.swing.action.ActionBuilder;
41 import net.
sf.japi.swing.action.ActionBuilderFactory;
42 import org.jetbrains.annotations.NotNull;
43 import org.jetbrains.annotations.Nullable;
55 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
61 private final DefaultTreeModel
treeModel =
new DefaultTreeModel(null);
117 treeModel.setRoot(treeRoot);
129 addEntry(categoryName, lineNo +
": " + message);
135 addEntry(categoryName,
"Warning: " + message);
140 addEntry(categoryName,
"Warning: line " + lineNo +
": " + message);
149 final Runnable runnable =
new Runnable() {
155 category.
add(errorEntry);
160 if (SwingUtilities.isEventDispatchThread()) {
164 SwingUtilities.invokeAndWait(runnable);
165 }
catch (
final InterruptedException ignored) {
166 Thread.currentThread().interrupt();
167 }
catch (
final InvocationTargetException ex) {
168 throw new RuntimeException(ex);
180 final ErrorEntry existingErrorEntry = categories.get(categoryName);
181 if (existingErrorEntry != null) {
182 return existingErrorEntry;
186 categories.put(categoryName, category);
187 treeRoot.
add(category);
204 if (dialog == null) {
217 final JTree tree =
new JTree(treeModel);
218 final JScrollPane scrollPane =
new JScrollPane(tree);
219 tree.setExpandsSelectedPaths(
true);
220 final TreePath path =
new TreePath(
new Object[] {
treeRoot, category, errorEntry, });
221 tree.setSelectionPath(path);
222 tree.scrollPathToVisible(path);
223 okButton =
new JButton(ACTION_BUILDER.createAction(
false,
"errorViewOk",
this));
224 final JOptionPane pane =
new JOptionPane(scrollPane, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null,
new Object[] { okButton, }, okButton) {
227 private static final long serialVersionUID = 1L;
230 public void setValue(@Nullable
final Object newValue) {
231 super.setValue(newValue);
232 if (newValue != UNINITIALIZED_VALUE) {
238 pane.setPreferredSize(
new Dimension(800, 600));
239 assert okButton != null;
240 okButton.setEnabled(
false);
242 pane.selectInitialValue();
243 assert dialog != null;
245 assert dialog != null;
246 dialog.setModal(
false);
247 assert dialog != null;
248 dialog.setVisible(
true);
254 final Runnable runnable =
new Runnable() {
258 assert okButton != null;
259 okButton.setEnabled(
true);
263 if (SwingUtilities.isEventDispatchThread()) {
267 SwingUtilities.invokeAndWait(runnable);
268 }
catch (
final InvocationTargetException ex) {
269 throw new RuntimeException(ex);
276 if (Thread.interrupted()) {
277 throw new InterruptedException();
286 if (dialog != null) {
303 return dialog != null;
final DefaultTreeModel treeModel
The DefaultTreeModel used for the error dialog.
final Map< ErrorViewCategory, ErrorEntry > categories
Maps category name to child node.
void add(@NotNull final MutableTreeNode newChild)
final DefaultMutableTreeNode treeRoot
The tree of defined objects.
void showDialogInt(@NotNull final ErrorEntry category, @NotNull final ErrorEntry errorEntry)
Shows a dialog showing the object tree.
void waitDialog()
Waits until the dialog has been dismissed.
Defines possible error categories for ErrorView instances.
ErrorEntry getCategory(@NotNull final ErrorViewCategory categoryName)
Returns the node for a category name.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Interface for classes displaying error messages.
Base package of all Gridarta classes.
void addEntry(final ErrorViewCategory categoryName, final String message)
Adds a text message.
boolean errors
Whether at least one error message has been added.
final Semaphore semaphore
The Semaphore used to wait for the dismissal of the error dialog.
void addWarning(@NotNull final ErrorViewCategory categoryName, final int lineNo, @NotNull final String message)
Adds a warning message.
An entry in a net.sf.gridarta.gui.dialog.errorview.DefaultErrorView.
boolean hasDialog()
Returns whether the dialog has been created.
void addWarning(@NotNull final ErrorViewCategory categoryName, @NotNull final String message)
Adds a warning message.
void addError(@NotNull final ErrorViewCategory categoryName, @NotNull final String message)
Adds an error message.
void errorViewOk()
Action method for "ok" button of error dialog.
final Object dialogSync
The synchronization object used to access dialog.
Utility class for ActionBuilder related functions.
void showDialog(@NotNull final ErrorEntry category, @NotNull final ErrorEntry errorEntry)
Shows a dialog showing the object tree.
void addError(@NotNull final ErrorViewCategory categoryName, final int lineNo, @NotNull final String message)
Adds an error message.
Dialog dialog
The dialog instance.
JButton okButton
The "ok" button of the error dialog.
boolean hasErrors()
Whether at least one error message has been added.
final Component parent
The parent component for showing the error dialog or.
A dialog displaying a tree of error messages.
static final ActionBuilder ACTION_BUILDER
Action Builder.
DefaultErrorView(@Nullable final Component parent)
Creates a new instance.