001package com.ganteater.ae.desktop.editor;
002
003import java.awt.BorderLayout;
004import java.awt.CardLayout;
005import java.awt.Color;
006import java.awt.Component;
007import java.awt.Desktop;
008import java.awt.Dimension;
009import java.awt.FileDialog;
010import java.awt.Font;
011import java.awt.Point;
012import java.awt.Toolkit;
013import java.awt.event.ActionEvent;
014import java.awt.event.ActionListener;
015import java.awt.event.ComponentAdapter;
016import java.awt.event.ComponentEvent;
017import java.awt.event.KeyAdapter;
018import java.awt.event.KeyEvent;
019import java.awt.event.MouseAdapter;
020import java.awt.event.MouseEvent;
021import java.io.File;
022import java.io.FileOutputStream;
023import java.io.IOException;
024import java.lang.reflect.Constructor;
025import java.lang.reflect.InvocationTargetException;
026import java.util.ArrayList;
027import java.util.HashMap;
028import java.util.Map;
029import java.util.Properties;
030import java.util.Set;
031import java.util.Vector;
032
033import javax.swing.BorderFactory;
034import javax.swing.JButton;
035import javax.swing.JCheckBox;
036import javax.swing.JComponent;
037import javax.swing.JLabel;
038import javax.swing.JMenu;
039import javax.swing.JMenuBar;
040import javax.swing.JMenuItem;
041import javax.swing.JOptionPane;
042import javax.swing.JPanel;
043import javax.swing.JScrollPane;
044import javax.swing.JSeparator;
045import javax.swing.JSlider;
046import javax.swing.JSplitPane;
047import javax.swing.JTabbedPane;
048import javax.swing.JToolBar;
049import javax.swing.JTree;
050import javax.swing.JTree.DynamicUtilTreeNode;
051import javax.swing.KeyStroke;
052import javax.swing.SwingConstants;
053import javax.swing.SwingUtilities;
054import javax.swing.plaf.basic.BasicTabbedPaneUI;
055import javax.swing.table.AbstractTableModel;
056import javax.swing.text.BadLocationException;
057import javax.swing.tree.DefaultMutableTreeNode;
058import javax.swing.tree.DefaultTreeModel;
059import javax.swing.tree.TreePath;
060import javax.swing.tree.TreeSelectionModel;
061
062import org.apache.commons.io.FilenameUtils;
063import org.apache.commons.lang.StringUtils;
064import org.apache.commons.lang.SystemUtils;
065import org.apache.commons.lang.exception.ExceptionUtils;
066
067import com.ganteater.ae.AEManager;
068import com.ganteater.ae.AEWorkspace;
069import com.ganteater.ae.CommandException;
070import com.ganteater.ae.ConfigurationException;
071import com.ganteater.ae.ILogger;
072import com.ganteater.ae.desktop.WorkPlace;
073import com.ganteater.ae.desktop.ui.AEFrame;
074import com.ganteater.ae.desktop.ui.Button;
075import com.ganteater.ae.desktop.ui.DialogPopupMenu;
076import com.ganteater.ae.desktop.ui.TaskPanel;
077import com.ganteater.ae.desktop.view.ListLogView;
078import com.ganteater.ae.desktop.view.LogView;
079import com.ganteater.ae.desktop.view.AbstractView;
080import com.ganteater.ae.processor.BaseProcessor;
081import com.ganteater.ae.processor.Processor;
082import com.ganteater.ae.util.xml.easyparser.EasyParser;
083import com.ganteater.ae.util.xml.easyparser.EasyUtils;
084import com.ganteater.ae.util.xml.easyparser.Node;
085import com.ganteater.ae.util.xml.easyparser.Node.TreeVector;
086
087/**
088 * @author victort
089 * @version 1.0, 29-Jul-2005
090 */
091public class TaskEditor extends WorkPlace {
092
093        public static final Font font = new Font("Monospaced", Font.PLAIN, 12);
094
095        public static final String EDITOR_STD_PACKAGE = "com.ganteater.ae.desktop.editor.";
096        private static final String ABOUT = "About";
097        private static final Color ACTIVE_COLOR = Color.GREEN.darker();
098
099        private static final String TASK_EDITOR = "Editor";
100        private static final String TASK_TREE = "Process";
101
102        private String fTaskFile;
103        private Vector<?> fTreeVector;
104        private Map<String, Object> fPresentationPanels = new HashMap<String, Object>();
105
106        private AEFrame frame;
107        private JTree taskTree;
108        private TextEditor fTaskText;
109        private TaskPanel taskPanel;
110
111        private JMenuItem fRunMenuItem = new JMenuItem("Run");
112        private JMenuItem fContinueMenuItem = new JMenuItem("Continue");
113        private JMenuItem fStopMenuItem = new JMenuItem("Stop");
114        private JMenuItem fPauseMenuItem = new JMenuItem("Pause");
115        private JButton fRunButton = new JButton("Run");
116        private JCheckBox notifyMeCheckBox = new JCheckBox();
117        private JMenuItem saveMenuItem;
118        private JSplitPane fOutputSplitPanel;
119        private JSlider speed = new JSlider(0, 100, 100);
120        private JLabel changedLabel = new JLabel("");
121
122        private JTabbedPane createEditorPanel;
123
124        private JLabel lblTitle = new JLabel();
125        private JTabbedPane tabbedPanel;
126
127        private JTabbedPane fOutputTabbedPane;
128
129        private boolean openIn;
130        private boolean editable = true;
131
132        private ArrayList<LogView> fLoggers = new ArrayList<LogView>();
133        private boolean isRunning;
134
135        private boolean restoreDividerRequired;
136
137        private static String directory;
138
139        public TaskEditor(AEFrame frame, Node aConfigNode, Map<String, Object> aSystemVariables) throws CommandException {
140                super(frame, aConfigNode, aSystemVariables);
141                this.frame = frame;
142
143                this.taskPanel = new TaskPanel(this);
144                taskPanel.addComponentListener(new ComponentAdapter() {
145                        @Override
146                        public void componentResized(ComponentEvent e) {
147                                if (taskPanel.getSize().width > AEFrame.MINIMUM_WIN_WIDTH) {
148                                        createEditorPanel.setVisible(true);
149                                        restoreDivider();
150                                } else {
151                                        createEditorPanel.setVisible(false);
152                                }
153                        }
154                });
155
156                fOutputTabbedPane = new JTabbedPane();
157                fOutputTabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
158                fOutputTabbedPane.setUI(new BasicTabbedPaneUI() {
159                        @Override
160                        protected int calculateTabAreaHeight(int tab_placement, int run_count, int max_tab_height) {
161                                int calculateTabAreaHeight = 0;
162                                if (fOutputTabbedPane.getTabCount() > 1) {
163                                        calculateTabAreaHeight = super.calculateTabAreaHeight(tab_placement, run_count, max_tab_height);
164                                }
165                                return calculateTabAreaHeight;
166                        }
167                });
168
169                fOutputTabbedPane.setPreferredSize(new Dimension(200, 800));
170                fOutputTabbedPane.addKeyListener(new KeyAdapter() {
171                        @Override
172                        public void keyReleased(KeyEvent e) {
173                                if (e.getKeyCode() == KeyEvent.VK_F4 && e.isControlDown()) {
174                                        removeActivePresentationPanel();
175                                }
176                        }
177                });
178
179                fOutputTabbedPane.addMouseListener(new MouseAdapter() {
180                        @Override
181                        public void mouseClicked(MouseEvent e) {
182                                JTabbedPane outputTabbedPane = (JTabbedPane) e.getSource();
183                                if (e.getButton() == MouseEvent.BUTTON2) {
184                                        if (outputTabbedPane.indexAtLocation(e.getX(), e.getY()) != -1) {
185                                                Component selectedComponent = outputTabbedPane.getSelectedComponent();
186                                                String id = ((AbstractView) selectedComponent).getName();
187                                                removeActivePresentationPanel();
188                                                fPresentationPanels.remove(id);
189                                        }
190                                }
191                                if (e.getButton() == MouseEvent.BUTTON3) {
192                                        if (outputTabbedPane.findComponentAt(e.getX(), e.getY()) == outputTabbedPane
193                                                        && outputTabbedPane.indexAtLocation(e.getX(), e.getY()) != -1) {
194
195                                                AbstractView selectedComponent = (AbstractView) outputTabbedPane
196                                                                .getSelectedComponent();
197
198                                                if (selectedComponent instanceof LogView
199                                                                && !((LogView) selectedComponent).isEmpty()) {
200                                                        if (fLoggers.contains(selectedComponent)) {
201                                                                String id = selectedComponent.getName();
202                                                                LogView findLogger = findLogger(id);
203                                                                LogView bakPresenter = findLogger.copyAndClean();
204                                                                outputTabbedPane.addTab(id, AEFrame.getIcon("copied.png"), bakPresenter);
205                                                        }
206                                                }
207                                        }
208                                }
209                        }
210                });
211
212                createEditorPanel = createEditorPanel();
213
214                fOutputSplitPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, createEditorPanel, fOutputTabbedPane);
215                fOutputSplitPanel.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, e -> {
216                        if (taskPanel.getSize().width > AEFrame.MINIMUM_WIN_WIDTH && !restoreDividerRequired) {
217                                int dividerLocation = fOutputSplitPanel.getDividerLocation();
218                                String divider = Integer.toString(dividerLocation);
219                                int selectedIndex = createEditorPanel.getSelectedIndex();
220                                AEWorkspace.getInstance().setDefaultUserConfiguration("splitPanel.divider." + selectedIndex, divider);
221                        }
222                });
223
224                setSplitPanel();
225
226                taskPanel.add(fOutputSplitPanel, BorderLayout.CENTER);
227                JMenuBar menuBar = new JMenuBar();
228
229                createFileMenu(menuBar);
230                createProcessMenu(menuBar);
231
232                Node taskNode = getTaskNode();
233                if (taskNode != null && taskNode.findNode(ABOUT, null, null) != null) {
234                        showAbout();
235                }
236
237                JToolBar panel2 = new JToolBar();
238                panel2.setBorderPainted(false);
239                panel2.setFloatable(false);
240
241                fRunButton.setBorder(BorderFactory.createEmptyBorder());
242                panel2.add(fRunButton);
243
244                notifyMeCheckBox.setBorder(BorderFactory.createEmptyBorder());
245                notifyMeCheckBox.setIcon(AEFrame.getIcon("shout-off.png"));
246                notifyMeCheckBox.setSelectedIcon(AEFrame.getIcon("shout.png"));
247                panel2.add(notifyMeCheckBox);
248
249                notifyMeCheckBox.addActionListener(e -> {
250                        if (getTaskName() != null) {
251                                String aName = getTaskName() + ".notifyMe";
252                                String value = Boolean.toString(notifyMeCheckBox.isSelected());
253                                AEWorkspace.getInstance().setDefaultUserConfiguration(aName, value);
254                                AEWorkspace.getInstance().setDefaultUserConfiguration("notifyMe", value);
255                        }
256                });
257
258                speed.setPreferredSize(new Dimension(30, 18));
259                speed.setToolTipText("Action speed");
260
261                speed.addChangeListener(e -> {
262                        String text;
263                        long traceDelay = getTraceDelay();
264                        if (traceDelay < 1000) {
265                                text = traceDelay + "ms.";
266                        } else {
267                                text = String.format("%.2f", traceDelay / 1000.0) + "s";
268                        }
269
270                        speed.setToolTipText("Delay: " + text);
271                        setMessage("Slow motion time: " + text);
272                });
273
274                JPanel panel = new JPanel(new BorderLayout(4, 4));
275                panel.setBorder(BorderFactory.createEtchedBorder());
276                panel.add(menuBar, BorderLayout.WEST);
277
278                JButton closeBtn = new Button("close.png");
279                closeBtn.setBorder(BorderFactory.createEmptyBorder());
280
281                closeBtn.addActionListener(e -> {
282                        stopTest();
283                        closeTab();
284                });
285                panel.add(closeBtn, BorderLayout.EAST);
286
287                taskPanel.add(panel, BorderLayout.NORTH);
288
289                JPanel aboutPanel = new JPanel(new BorderLayout(0, 0));
290                aboutButtonPanel.setBorderPainted(false);
291                aboutButtonPanel.setFloatable(false);
292                aboutPanel.add(panel2, BorderLayout.WEST);
293
294                JPanel titlePanel = new JPanel(new BorderLayout(0, 0));
295                titlePanel.add(aboutButtonPanel, BorderLayout.WEST);
296                titlePanel.add(fTitleTest, BorderLayout.CENTER);
297                aboutPanel.add(titlePanel, BorderLayout.CENTER);
298                panel.add(aboutPanel, BorderLayout.CENTER);
299        }
300
301        public void setSplitPanel() {
302                fOutputSplitPanel.setOneTouchExpandable(true);
303        }
304
305        private String getTaskName() {
306                String name = null;
307                if (getTaskNode() != null) {
308                        name = getTaskNode().getAttribute("name");
309                }
310                return name;
311        }
312
313        public TaskEditor(AEFrame aeFrame) throws CommandException {
314                this(aeFrame, aeFrame.getWorkspace().getConfigNode(), aeFrame.getWorkspace().getSystemVariables());
315                setRunButtonAction(true);
316        }
317
318        private void createFileMenu(JMenuBar menuBar) {
319                JMenu menu = new JMenu("File");
320
321                JMenuItem menuItem;
322                menuItem = new JMenuItem("Save");
323                try {
324                        menuItem.setAccelerator(KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
325                } catch (Exception e) {
326                }
327
328                this.saveMenuItem = menuItem;
329                menuItem.addActionListener(new ActionListener() {
330                        public void actionPerformed(ActionEvent arg0) {
331
332                                SwingUtilities.invokeLater(() -> {
333                                        try {
334                                                save();
335                                        } catch (IOException e) {
336                                                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
337                                                                "Error: Unable to Save File: " + fTaskFile);
338                                        }
339                                });
340                        }
341                });
342                menu.add(menuItem);
343
344                menuItem = new JMenuItem("Reload");
345                final JMenuItem reloadmenuItem = menuItem;
346                try {
347                        menuItem.setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
348                } catch (Exception e) {
349                }
350                menuItem.addActionListener(arg0 -> {
351                        reload();
352                });
353                menu.add(menuItem);
354
355                menuItem = new JMenuItem("Format");
356                try {
357                        menuItem.setAccelerator(KeyStroke.getKeyStroke('F', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
358                } catch (Exception e) {
359                }
360                menuItem.addActionListener(arg0 -> {
361                        format();
362                });
363                menu.add(menuItem);
364
365                menuItem = new JMenuItem("Open In");
366                try {
367                        menuItem.setAccelerator(KeyStroke.getKeyStroke('E', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
368                } catch (Exception e) {
369                }
370                menuItem.addActionListener(arg0 -> {
371                        File file;
372                        if (fTaskFile.startsWith("jar:file:")) {
373                                String pathname = fTaskFile.replaceFirst("jar:file:", "");
374                                pathname = StringUtils.substringBeforeLast(pathname, "!");
375                                file = new File(pathname);
376                        } else {
377                                file = new File(fTaskFile);
378                        }
379                        if (file.exists() || fTaskFile.startsWith("jar:file:")) {
380                                try {
381                                        Desktop.getDesktop().open(file);
382                                        openIn = true;
383                                        reloadmenuItem.setText("Reload [Before Run]");
384
385                                } catch (IOException e) {
386                                        getLogger().error(e.getMessage(), e);
387                                }
388                        }
389                });
390                menu.add(menuItem);
391
392                menu.add(new JSeparator());
393                menuItem = new JMenuItem("Close");
394                try {
395                        menuItem.setAccelerator(KeyStroke.getKeyStroke('X', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
396                } catch (Exception e) {
397                }
398                menuItem.addActionListener(e -> {
399                        closeTab();
400                });
401                menu.add(menuItem);
402                menuBar.add(menu);
403        }
404
405        public void reload() {
406                openTaskFile(fTaskFile);
407        }
408
409        public void save() throws IOException {
410                changedLabel.setText("");
411                format();
412                saveTask();
413        }
414
415        public void format() {
416                try {
417                        compileTask();
418                        refreshTaskTree();
419
420                        Node taskNode = getTaskNode();
421                        applyText(taskNode);
422
423                        if (taskNode != null && taskNode.findNode(ABOUT, null, null) != null) {
424                                showAbout();
425                        }
426
427                } catch (Exception e) {
428                        getLogger().error("Save action failed.", e);
429                }
430        }
431
432        private void createProcessMenu(JMenuBar menuBar) {
433                JMenu menu = new JMenu("Process");
434
435                JMenuItem compileMenuItem = new JMenuItem("Compile");
436                menu.add(compileMenuItem);
437                compileMenuItem.addActionListener(arg0 -> {
438                        try {
439                                compileTask();
440                        } catch (Exception e) {
441                                getLogger().error("Compilation failed.", e);
442                        }
443                });
444
445                menu.add(fRunMenuItem);
446
447                try {
448                        fRunMenuItem.setAccelerator(
449                                        KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
450                } catch (Exception e) {
451                }
452
453                fRunMenuItem.addActionListener(e -> {
454                        runTask();
455                });
456                menu.add(speed);
457
458                fRunButton.addActionListener(e -> {
459                        boolean isCurrentRunAction = "Run".equals(e.getActionCommand());
460
461                        if (isCurrentRunAction) {
462                                runTask();
463                        } else {
464                                stopTest();
465                                if (getTaskProcessor().isStoppedTest()) {
466                                        setRunButtonAction(true);
467                                }
468                        }
469                });
470
471                menu.add(fPauseMenuItem);
472
473                try {
474                        fPauseMenuItem
475                                        .setAccelerator(KeyStroke.getKeyStroke('P', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
476                } catch (Exception e) {
477                }
478
479                fPauseMenuItem.addActionListener(e -> {
480                        getTaskProcessor().pause();
481                });
482
483                menu.add(fContinueMenuItem);
484
485                try {
486                        fContinueMenuItem
487                                        .setAccelerator(KeyStroke.getKeyStroke('P', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
488                } catch (Exception e) {
489                }
490
491                fContinueMenuItem.addActionListener(arg0 -> getTaskProcessor().resume());
492
493                try {
494                        fStopMenuItem.setAccelerator(
495                                        KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
496                } catch (Exception e) {
497                }
498
499                fStopMenuItem.addActionListener(arg0 -> stopTask());
500                menu.add(fStopMenuItem);
501                menuBar.add(menu);
502        }
503
504        @Override
505        public void setProgress(String message, long aMaxTags, long aCurrTags, boolean aErrorState) {
506                manager.progressValue((int) (((double) aCurrTags / aMaxTags) * 100), 100, true);
507                setMessage(message);
508        }
509
510        private void setMessage(String message) {
511                fTitleTest.setText(message);
512                int width = fTitleTest.getSize().width;
513                int textWidth = message.length() * 8;
514                if (width < textWidth) {
515                        fTitleTest.setToolTipText(message);
516                } else {
517                        fTitleTest.setToolTipText(null);
518                }
519        }
520
521        public void stopTask() {
522                super.stopTest();
523        }
524
525        private JTabbedPane createEditorPanel() throws CommandException {
526                JTabbedPane editorPanel = new JTabbedPane();
527                editorPanel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
528
529                editorPanel.setTabPlacement(SwingConstants.TOP);
530
531                JScrollPane theScroll = new JScrollPane();
532                theScroll.getViewport().removeAll();
533                taskTree = new JTree();
534                taskTree.setRootVisible(false);
535                taskTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
536
537                taskTree.addMouseListener(new MouseAdapter() {
538                        @Override
539                        public void mousePressed(MouseEvent e) {
540                                if (e.getClickCount() == 2) {
541                                        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) taskTree
542                                                        .getLastSelectedPathComponent();
543                                        TreeVector userObject = (TreeVector) selectedNode.getUserObject();
544                                        Node node = userObject.getNode();
545
546                                        String tagName = node.getTag();
547                                        if ("Task".equals(tagName)) {
548                                                String name = node.getAttribute("name");
549                                                TaskEditor editTask;
550                                                try {
551                                                        editTask = getAeFrame().editTask(name);
552                                                        editTask.setRunButtonAction(true);
553                                                } catch (CommandException e1) {
554                                                        // TODO Auto-generated catch block
555                                                        e1.printStackTrace();
556                                                }
557                                        }
558                                }
559                        }
560                });
561
562                theScroll.getViewport().add(taskTree);
563
564                editorPanel.addTab(TASK_TREE, theScroll);
565
566                return editorPanel;
567        }
568
569        private void restoreDivider() {
570                if (!restoreDividerRequired) {
571                        this.restoreDividerRequired = true;
572                        new Thread(() -> {
573                                try {
574                                        Thread.sleep(200);
575                                } catch (InterruptedException e) {
576                                        // do nothing.
577                                }
578
579                                if (restoreDividerRequired) {
580                                        int selectedIndex = createEditorPanel.getSelectedIndex();
581                                        String divider = AEWorkspace.getInstance()
582                                                        .getDefaultUserConfiguration("splitPanel.divider." + selectedIndex, null);
583                                        if (divider != null) {
584                                                fOutputSplitPanel.setDividerLocation(Integer.parseInt(divider));
585                                        }
586
587                                        Component selectedComponent = createEditorPanel.getSelectedComponent();
588                                        if (selectedComponent instanceof VariableViewPanel) {
589                                                VariableViewPanel panel = (VariableViewPanel) selectedComponent;
590                                                panel.refreshData();
591                                        }
592                                        restoreDividerRequired = false;
593                                }
594                        }).start();
595                }
596        }
597
598        public void compileTask() {
599                try {
600                        String text = fTaskText.getText();
601                        Node object = new EasyParser().getObject(text);
602                        setTaskNode(object);
603
604                } catch (Exception e1) {
605                        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(), "Incorrect code!\nError: " + e1.getMessage());
606                        throw e1;
607                }
608        }
609
610        public void showPanel(JTabbedPane panel, String name) {
611                if (name == null) {
612                        name = getPanelName();
613                }
614                tabbedPanel = panel;
615                String tabNameId = Integer.toString(taskPanel.hashCode());
616                panel.addTab(tabNameId, taskPanel);
617                panel.setSelectedComponent(taskPanel);
618
619                JPanel pnlTab = new JPanel(new BorderLayout());
620                pnlTab.setOpaque(false);
621                pnlTab.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
622
623                setTitle(name);
624                lblTitle.addMouseListener(new MouseAdapter() {
625                        @Override
626                        public void mouseClicked(MouseEvent var1) {
627                                int index = tabbedPanel.indexOfTab(tabNameId);
628                                int button = var1.getButton();
629                                if (button == MouseEvent.BUTTON2) {
630                                        TaskEditor.this.frame.removeTab(TaskEditor.this);
631                                } else {
632                                        tabbedPanel.setSelectedIndex(index);
633                                }
634                        }
635                });
636
637                pnlTab.add(lblTitle, BorderLayout.CENTER);
638                pnlTab.add(changedLabel, BorderLayout.EAST);
639
640                int index = tabbedPanel.indexOfTab(tabNameId);
641                tabbedPanel.setTabComponentAt(index, pnlTab);
642        }
643
644        private void setTitle(String name) {
645                lblTitle.setText(StringUtils.abbreviate(name, 12));
646                lblTitle.setToolTipText(name);
647        }
648
649        public JPanel getMainPanel() {
650                return taskPanel;
651        }
652
653        @Override
654        public void endTask(boolean aErrorState) {
655                super.endTask(aErrorState);
656                fRunMenuItem.setEnabled(true);
657                setRunButtonAction(true);
658        }
659
660        private void openTaskFile(String filePath) {
661                fTaskFile = filePath;
662                if (new File(fTaskFile).exists() && !openIn) {
663                        setEditable(true);
664                }
665
666                try {
667                        Node node = new EasyParser().load(filePath);
668                        applyText(node);
669                        changedLabel.setText("");
670                } catch (Exception e1) {
671                        throw new ConfigurationException("Invalid recipe file.", e1);
672                }
673
674        }
675
676        private void applyText(Node node) {
677                setTaskNode(node);
678
679                int caretPosition = fTaskText.getCaretPosition();
680                EasyUtils.removeTagId(node);
681
682                fTaskText.setOriginalText(node.getXMLText());
683                if (caretPosition < fTaskText.getDocument().getLength()) {
684                        fTaskText.setCaretPosition(caretPosition);
685                }
686                refreshTaskTree();
687        }
688
689        private void createEditors(Node[] editors) {
690                for (Node editorNode : editors) {
691                        String className = editorNode.getAttribute("class");
692                        if (className == null) {
693                                className = TextEditor.class.getName();
694                        }
695                        Class<?> filterClass;
696                        try {
697                                if (!className.startsWith(EDITOR_STD_PACKAGE)) {
698                                        className = EDITOR_STD_PACKAGE + className;
699                                }
700
701                                filterClass = Class.forName(className);
702                                Constructor<?> constructor = filterClass.getConstructor();
703
704                                String name = editorNode.getAttribute("name");
705                                String tabName = StringUtils.defaultIfEmpty(name, StringUtils.substringAfterLast(className, "."));
706
707                                JComponent editor = (JComponent) constructor.newInstance();
708                                if (editor instanceof TextEditor) {
709                                        if (fTaskText == null) {
710                                                setEditor(editorNode, (TextEditor) editor);
711                                        }
712                                } else if (editor instanceof Editor) {
713                                        ((Editor) editor).setEditorNode(editorNode);
714                                        ((Editor) editor).init(this);
715                                        createEditorPanel.addTab(tabName, editor);
716                                }
717
718                        } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException
719                                        | IllegalAccessException | IllegalArgumentException | InvocationTargetException
720                                        | CommandException e) {
721                                e.printStackTrace();
722                                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
723                                                "The creation of the extended panel failed.\nError: " + ExceptionUtils.getRootCauseMessage(e));
724                        }
725                }
726
727                createEditorPanel.addChangeListener(e -> {
728                        restoreDivider();
729                });
730        }
731
732        private void setEditor(Node editorNode, TextEditor editor) {
733                ((TextEditor) editor).setEditorNode(editorNode);
734                JScrollPane scrollPane = new JScrollPane();
735                scrollPane.getViewport().add(editor);
736                editor.setEditable(editable);
737                createEditorPanel.insertTab(TASK_EDITOR, null, scrollPane, null, 1);
738                fTaskText = editor;
739        }
740
741        private void setEditable(boolean editable) {
742                this.editable = editable;
743                saveMenuItem.setEnabled(editable);
744                if (fTaskText != null) {
745                        fTaskText.setEditable(editable);
746                }
747        }
748
749        protected void refreshTaskTree() {
750                if (getTaskNode() != null) {
751                        fTreeVector = getTaskNode().getVector(true);
752
753                        DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
754                        DynamicUtilTreeNode.createChildren(root, fTreeVector);
755                        DefaultTreeModel model = new DefaultTreeModel(root, false);
756                        taskTree.setModel(model);
757
758                        taskTree.setEditable(false);
759                        taskTree.setEnabled(true);
760
761                        taskTree.setFont(font);
762                        taskTree.setForeground(ACTIVE_COLOR);
763                        for (int i = 0; i < taskTree.getRowCount(); i++) {
764                                taskTree.expandRow(i);
765                        }
766                }
767        }
768
769        @Override
770        public void changeVariable(String aAttribut, Object aValue) {
771        }
772
773        static class JBorderedPanel extends JPanel {
774                private static final long serialVersionUID = 1L;
775
776                public JBorderedPanel(Component aNorth, Component aWest, Component aCenter, Component aEast, Component aSouth) {
777                        setLayout(new BorderLayout());
778                        if (aNorth != null) {
779                                add(aNorth, BorderLayout.NORTH);
780                        }
781                        if (aWest != null) {
782                                add(aWest, BorderLayout.WEST);
783                        }
784                        if (aCenter != null) {
785                                add(aCenter, BorderLayout.CENTER);
786                        }
787                        if (aEast != null) {
788                                add(aEast, BorderLayout.EAST);
789                        }
790                        if (aSouth != null) {
791                                add(aSouth, BorderLayout.SOUTH);
792                        }
793                }
794        }
795
796        @Override
797        public void startCommand(int aNumberCommand) {
798                setRunButtonAction(false);
799                try {
800                        if (taskTree != null) {
801                                taskTree.setSelectionRow(aNumberCommand);
802                                long delay = getTraceDelay();
803                                if (delay > 0) {
804                                        try {
805                                                Thread.sleep(delay);
806                                        } catch (Exception e) {
807                                                Thread.currentThread().interrupt();
808                                        }
809                                }
810                        }
811                } catch (Exception e) {
812                        //
813                }
814        }
815
816        private long getTraceDelay() {
817                return (int) ((Math.pow(1.5, (double) (100 - speed.getValue()) / 4)) - 1);
818        }
819
820        @Override
821        public void aboutTest(String theTaskName, Node aCurrentAction) {
822                try {
823                        setAbout(theTaskName, aCurrentAction);
824                        aboutButtonPanel.setVisible(true);
825                } catch (Exception e) {
826                        getLogger().error("Error", e);
827                }
828        }
829
830        @Override
831        public void runCommandView(Properties params) {
832                String id = params.getProperty("name");
833                String title = params.getProperty("title");
834
835                String reuse = params.getProperty("reuse");
836                if ("true".equals(reuse)) {
837                        AbstractView thePPanel = (AbstractView) fPresentationPanels.get(id);
838                        if (thePPanel != null && thePPanel.isValid()) {
839                                return;
840                        }
841                }
842
843                createView(id, params, title);
844        }
845
846        private AbstractView createView(String name, Properties linkedMap, String title) {
847
848                if (title == null) {
849                        title = name;
850                }
851
852                String className = linkedMap.getProperty("type", "Text");
853
854                if (className.indexOf('.') < 0) {
855                        className = "com.ganteater.ae.desktop.view." + className;
856                }
857
858                Class<?> ppClass;
859                try {
860                        ppClass = Class.forName(className);
861                        Constructor<?> constructor = ppClass.getConstructor();
862                        AbstractView pPanel = (AbstractView) constructor.newInstance();
863                        pPanel.init(linkedMap, manager);
864
865                        fPresentationPanels.put(name, pPanel);
866                        fOutputTabbedPane.add(title, pPanel);
867
868                        fOutputTabbedPane.setSelectedComponent(pPanel);
869                        return pPanel;
870
871                } catch (Exception e) {
872                        throw new IllegalArgumentException(e);
873                }
874        }
875
876        @Override
877        public void outToView(Processor processor, Properties properties, Object value) {
878                String id = processor.replaceProperties((String) properties.get("view"));
879                if (id != null) {
880                        AbstractView panel = (AbstractView) fPresentationPanels.get(id);
881                        if (panel != null) {
882                                Properties params = panel.getParams();
883
884                                if (fOutputTabbedPane.getComponentZOrder(panel) < 0) {
885                                        fPresentationPanels.remove(id);
886                                        panel = null;
887                                }
888
889                                if (panel == null) {
890                                        createView(id, params, null);
891                                } else {
892                                        panel.out(value, properties);
893                                }
894                        }
895                }
896        }
897
898        public void removeActivePresentationPanel() {
899                int selectedIndex = fOutputTabbedPane.getSelectedIndex();
900
901                Component theComp = fOutputTabbedPane.getComponent(selectedIndex);
902                if (theComp instanceof AbstractView) {
903                        AbstractView thePPanel = (AbstractView) theComp;
904                        fPresentationPanels.remove(thePPanel.getName());
905                }
906
907                fOutputTabbedPane.remove(selectedIndex);
908                fLoggers.remove(findLogger(theComp));
909        }
910
911        int fNumberLog = 1;
912
913        public ILogger createLog(String aLogName, boolean mainLog) {
914
915                LogView loggPanel = findLogger(aLogName);
916
917                if (loggPanel == null) {
918                        if (aLogName == null || aLogName.length() == 0)
919                                aLogName = "Log #" + String.valueOf(fNumberLog++);
920                        loggPanel = new ListLogView(this, aLogName, mainLog);
921                        outputPaneAdd(loggPanel);
922                }
923
924                setLog(loggPanel);
925                return loggPanel;
926        }
927
928        public void setLog(ILogger log) {
929                super.setLog(log);
930        }
931
932        private LogView findLogger(String aLogName) {
933                if (aLogName == null && fLoggers.size() > 0) {
934                        return fLoggers.get(0);
935                }
936
937                int tabCount = fLoggers.size();
938                for (int i = 0; i < tabCount; i++) {
939                        LogView logger = (LogView) fLoggers.get(i);
940                        String name = logger.getName();
941                        if (name.equals(aLogName)) {
942                                return logger;
943                        }
944                }
945
946                return null;
947        }
948
949        private LogView findLogger(Component comp) {
950                int tabCount = fLoggers.size();
951                for (int i = 0; i < tabCount; i++) {
952                        LogView logger = (LogView) fLoggers.get(i);
953                        if (logger == comp) {
954                                return logger;
955                        }
956                }
957                return null;
958        }
959
960        @Override
961        public void errorInformation(Processor processor, Throwable exception, Node command) throws CommandException {
962                try {
963                        frame.errorInformation(processor, exception, command, notifyMeCheckBox.isSelected());
964                } catch (CommandException e) {
965                        throw e;
966                } catch (Throwable e) {
967                        throw new CommandException(e, processor, command);
968                }
969        }
970
971        class VarTableModel extends AbstractTableModel {
972                private static final long serialVersionUID = 1L;
973                private String[][] fRows;
974
975                public VarTableModel() throws Exception {
976                        Set<String> enumeration = getSystemVariables().keySet();
977                        fRows = new String[getSystemVariables().size()][2];
978                        int i = 0;
979                        for (String theName : enumeration) {
980                                String theValue = (String) getSystemVariables().get(theName);
981                                fRows[i][0] = theName;
982                                fRows[i][1] = theValue;
983                                i++;
984                        }
985                }
986
987                public int getColumnCount() {
988                        return 2;
989                }
990
991                public int getRowCount() {
992                        return getSystemVariables().size();
993                }
994
995                public Class<String> getColumnClass(int columnIndex) {
996                        return String.class;
997                }
998
999                public Object getValueAt(int row, int col) {
1000                        return fRows[row][col];
1001                }
1002
1003                public boolean isCellEditable(int rowIndex, int columnIndex) {
1004                        return columnIndex > 0;
1005                }
1006
1007                public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
1008                        if (columnIndex == 1) {
1009                                getSystemVariables().put(fRows[rowIndex][0], aValue);
1010                                fRows[rowIndex][1] = (String) aValue;
1011                        }
1012                }
1013
1014                public String getColumnName(int column) {
1015                        if (column == 0) {
1016                                return "Name";
1017                        } else {
1018                                return "Value";
1019                        }
1020                }
1021
1022        }
1023
1024        public void outputPaneAdd(LogView logPanel) {
1025                fLoggers.add(logPanel);
1026                LogView panel = logPanel;
1027                fOutputTabbedPane.add(logPanel.getName(), panel);
1028                fPresentationPanels.put(logPanel.getName(), logPanel);
1029                fOutputTabbedPane.setSelectedComponent(panel);
1030        }
1031
1032        @Override
1033        public void setActiveTest(String theActiveTest) throws CommandException {
1034                Node taskNode = getConfigNode();
1035                if (taskNode != null) {
1036                        Node[] editors = taskNode.getNodes(TASK_EDITOR);
1037                        createEditors(editors);
1038                }
1039                if (fTaskText == null) {
1040                        setEditor(null, new TextEditor());
1041                }
1042
1043                String fileName = manager.getTestPath(theActiveTest);
1044                if (fileName == null) {
1045                        throw new IllegalArgumentException("Task file is not found. Recipe: " + theActiveTest);
1046                }
1047
1048                setActiveTestFile(fileName);
1049                fTaskText.init(this);
1050
1051                taskNode = getTaskNode();
1052                if (taskNode != null) {
1053                        Node[] editors = taskNode.getNodes(TASK_EDITOR);
1054                        createEditors(editors);
1055                }
1056
1057        }
1058
1059        private void setActiveTestFile(String fileName) {
1060                openTaskFile(fileName);
1061                recipeFilePath = fileName;
1062
1063                boolean editable = new File(fTaskFile).exists();
1064
1065                setEditable(editable);
1066
1067                Node taskNode = getTaskNode();
1068                boolean c = taskNode != null && taskNode.findNode(ABOUT, null, null) != null;
1069                if (c) {
1070                        showAbout();
1071                }
1072
1073                restoreDivider();
1074        }
1075
1076        public void runTaskNode() {
1077                setRunButtonAction(false);
1078
1079                Thread thread = new Thread() {
1080                        public void run() {
1081                                try {
1082                                        runCode(false);
1083
1084                                } catch (Exception e) {
1085                                        e.printStackTrace();
1086                                } finally {
1087                                        setRunButtonAction(true);
1088                                }
1089                        }
1090                };
1091
1092                thread.start();
1093        }
1094
1095        public void runCode(boolean runSelectedCode) throws BadLocationException, CommandException {
1096
1097                File parentFile = SystemUtils.getUserDir();
1098                if (fTaskFile != null) {
1099                        parentFile = new File(fTaskFile).getParentFile();
1100                }
1101
1102                Processor processor;
1103                Node taskNode;
1104                Map<String, Object> hashtable;
1105
1106                if (!runSelectedCode) {
1107                        compileTask();
1108                        taskNode = getTaskNode();
1109                        processor = createProcessor();
1110                        hashtable = processor.startVariables;
1111
1112                } else {
1113                        String selectedText = fTaskText.getSelectedText();
1114                        if (StringUtils.isNotBlank(selectedText)) {
1115                                Node selectedNode = new EasyParser().getObject(selectedText);
1116                                boolean isValide = !"$Text".equals(selectedNode.getTag());
1117
1118                                if (!isValide) {
1119                                        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
1120                                                        "The selected code is invalid to run.");
1121                                        return;
1122                                }
1123                        }
1124
1125                        String code = fTaskText.getText(0, fTaskText.getSelectionStart());
1126                        code = StringUtils.substringAfterLast(code, "<Extern ");
1127                        if (!StringUtils.isEmpty(code)) {
1128                                code = "<Extern " + code;
1129                                selectedText = StringUtils.substringBefore(code, ">") + ">" + selectedText + "</Extern>";
1130                        }
1131
1132                        code = "<Task>" + selectedText + "</Task>";
1133                        taskNode = new EasyParser().getObject(code);
1134
1135                        processor = getTaskProcessor();
1136                        hashtable = processor.getVariables();
1137                }
1138                taskNode.getVector(true);
1139
1140                if (taskNode.size() > 0 && StringUtils.isNotBlank(taskNode.get(0).toString())) {
1141                        processor.processTesting(taskNode, hashtable, parentFile);
1142                } else {
1143                        fTaskText.select(fTaskText.getCaretPosition(), fTaskText.getCaretPosition());
1144                }
1145                processor.getListener().endTask(false);
1146                endTask(false);
1147                setRunButtonAction(true);
1148        }
1149
1150        private void runProcessTreeLine() {
1151                TreePath[] selectedPaths = taskTree.getSelectionPaths();
1152                if (createEditorPanel.getSelectedIndex() == 0 && selectedPaths != null) {
1153                        Processor processor = getTaskProcessor();
1154                        Node taskNode = new Node("Task");
1155                        setRunButtonAction(false);
1156                        for (TreePath path : selectedPaths) {
1157                                DefaultMutableTreeNode lastPathComponent = (DefaultMutableTreeNode) path.getLastPathComponent();
1158                                TreeVector userObject = (TreeVector) lastPathComponent.getUserObject();
1159                                Node node = userObject.getNode();
1160                                if ("Recipe".equals(node.getTag())) {
1161                                        taskNode = node;
1162                                        processor = createProcessor();
1163                                        Map<String, Object> hashtable = processor.startVariables;
1164                                } else {
1165                                        taskNode.add(node);
1166                                        processor = getTaskProcessor();
1167                                }
1168                        }
1169                }
1170        }
1171
1172        private Processor createProcessor() {
1173                String attribute = getTaskNode().getAttribute("name");
1174                if (attribute == null || attribute.isEmpty())
1175                        attribute = getTaskNode().getAttribute("description");
1176
1177                ILogger createLog = createLog(attribute, true);
1178                setProcessor(null);
1179                Processor processor = new BaseProcessor(getManager(), createLog, getManager().getStartDir());
1180                processor.init(fConfigNode, getSystemVariables(), this, getManager().getStartDir(), createLog);
1181                processor.setTestListener(this);
1182
1183                setProcessor(processor);
1184                return processor;
1185        }
1186
1187        public void start(String name) throws CommandException {
1188                if (StringUtils.isNotBlank(name)) {
1189                        setActiveTest(name);
1190                        runTaskNode();
1191                }
1192                fRunMenuItem.setEnabled(false);
1193        }
1194
1195        public void setRunButtonAction(boolean runAction) {
1196                this.isRunning = !runAction;
1197                if (runAction) {
1198                        try {
1199                                fRunButton.setText("Run");
1200                                fRunButton.setToolTipText("Run");
1201                                fContinueMenuItem.setEnabled(false);
1202                                fRunMenuItem.setEnabled(true);
1203                                fStopMenuItem.setEnabled(false);
1204                                fPauseMenuItem.setEnabled(false);
1205                                lblTitle.setBorder(BorderFactory.createEmptyBorder());
1206                        } catch (Exception e) {
1207                                e.printStackTrace();
1208                        }
1209
1210                } else {
1211                        try {
1212                                fRunButton.setText("Stop");
1213                                fRunButton.setToolTipText("Stop");
1214                                fContinueMenuItem.setEnabled(false);
1215                                fRunMenuItem.setEnabled(false);
1216                                fStopMenuItem.setEnabled(true);
1217                                fPauseMenuItem.setEnabled(true);
1218                                lblTitle.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, ACTIVE_COLOR));
1219                        } catch (Exception e) {
1220                                e.printStackTrace();
1221                        }
1222                }
1223        }
1224
1225        public void edit(String name) {
1226                ListLogView log = new ListLogView(this, name);
1227                setLog(log);
1228                outputPaneAdd(log);
1229                fRunMenuItem.setEnabled(true);
1230        }
1231
1232        public void create(String name) throws CommandException {
1233                ListLogView log = new ListLogView(this, name);
1234                setLog(log);
1235
1236                fRunMenuItem.setEnabled(true);
1237                Node node = new EasyParser().getObject("<Recipe name=\"" + name + "\">\n<!-- your recipe code -->\n</Recipe>");
1238
1239                Node confNode = getConfigNode();
1240                if (confNode != null) {
1241                        Node[] editors = confNode.getNodes(TASK_EDITOR);
1242                        createEditors(editors);
1243                }
1244
1245                if (fTaskText == null) {
1246                        setEditor(null, new TextEditor());
1247                }
1248
1249                applyText(node);
1250
1251                runTest(new Node[] { node });
1252                fContinueMenuItem.setEnabled(false);
1253                fTaskText.init(this);
1254        }
1255
1256        public String getPanelName() {
1257                Processor processor = getTaskProcessor();
1258                return processor.getTestName();
1259        }
1260
1261        public void saveTask() throws IOException {
1262                String recipeName = getTaskNode().getAttribute("name");
1263                if (fTaskFile == null || !fTaskFile.startsWith("jar:")) {
1264
1265                        if (fTaskFile == null) {
1266                                FileDialog theFileDialog = new FileDialog(JOptionPane.getRootFrame(), "Save Recipe File",
1267                                                FileDialog.SAVE);
1268
1269                                if (directory == null) {
1270                                        theFileDialog.setDirectory(getFrame().getWorkspace().getBaseDir().getAbsolutePath());
1271                                }
1272
1273                                if (getTaskNode() != null) {
1274                                        theFileDialog.setFile(recipeName + ".recipe");
1275                                }
1276                                theFileDialog.setVisible(true);
1277                                if (theFileDialog.getFile() == null)
1278                                        return;
1279
1280                                directory = theFileDialog.getDirectory();
1281
1282                                fTaskFile = new File(theFileDialog.getDirectory() + theFileDialog.getFile()).getAbsolutePath();
1283
1284                        }
1285
1286                        if (getTaskNode() != null) {
1287                                File file = new File(fTaskFile);
1288                                String name = FilenameUtils.getBaseName(file.getName());
1289                                String oldName = getTaskNode().getAttribute("name");
1290                                if (!StringUtils.equals(name, oldName)) {
1291                                        File newfile = new File(file.getParent(), oldName + ".recipe");
1292                                        if (file.renameTo(newfile)) {
1293                                                file = newfile;
1294                                                fTaskFile = file.getAbsolutePath();
1295                                        }
1296                                }
1297
1298                                Node theNode = (Node) getTaskNode().clone();
1299                                String newName = theNode.getAttribute("name");
1300
1301                                AEWorkspace workspace = frame.getWorkspace();
1302                                workspace.removeTestPath(oldName);
1303                                workspace.setTestPath(newName, fTaskFile);
1304
1305                                EasyUtils.removeTagId(theNode);
1306
1307                                byte[] bytes = getTaskNode().getXMLText().getBytes("UTF-8");
1308
1309                                try (FileOutputStream theFileOutputStream = new FileOutputStream(fTaskFile)) {
1310                                        theFileOutputStream.write(bytes);
1311                                }
1312
1313                                setTitle(recipeName);
1314                        }
1315                }
1316        }
1317
1318        public void runTask() {
1319                try {
1320                        final String selectedText = fTaskText.getSelectedText();
1321
1322                        if (openIn && StringUtils.isBlank(selectedText)) {
1323                                reload();
1324                        }
1325
1326                        getManager().startTaskNotify(this);
1327                        runTaskNode();
1328
1329                } catch (Exception e) {
1330                        getLogger().error("Running failed.", e);
1331                }
1332        }
1333
1334        @Override
1335        public void criticalError(final CommandException exception, final Processor processor) {
1336                frame.criticalError(TaskEditor.this);
1337                lblTitle.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, Color.RED));
1338
1339                if (isNotifyMe()) {
1340                        getFrame().fireBuzzAction(() -> super.criticalError(exception, processor));
1341                } else {
1342                        super.criticalError(exception, processor);
1343                }
1344        }
1345
1346        @Override
1347        public void checkFailure(final CommandException exception, final Processor processor) {
1348                frame.checkFailure(TaskEditor.this);
1349
1350                if (isNotifyMe()) {
1351                        getFrame().fireBuzzAction(() -> super.checkFailure(exception, processor));
1352                } else {
1353                        super.checkFailure(exception, processor);
1354                }
1355        }
1356
1357        public void closeTab() {
1358                frame.removeTab(TaskEditor.this);
1359        }
1360
1361        public void showAbout() {
1362                Node taskNode = getTaskNode();
1363                aboutTest(taskNode.getAttribute("name"), taskNode.findNode(ABOUT, null, null));
1364        }
1365
1366        public void showTaskTreePane() {
1367                CardLayout cl = (CardLayout) (createEditorPanel.getLayout());
1368                cl.show(createEditorPanel, TASK_TREE);
1369        }
1370
1371        public int getCaretPosition() {
1372                return fTaskText.getCaretPosition();
1373        }
1374
1375        public Point getMagicCaretPosition() {
1376                return fTaskText.getCaret().getMagicCaretPosition();
1377        }
1378
1379        public String getText() {
1380                return fTaskText.getText();
1381        }
1382
1383        public void replaceRange(String text, int i, int caretPosition2) {
1384                fTaskText.replaceRange(text, i, caretPosition2);
1385        }
1386
1387        public DialogPopupMenu contextHelp(DialogPopupMenu menu) {
1388                return menu;
1389        }
1390
1391        @Override
1392        public void runTest(Node testNode[]) {
1393                Node object = testNode[0];
1394                object.getVector(true);
1395                setTaskNode(object);
1396                refreshTaskTree();
1397                runTaskNode();
1398        }
1399
1400        public AEFrame getFrame() {
1401                return frame;
1402        }
1403
1404        public void pause() {
1405                fRunMenuItem.setEnabled(false);
1406                fContinueMenuItem.setEnabled(true);
1407                fPauseMenuItem.setEnabled(false);
1408
1409                setMessage(" Suspended execution ...");
1410                fTitleTest.setForeground(Color.YELLOW.darker());
1411                lblTitle.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, Color.YELLOW));
1412        }
1413
1414        @Override
1415        public void resume() {
1416                fRunMenuItem.setEnabled(false);
1417                fContinueMenuItem.setEnabled(false);
1418                fPauseMenuItem.setEnabled(true);
1419
1420                setMessage("");
1421                fTitleTest.setForeground(Color.GRAY.darker());
1422                lblTitle.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, ACTIVE_COLOR));
1423        }
1424
1425        public boolean isRunning() {
1426                return isRunning;
1427        }
1428
1429        public TextEditor getEditor() {
1430                return fTaskText;
1431        }
1432
1433        public void select() {
1434                getFrame().setSelectedComponent(getMainPanel());
1435        }
1436
1437        @Override
1438        public void setTaskNode(Node taskNode) {
1439                super.setTaskNode(taskNode);
1440                String aName = getTaskName() + ".notifyMe";
1441                String defaultNotify = AEWorkspace.getInstance().getDefaultUserConfiguration("notifyMe", "true");
1442                boolean notify = Boolean
1443                                .parseBoolean(AEWorkspace.getInstance().getDefaultUserConfiguration(aName, defaultNotify));
1444                notifyMeCheckBox.setSelected(notify);
1445        }
1446
1447        public boolean isNotifyMe() {
1448                return notifyMeCheckBox.isSelected();
1449        }
1450
1451}