Source Code Cross Referenced for ExplorerEditor.java in  » Content-Management-System » contelligent » de » finix » contelligent » client » gui » explorer » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » contelligent » de.finix.contelligent.client.gui.explorer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 2001-2006 C:1 Financial Services GmbH
0003:         *
0004:         * This software is free software; you can redistribute it and/or
0005:         * modify it under the terms of the GNU Lesser General Public
0006:         * License Version 2.1, as published by the Free Software Foundation.
0007:         *
0008:         * This software is distributed in the hope that it will be useful,
0009:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0010:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0011:         * Lesser General Public License for more details.
0012:         *
0013:         * You should have received a copy of the GNU Lesser General Public
0014:         * License along with this library; if not, write to the Free Software
0015:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
0016:         */
0017:
0018:        package de.finix.contelligent.client.gui.explorer;
0019:
0020:        import java.awt.Cursor;
0021:        import java.awt.Dimension;
0022:        import java.awt.Frame;
0023:        import java.awt.GraphicsEnvironment;
0024:        import java.awt.Rectangle;
0025:        import java.awt.Toolkit;
0026:        import java.awt.datatransfer.Clipboard;
0027:        import java.awt.event.FocusAdapter;
0028:        import java.awt.event.FocusEvent;
0029:        import java.awt.event.InputEvent;
0030:        import java.awt.event.KeyAdapter;
0031:        import java.awt.event.KeyEvent;
0032:        import java.awt.event.KeyListener;
0033:        import java.awt.event.MouseAdapter;
0034:        import java.awt.event.MouseEvent;
0035:        import java.util.ArrayList;
0036:        import java.util.Collection;
0037:        import java.util.Iterator;
0038:        import java.util.List;
0039:        import java.util.StringTokenizer;
0040:        import java.util.logging.Level;
0041:        import java.util.logging.Logger;
0042:
0043:        import javax.swing.Action;
0044:        import javax.swing.ActionMap;
0045:        import javax.swing.InputMap;
0046:        import javax.swing.JComponent;
0047:        import javax.swing.JOptionPane;
0048:        import javax.swing.JScrollPane;
0049:        import javax.swing.JTextField;
0050:        import javax.swing.KeyStroke;
0051:        import javax.swing.ToolTipManager;
0052:        import javax.swing.event.TreeExpansionEvent;
0053:        import javax.swing.event.TreeExpansionListener;
0054:        import javax.swing.event.TreeSelectionEvent;
0055:        import javax.swing.event.TreeSelectionListener;
0056:        import javax.swing.event.TreeWillExpandListener;
0057:        import javax.swing.tree.DefaultMutableTreeNode;
0058:        import javax.swing.tree.DefaultTreeModel;
0059:        import javax.swing.tree.DefaultTreeSelectionModel;
0060:        import javax.swing.tree.TreePath;
0061:        import javax.swing.tree.TreeSelectionModel;
0062:
0063:        import de.finix.contelligent.client.ContelligentClient;
0064:        import de.finix.contelligent.client.MainPanel;
0065:        import de.finix.contelligent.client.base.ComponentFactory;
0066:        import de.finix.contelligent.client.base.ComponentNotFoundException;
0067:        import de.finix.contelligent.client.base.ComponentPath;
0068:        import de.finix.contelligent.client.base.ComponentReference;
0069:        import de.finix.contelligent.client.base.ContelligentComponent;
0070:        import de.finix.contelligent.client.base.ContelligentConstants;
0071:        import de.finix.contelligent.client.base.Context;
0072:        import de.finix.contelligent.client.base.Errors;
0073:        import de.finix.contelligent.client.base.PackageNotFoundException;
0074:        import de.finix.contelligent.client.base.PreviewManager;
0075:        import de.finix.contelligent.client.base.ServerInfo;
0076:        import de.finix.contelligent.client.base.Session;
0077:        import de.finix.contelligent.client.base.Type;
0078:        import de.finix.contelligent.client.base.TypeFactory;
0079:        import de.finix.contelligent.client.base.category.ContelligentCategoryManager;
0080:        import de.finix.contelligent.client.base.resource.ContelligentBinaryResource;
0081:        import de.finix.contelligent.client.event.ComponentDisplayEventListener;
0082:        import de.finix.contelligent.client.event.ComponentEventListener;
0083:        import de.finix.contelligent.client.event.ContelligentComponentDisplayEvent;
0084:        import de.finix.contelligent.client.event.ContelligentComponentEvent;
0085:        import de.finix.contelligent.client.event.ContelligentEvent;
0086:        import de.finix.contelligent.client.event.ContelligentEventDispatcher;
0087:        import de.finix.contelligent.client.event.ContelligentLockEvent;
0088:        import de.finix.contelligent.client.event.ContextEvent;
0089:        import de.finix.contelligent.client.event.ContextEventListener;
0090:        import de.finix.contelligent.client.event.LockEventListener;
0091:        import de.finix.contelligent.client.event.TypeEvent;
0092:        import de.finix.contelligent.client.event.TypeEventListener;
0093:        import de.finix.contelligent.client.gui.AbstractComponentEditor;
0094:        import de.finix.contelligent.client.gui.ContelligentAction;
0095:        import de.finix.contelligent.client.gui.CreateComponentDialogView;
0096:        import de.finix.contelligent.client.gui.GUI;
0097:        import de.finix.contelligent.client.gui.GUIContainer;
0098:        import de.finix.contelligent.client.gui.GUIFactory;
0099:        import de.finix.contelligent.client.gui.PathSelectionListener;
0100:        import de.finix.contelligent.client.gui.PathSelectionManager;
0101:        import de.finix.contelligent.client.gui.directory.ComponentFilter;
0102:        import de.finix.contelligent.client.gui.directory.DirectoryEditor;
0103:        import de.finix.contelligent.client.gui.directory.NodeNavigation;
0104:        import de.finix.contelligent.client.gui.directory.ProgressIndicator;
0105:        import de.finix.contelligent.client.i18n.Resources;
0106:        import de.finix.contelligent.client.modules.ModuleFrame;
0107:        import de.finix.contelligent.client.modules.ModuleInitException;
0108:        import de.finix.contelligent.client.modules.event.ModuleAdapter;
0109:        import de.finix.contelligent.client.modules.event.ModuleEvent;
0110:        import de.finix.contelligent.client.modules.preferences.PreferencesModule;
0111:        import de.finix.contelligent.client.remote.ActionResult;
0112:        import de.finix.contelligent.client.remote.Actions;
0113:        import de.finix.contelligent.client.remote.RemoteActionException;
0114:        import de.finix.contelligent.client.util.ActionBundle;
0115:        import de.finix.contelligent.client.util.ExceptionDialog;
0116:        import de.finix.contelligent.client.util.PreviewOptionPane;
0117:        import de.finix.contelligent.client.util.TableLayout;
0118:        import de.finix.contelligent.client.util.bookmark.BookmarkManager;
0119:        import de.finix.contelligent.client.util.dnd.JTreeDND;
0120:        import de.finix.contelligent.client.wizard.TypeWizard;
0121:
0122:        /**
0123:         * Wrapped by DirectoryGUI, PreviewGUI and ExpertTreeGUI, each of which calls this calls with different parameters.
0124:         */
0125:        public class ExplorerEditor extends AbstractComponentEditor implements 
0126:                TypeEventListener, ComponentEventListener,
0127:                ComponentDisplayEventListener, LockEventListener,
0128:                ContextEventListener {
0129:
0130:            public static int BROWSABLE_VIEW = 0;
0131:
0132:            public static int TREE_VIEW = 1;
0133:
0134:            public static int DEFAULT_MODE = 0;
0135:
0136:            public static int EXPERT_MODE = 1;
0137:
0138:            public static int RESTRICTED_MODE = 2;
0139:
0140:            static Logger logger = Logger.getLogger(ExplorerEditor.class
0141:                    .getName());
0142:
0143:            final static Object[] YES_CANCEL_OPTIONS = {
0144:                    Resources.getLocalString("yes"),
0145:                    Resources.getLocalString("cancel") };
0146:
0147:            final static Object[] YES_NO_OPTIONS = {
0148:                    Resources.getLocalString("yes"),
0149:                    Resources.getLocalString("no") };
0150:
0151:            final static Object[] OK_OPTIONS = { Resources.getLocalString("ok") };
0152:
0153:            int MAX_SUBMENU_ITEMS = PreferencesModule.getPreferences().getInt(
0154:                    PreferencesModule.MAX_SUBMENU_ITEMS,
0155:                    PreferencesModule.DEFAULT_MAX_SUBMENU_ITEMS);
0156:
0157:            // Visible children for component paging, set to a minimum of 5 in case the user enters weird data
0158:            private int maxVisibleChildren = Math
0159:                    .max(
0160:                            5,
0161:                            PreferencesModule
0162:                                    .getPreferences()
0163:                                    .getInt(
0164:                                            PreferencesModule.VISIBLE_COMPONENTS_IN_FOLDER,
0165:                                            PreferencesModule.DEFAULT_VISIBLE_COMPONENTS_IN_FOLDER));
0166:
0167:            private int browseMode = TREE_VIEW;
0168:
0169:            private int mode = DEFAULT_MODE;
0170:
0171:            /**
0172:             * Indicates if it is safe to access the system clipboard. Once false, access will never be checked again.
0173:             */
0174:            boolean canAccessSystemClipboard;
0175:
0176:            private boolean editable, previewEditListener;
0177:
0178:            boolean isRootVisible;
0179:
0180:            private int dragAndDropActions;
0181:
0182:            private boolean dropEnabled = true;
0183:
0184:            private JTextField searchField = new JTextField();
0185:
0186:            private ComponentFilter filter;
0187:
0188:            public JTreeDND tree;
0189:
0190:            ContelligentComponent browseRootComponent;
0191:
0192:            ContelligentComponent rootComponent;
0193:
0194:            GUIContainer guiContainer;
0195:
0196:            PathSelectionManager pathSelectionManager;
0197:
0198:            DefaultMutableTreeNode rootNode;
0199:
0200:            static ContelligentComponent componentToCopy = null;
0201:
0202:            private String incrementalSearchString = "";
0203:
0204:            String searchTerm;
0205:
0206:            String currentContext;
0207:
0208:            String createdComponent;
0209:
0210:            boolean editCreatedComponent = false;
0211:
0212:            private DefaultMutableTreeNode selectedNode;
0213:
0214:            private String storedContextName = "";
0215:
0216:            /**
0217:             * Key used in app context to lookup Clipboard to use if access to System clipboard is denied.
0218:             */
0219:            private static Object SandboxClipboardKey = new Object();
0220:
0221:            // Navigation:
0222:            private UpAction upAction = new UpAction(this );
0223:
0224:            private FollowSelectionAction followSelectionAction = new FollowSelectionAction(
0225:                    this );
0226:
0227:            private NewWindowAction newWindowAction = new NewWindowAction(this );
0228:
0229:            HelpAction helpAction = new HelpAction(this );
0230:
0231:            // Component actions
0232:            private ReloadComponentAction reloadComponentAction = new ReloadComponentAction(
0233:                    this );
0234:
0235:            private RenderComponentAction renderComponentAction = new RenderComponentAction(
0236:                    this );
0237:
0238:            private ToggleFinalAction toggleFinalAction = new ToggleFinalAction(
0239:                    this );
0240:
0241:            private PublisherAction publisherAction = new PublisherAction(this );
0242:
0243:            private SignAction signAction = new SignAction(this );
0244:
0245:            private SubtreeSizeAction subtreeSizeAction = new SubtreeSizeAction(
0246:                    this );
0247:
0248:            // Copy & paste...
0249:            private DeleteComponentAction deleteComponentAction = new DeleteComponentAction(
0250:                    this );
0251:
0252:            private CopyComponentAction copyComponentAction = new CopyComponentAction(
0253:                    this );
0254:
0255:            private PasteComponentAction pasteComponentAction = new PasteComponentAction(
0256:                    this );
0257:
0258:            private RenameComponentAction renameComponentAction = new RenameComponentAction(
0259:                    this );
0260:
0261:            // Export & import
0262:            private ExportSubtreeAction exportSubtreeAction = new ExportSubtreeAction(
0263:                    this );
0264:
0265:            private ImportAction importAction = new ImportAction(this );
0266:
0267:            // Types
0268:            public TypeAction typeAction = new TypeAction(this );
0269:
0270:            private CreateTypeAction createTypeAction = new CreateTypeAction(
0271:                    this );
0272:
0273:            private UpdateTypeAction updateTypeAction = new UpdateTypeAction(
0274:                    this );
0275:
0276:            private RenameTypeAction renameTypeAction = new RenameTypeAction(
0277:                    this );
0278:
0279:            private ConvertTypeAction convertTypeAction = new ConvertTypeAction(
0280:                    this );
0281:
0282:            private DeleteTypeOnlyAction deleteTypeOnlyAction = new DeleteTypeOnlyAction(
0283:                    this );
0284:
0285:            private CreateTypeInstanceAction createTypeInstanceAction;
0286:
0287:            // Move & sort
0288:            MoveAction moveAction = new MoveAction(this );
0289:
0290:            private MoveUpAction moveUpAction = new MoveUpAction(this );
0291:
0292:            private MoveDownAction moveDownAction = new MoveDownAction(this );
0293:
0294:            private MoveTopAction moveTopAction = new MoveTopAction(this );
0295:
0296:            private MoveBottomAction moveBottomAction = new MoveBottomAction(
0297:                    this );
0298:
0299:            private SortAscendAction sortAscendAction = new SortAscendAction(
0300:                    this );
0301:
0302:            private SortDescendAction sortDescendAction = new SortDescendAction(
0303:                    this );
0304:
0305:            // Find:
0306:            FindAction findAction = new FindAction(this );
0307:
0308:            private FindInstancesAction findInstancesAction = new FindInstancesAction(
0309:                    this );
0310:
0311:            private FindUsagesAction findUsagesAction = new FindUsagesAction(
0312:                    this );
0313:
0314:            private FindTextAction findTextAction = new FindTextAction(this );
0315:
0316:            private FindNameAction findNameAction = new FindNameAction(this );
0317:
0318:            // Go to:
0319:            GoToAction goToAction = new GoToAction(this );
0320:
0321:            private GoToBlueprintAction goToBlueprintAction = new GoToBlueprintAction(
0322:                    this );
0323:
0324:            private GoToLinkTargetAction goToLinkTarget = new GoToLinkTargetAction(
0325:                    this );
0326:
0327:            // Preview:
0328:            private PreviewAction previewAction = new PreviewAction(this );
0329:
0330:            private LastPreviewAction lastPreviewAction = new LastPreviewAction(
0331:                    this );
0332:
0333:            private EditPreviewAction editPreviewAction = new EditPreviewAction(
0334:                    this );
0335:
0336:            // Bookmarks:
0337:            private CreateBookmarkAction createBookmarkAction = new CreateBookmarkAction(
0338:                    this );
0339:
0340:            private ManageBookmarkAction manageBookmarkAction = new ManageBookmarkAction(
0341:                    this );
0342:
0343:            private boolean moduleLoaded = false;
0344:
0345:            // Context handling:
0346:            private CreateContextAction createContextAction = new CreateContextAction(
0347:                    this );
0348:
0349:            private EditContextACLAction editContextACLAction = new EditContextACLAction(
0350:                    this );
0351:
0352:            private SwitchContextAction switchContextAction = new SwitchContextAction(
0353:                    this );
0354:
0355:            private DiscardContextAction discardContextAction = new DiscardContextAction(
0356:                    this );
0357:
0358:            private CommitContextAction commitContextAction = new CommitContextAction(
0359:                    this );
0360:
0361:            private ShowModifiedComponentsAction showModifiedComponentsAction = new ShowModifiedComponentsAction(
0362:                    this );
0363:
0364:            private ShowDeletedComponentsAction showDeletedComponentsAction = new ShowDeletedComponentsAction(
0365:                    this );
0366:
0367:            private ShowLockedComponentsAction showLockedComponentsAction = new ShowLockedComponentsAction(
0368:                    this );
0369:
0370:            // Locking:
0371:            private LockAction lockAction = new LockAction(this );
0372:
0373:            private UnlockAction unlockAction = new UnlockAction(this );
0374:
0375:            private CommitSubtreeAction commitSubtreeAction = new CommitSubtreeAction(
0376:                    this );
0377:
0378:            private RollbackSubtreeAction rollbackSubtreeAction = new RollbackSubtreeAction(
0379:                    this );
0380:
0381:            // Refactoring
0382:            private AddToBlueprintInstancesAction addToBlueprintInstancesAction = new AddToBlueprintInstancesAction(
0383:                    this );
0384:
0385:            private CleanUpBlueprintInstancesAction cleanUpBlueprintInstancesAction = new CleanUpBlueprintInstancesAction(
0386:                    this );
0387:
0388:            private UnlinkAction unlinkAction = new UnlinkAction(this );
0389:
0390:            public void init() {
0391:                rootComponent = getComponent();
0392:                setLayout(new TableLayout(new double[][] {
0393:                        { TableLayout.FILL },
0394:                        { TableLayout.FILL, TableLayout.PREFERRED } }));
0395:                setMinimumSize(new Dimension(200, 0));
0396:
0397:                rootNode = new DefaultMutableTreeNode(new ComponentReference(
0398:                        rootComponent));
0399:                addSubcomponents(rootComponent, rootNode);
0400:
0401:                tree = new JTreeDND(getView().getEnvironment(), rootNode,
0402:                        getDragAndDropActions(), dropEnabled);
0403:                tree.setPathSelectionManager(pathSelectionManager);
0404:                tree.setDragEnabled(true);
0405:                tree.setEditable(false);
0406:                tree.setRowHeight(20);
0407:                tree.setToggleClickCount(99);
0408:                tree.setCellRenderer(new ExplorerCellRenderer(getView()));
0409:                tree.putClientProperty("JTree.lineStyle", "Angled");
0410:
0411:                ActionMap aMap = tree.getActionMap();
0412:                InputMap iMap = tree.getInputMap();
0413:                iMap.put((KeyStroke) copyComponentAction
0414:                        .getValue(Action.ACCELERATOR_KEY), "copy");
0415:                iMap.put((KeyStroke) pasteComponentAction
0416:                        .getValue(Action.ACCELERATOR_KEY), "paste");
0417:
0418:                iMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT,
0419:                        InputEvent.CTRL_MASK), "copy");
0420:                iMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_INSERT,
0421:                        InputEvent.SHIFT_MASK), "paste");
0422:
0423:                aMap.put("copy", copyComponentAction);
0424:                aMap.put("paste", pasteComponentAction);
0425:
0426:                // XXX unregister default key listener that listens to characters and
0427:                // jumps between nodes...
0428:                // We replace this with incremental search...
0429:                KeyListener[] listeners = tree.getKeyListeners();
0430:                tree.removeKeyListener(listeners[0]);
0431:
0432:                ToolTipManager.sharedInstance().registerComponent(tree);
0433:                if (browseMode == BROWSABLE_VIEW) {
0434:                    tree.setRootVisible(isRootVisible);
0435:                } else if (browseMode == TREE_VIEW) {
0436:                    tree.setRootVisible(isRootVisible);
0437:                }
0438:                DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
0439:                selectionModel
0440:                        .setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
0441:                tree.setSelectionModel(selectionModel);
0442:
0443:                tree.addFocusListener(new FocusAdapter() {
0444:                    public void focusGained(FocusEvent e) {
0445:                        if (!getView().isEditInProgress()) {
0446:                            setActions(getActions());
0447:
0448:                            if (moduleLoaded) {
0449:                                // update bookmark actions
0450:                                getView().getMenuAndToolbarComposer()
0451:                                        .addTemporaryActionBundle(
0452:                                                ActionBundle.BOOKMARK_ACTIONS,
0453:                                                getBookmarkActions());
0454:                            }
0455:                        }
0456:                    }
0457:                });
0458:
0459:                tree.addTreeExpansionListener(new TreeExpansionListener() {
0460:                    public void treeExpanded(TreeExpansionEvent te) {
0461:                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) te
0462:                                .getPath().getLastPathComponent();
0463:                        incrementalSearchString = "";
0464:                        updateNode(node);
0465:                        setCursor(Cursor.getDefaultCursor());
0466:                    }
0467:
0468:                    public void treeCollapsed(TreeExpansionEvent te) {
0469:                    }
0470:                });
0471:
0472:                tree.addTreeWillExpandListener(new TreeWillExpandListener() {
0473:                    public void treeWillExpand(TreeExpansionEvent te) {
0474:                        setCursor(Cursor
0475:                                .getPredefinedCursor(Cursor.WAIT_CURSOR));
0476:                    }
0477:
0478:                    public void treeWillCollapse(TreeExpansionEvent te) {
0479:                    }
0480:                });
0481:
0482:                tree.addTreeSelectionListener(new TreeSelectionListener() {
0483:                    public void valueChanged(TreeSelectionEvent e) {
0484:                        // Only update on nodes added to selection, not removed
0485:                        if (e.isAddedPath()) {
0486:                            DefaultMutableTreeNode node = (DefaultMutableTreeNode) e
0487:                                    .getPath().getLastPathComponent();
0488:                            try {
0489:                                Object o = node.getUserObject();
0490:                                if (o instanceof  ComponentReference) {
0491:                                    ContelligentComponent component = ((ComponentReference) o)
0492:                                            .getComponent();
0493:                                    if (guiContainer != null)
0494:                                        guiContainer
0495:                                                .setSelectedComponent(component);
0496:                                    activateActions((DefaultMutableTreeNode) tree
0497:                                            .getLastSelectedPathComponent());
0498:                                }
0499:                            } catch (ComponentNotFoundException cnfe) {
0500:                                logger.log(Level.WARNING,
0501:                                        "ContelligentComponent not found at node ["
0502:                                                + node + "]", cnfe);
0503:                            }
0504:                        }
0505:                    }
0506:                });
0507:
0508:                tree.addMouseListener(new ExplorerMouseAdapter());
0509:
0510:                JScrollPane scrollPane = new JScrollPane(tree);
0511:
0512:                tree.addKeyListener(new KeyAdapter() {
0513:                    public void keyReleased(KeyEvent e) {
0514:                        if (e.getKeyCode() == KeyEvent.VK_DELETE
0515:                                || e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
0516:                            if (incrementalSearchString.length() == 1) {
0517:                                incrementalSearchString = "";
0518:                            } else if (incrementalSearchString.length() > 1) {
0519:                                incrementalSearchString = incrementalSearchString
0520:                                        .substring(0, incrementalSearchString
0521:                                                .length() - 1);
0522:                            }
0523:                            updateSelectedNode();
0524:                            e.consume();
0525:                        } else if (!e.isActionKey() && !e.isControlDown()) {
0526:                            char c = e.getKeyChar();
0527:                            if (Character.isLetterOrDigit(c)
0528:                                    || Character.isSpaceChar(c)) {
0529:                                incrementalSearchString = incrementalSearchString
0530:                                        + c;
0531:                                updateSelectedNode();
0532:                                e.consume();
0533:                            }
0534:                        }
0535:                        searchField.setText(incrementalSearchString);
0536:                    }
0537:                });
0538:
0539:                getView().addModuleListener(new ModuleAdapter() {
0540:                    public void moduleActivated(ModuleEvent event) {
0541:                        // add bookmark action bundle to toolbar etc...
0542:                        getView().getMenuAndToolbarComposer()
0543:                                .addTemporaryActionBundle(
0544:                                        ActionBundle.BOOKMARK_ACTIONS,
0545:                                        getBookmarkActions());
0546:
0547:                        moduleLoaded = true;
0548:                    }
0549:
0550:                    public void moduleDeactivated(ModuleEvent event) {
0551:                        // remove bookmark action bundle from toolbar etc...
0552:                        getView().getMenuAndToolbarComposer()
0553:                                .removeActionBundle(
0554:                                        ActionBundle.BOOKMARK_ACTIONS);
0555:
0556:                        moduleLoaded = false;
0557:                    }
0558:
0559:                    public void moduleDestroyed(ModuleEvent event) {
0560:                        // remove all action bundles from toolbar etc...
0561:                        getView().getMenuAndToolbarComposer()
0562:                                .removeActionBundle(
0563:                                        ActionBundle.BOOKMARK_ACTIONS);
0564:
0565:                        moduleLoaded = false;
0566:                    }
0567:                });
0568:
0569:                add(scrollPane, "0,0,0,0");
0570:                searchField.setEditable(false);
0571:                searchField.setFocusable(false);
0572:                searchField.setBackground(ContelligentConstants.CI_COLOR);
0573:                add(searchField, "0,1,0,1");
0574:
0575:                upAction.setEnabled(false);
0576:
0577:                // XXX do this here to have view set and action updated upon reload
0578:                createTypeInstanceAction = new CreateTypeInstanceAction(this );
0579:                updateActiveActionsCheckingWorkflowAndACL();
0580:                showModifiedComponentsAction.setEnabled(false);
0581:                showDeletedComponentsAction.setEnabled(false);
0582:
0583:                ComponentFactory.getInstance().addLockEventListener(this ,
0584:                        ContelligentEventDispatcher.DOES_USE_SWING);
0585:                ComponentFactory.getInstance().addComponentEventListener(this ,
0586:                        ContelligentEventDispatcher.DOES_USE_SWING);
0587:                ComponentFactory.getInstance()
0588:                        .addComponentDisplayEventListener(this ,
0589:                                ContelligentEventDispatcher.DOES_USE_SWING);
0590:                ComponentFactory.getInstance().addContextEventListener(this ,
0591:                        ContelligentEventDispatcher.DOES_USE_SWING);
0592:                TypeFactory.getInstance().addTypeEventListener(this ,
0593:                        ContelligentEventDispatcher.DOES_USE_SWING);
0594:
0595:                setActions(getActions());
0596:                activateActions(rootNode);
0597:            }
0598:
0599:            public void initialSelect() {
0600:                try {
0601:                    ContelligentComponent component = ((ComponentReference) rootNode
0602:                            .getUserObject()).getComponent();
0603:                    this .selectComponent(component);
0604:                    guiContainer.setSelectedComponent(component);
0605:                    guiContainer.renderSelectedComponent();
0606:
0607:                } catch (ComponentNotFoundException cne) {
0608:                    logger.log(Level.WARNING, "Root component for module "
0609:                            + this .getName() + " could not be found.");
0610:                }
0611:            }
0612:
0613:            /**
0614:             * Enables or disabled dropping of components on the tree
0615:             * 
0616:             * @param dropEnabled
0617:             *            true=drop is accepted, false=drop will be rejected
0618:             */
0619:            public void setDropEnabled(boolean dropEnabled) {
0620:                this .dropEnabled = dropEnabled;
0621:            }
0622:
0623:            private void updateSelectedNode() {
0624:                DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
0625:                        .getLastSelectedPathComponent();
0626:                if (node == null) {
0627:                    node = rootNode;
0628:                } else {
0629:                    node = (DefaultMutableTreeNode) node.getParent();
0630:                    if (node == null)
0631:                        node = rootNode;
0632:                }
0633:                updateNode(node);
0634:            }
0635:
0636:            /**
0637:             * Updates the given tree node by removing and readding the children of this node If the <code>selectedNode</code>
0638:             * is set, the tree scrolls to the selected node.
0639:             * 
0640:             * @param node
0641:             *            the node to update
0642:             */
0643:            private void updateNode(DefaultMutableTreeNode node) {
0644:                if (node.getUserObject() instanceof  ComponentReference) {
0645:                    try {
0646:                        ContelligentComponent component = ((ComponentReference) node
0647:                                .getUserObject()).getComponent();
0648:                        addSubcomponents(component, node);
0649:                    } catch (ComponentNotFoundException cnfe) {
0650:                        logger
0651:                                .log(
0652:                                        Level.WARNING,
0653:                                        "ContelligentComponent not found while expanding",
0654:                                        cnfe);
0655:                    }
0656:                    ((DefaultTreeModel) tree.getModel()).reload(node);
0657:                } else {
0658:                    node.removeFromParent();
0659:                }
0660:                if (selectedNode != null) {
0661:                    TreePath path = new TreePath(selectedNode.getPath());
0662:                    tree.setSelectionPath(path);
0663:                    tree.scrollPathToVisible(path);
0664:                    activateActions((DefaultMutableTreeNode) tree
0665:                            .getLastSelectedPathComponent());
0666:                }
0667:            }
0668:
0669:            // Context event listener methods:
0670:
0671:            public void onContextCreated(ContextEvent e) {
0672:            }
0673:
0674:            public void onContextDiscarded(ContextEvent e) {
0675:                // If our current context is discarded, switch back to Production
0676:                if (e.getContext().equals(
0677:                        ComponentFactory.getInstance().getCurrentContext()
0678:                                .getName())) {
0679:                    ComponentFactory.getInstance().switchToMainContext();
0680:                    JOptionPane
0681:                            .showMessageDialog(
0682:                                    this ,
0683:                                    Resources
0684:                                            .getLocalString("context_discarded_message"),
0685:                                    Resources
0686:                                            .getLocalString("context_discarded_title"),
0687:                                    JOptionPane.WARNING_MESSAGE);
0688:                }
0689:            }
0690:
0691:            public void onContextSwitched(ContextEvent e) {
0692:                // Prevent double context switching
0693:                if (!e.getContext().equals(storedContextName)) {
0694:                    try {
0695:                        // We must clear the selection manually before setting the
0696:                        // new model on the tree, since our listeners break otherwise.
0697:                        tree.clearSelection();
0698:                        currentContext = e.getContext();
0699:                        ComponentFactory.getInstance().reload(rootComponent);
0700:                        rootNode = new DefaultMutableTreeNode(
0701:                                new ComponentReference(rootComponent));
0702:                        addSubcomponents(rootComponent, rootNode);
0703:                        tree.setModel(new DefaultTreeModel(rootNode));
0704:                        tree.validate();
0705:                        tree.repaint();
0706:                        storedContextName = e.getContext();
0707:                        // reset search results
0708:                        pathSelectionManager.hidePaths();
0709:                    } catch (ComponentNotFoundException cnfe) {
0710:                        logger
0711:                                .log(Level.SEVERE,
0712:                                        "Could not reload root component of explorer editor!");
0713:                    }
0714:                    updateActiveActionsCheckingWorkflowAndACL();
0715:                    initialSelect();
0716:                }
0717:            }
0718:
0719:            // Component event listener methods:
0720:            /**
0721:             * This method is called when a component add event occurs. It has to check, if the component to add already exists
0722:             * or if a progress indicator exitst under the name of the newly added component.
0723:             * 
0724:             * @param event
0725:             */
0726:            public synchronized void onComponentAdded(
0727:                    ContelligentComponentEvent event) {
0728:                String targetDir = ComponentPath.getClientComponentDir(event
0729:                        .getTarget());
0730:                String targetName = ComponentPath.getComponentName(event
0731:                        .getTarget());
0732:                String targetPath = ComponentPath.toClientComponentPath(event
0733:                        .getTarget());
0734:
0735:                DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) tree
0736:                        .getModel().getRoot();
0737:                String rootPath = ComponentPath
0738:                        .getClientComponentDir(((ComponentReference) rootNode
0739:                                .getUserObject()).getPath());
0740:
0741:                // check if parent of target node is already part of the tree
0742:                DefaultMutableTreeNode node = findNode(rootNode, rootPath,
0743:                        targetDir);
0744:                if (node != null) {
0745:                    boolean addComponent = true;
0746:                    // check if component already exists...
0747:                    for (int i = 0; i < node.getChildCount(); i++) {
0748:                        DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node
0749:                                .getChildAt(i);
0750:                        if (childNode.getUserObject() instanceof  ComponentReference) {
0751:                            if (((ComponentReference) childNode.getUserObject())
0752:                                    .getName().equals(targetName)) {
0753:                                // ...and do nothing if already there
0754:                                addComponent = false;
0755:                                break;
0756:                            }
0757:                        } else if (childNode.getUserObject() instanceof  ProgressIndicator) {
0758:                            if (((ProgressIndicator) childNode.getUserObject())
0759:                                    .getName().equals(targetName)) {
0760:                                // ...and remove progress indactor in case of finished
0761:                                // copy/move
0762:                                ((DefaultTreeModel) tree.getModel())
0763:                                        .removeNodeFromParent(childNode);
0764:                                break;
0765:                            }
0766:                        }
0767:                    }
0768:                    if (addComponent) {
0769:                        try {
0770:                            ContelligentComponent component = ComponentFactory
0771:                                    .getInstance().getComponent(
0772:                                            event.getTarget());
0773:                            if (!getView().isEditInProgress()
0774:                                    && event.getTarget().equals(
0775:                                            createdComponent)
0776:                                    && guiContainer != null) {
0777:                                createdComponent = null;
0778:                                guiContainer.setSelectedComponent(component);
0779:                                selectComponent(component);
0780:                                if (editCreatedComponent) {
0781:                                    guiContainer.editSelectedComponent();
0782:                                } else {
0783:                                    guiContainer.renderSelectedComponent();
0784:                                }
0785:                            } else {
0786:                                addChildNode(node, createChildNode(component));
0787:                            }
0788:                        } catch (ComponentNotFoundException cnfe) {
0789:                            logger.log(Level.SEVERE,
0790:                                    "Component could not be added", cnfe);
0791:                        }
0792:                    }
0793:                } else {
0794:                    logger.log(Level.FINE, "Target path not part of the tree!");
0795:                }
0796:
0797:                // we have to check if user bookmark component has changed, because the bookmark list in menu has to be always
0798:                // up to date. every bookmark item is a bookmark action.
0799:                // get user:
0800:                String groupID = Session.getInstance().getUser().getPrincipal()
0801:                        .getGroupId();
0802:                String iD = Session.getInstance().getUser().getPrincipal()
0803:                        .getId();
0804:                // build path to user bookmark component:
0805:                String userBookmarkPath = "/contelligent/home/" + groupID + "/"
0806:                        + iD + "/bookmarks";
0807:                // check, if user bookmark component has changed:
0808:                if (targetPath.equals(userBookmarkPath)) {
0809:                    if (moduleLoaded) {
0810:                        BookmarkManager bookmarkManager = BookmarkManager
0811:                                .getInstance();
0812:                        bookmarkManager.loadBookmarks();
0813:
0814:                        // update bookmark actions
0815:                        getView().getMenuAndToolbarComposer()
0816:                                .addTemporaryActionBundle(
0817:                                        ActionBundle.BOOKMARK_ACTIONS,
0818:                                        getBookmarkActions());
0819:                    }
0820:                }
0821:            }
0822:
0823:            private synchronized void addChildNode(DefaultMutableTreeNode node,
0824:                    DefaultMutableTreeNode childNode) {
0825:                Object o1 = node.getUserObject();
0826:                Object o2 = childNode.getUserObject();
0827:                int targetPos = -1; // Old-style auto placement (for progress indicators)
0828:                if ((o1 instanceof  ComponentReference)
0829:                        && (o2 instanceof  ComponentReference)) {
0830:                    targetPos = -2; // Dont add node if no position could be found
0831:                    try {
0832:                        ComponentReference cr1 = (ComponentReference) o1;
0833:                        ComponentReference cr2 = (ComponentReference) o2;
0834:                        int start = cr1.getStart();
0835:                        int pos = cr1.getComponent().indexOfSubcomponent(
0836:                                cr2.getName());
0837:                        if ((start == 0)
0838:                                && ((pos < maxVisibleChildren) || (!(node
0839:                                        .getLastLeaf().getUserObject() instanceof  NodeNavigation)))) {
0840:                            // If the list is at the beginning and (it doesnt page yet or our element is within the
0841:                            // page size), add it.
0842:                            targetPos = pos;
0843:                        } else if ((pos < (start + maxVisibleChildren))
0844:                                && (pos >= start)) {
0845:                            // Otherwise check if the component is within the limits of the current page
0846:                            targetPos = pos - start + 1;
0847:                        }
0848:                    } catch (ComponentNotFoundException cne) {
0849:                        logger.log(Level.WARNING, "Component not found.", cne);
0850:                    }
0851:                }
0852:                if (targetPos == -1) {
0853:                    // add new component after the children but before next-indicator
0854:                    if (node.getChildCount() > 0
0855:                            && ((DefaultMutableTreeNode) node.getLastChild())
0856:                                    .getUserObject() instanceof  NodeNavigation) {
0857:                        node.insert(childNode, node.getChildCount() - 1);
0858:                    } else {
0859:                        node.add(childNode);
0860:                    }
0861:                    ((DefaultTreeModel) tree.getModel())
0862:                            .nodeStructureChanged(node);
0863:                } else if (targetPos >= 0) {
0864:                    // add at fixed position
0865:                    node.insert(childNode, targetPos);
0866:                    ((DefaultTreeModel) tree.getModel())
0867:                            .nodeStructureChanged(node);
0868:                }
0869:            }
0870:
0871:            public void onComponentRemoved(ContelligentComponentEvent event) {
0872:                String targetPath = event.getTarget();
0873:                String targetDir = ComponentPath
0874:                        .getClientComponentDir(targetPath);
0875:                String targetName = ComponentPath.getComponentName(targetPath);
0876:
0877:                DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) tree
0878:                        .getModel().getRoot();
0879:                String rootPath = ComponentPath
0880:                        .getClientComponentDir(((ComponentReference) rootNode
0881:                                .getUserObject()).getPath());
0882:
0883:                // check if target node is already part of the tree
0884:                DefaultMutableTreeNode node = findNode(rootNode, rootPath,
0885:                        targetDir);
0886:                if (node != null) {
0887:                    DefaultMutableTreeNode childNode = getChild(node,
0888:                            targetName);
0889:                    if (childNode != null) {
0890:                        DefaultTreeModel model = ((DefaultTreeModel) tree
0891:                                .getModel());
0892:                        int childIndex = model.getIndexOfChild(node, childNode);
0893:                        int childCount = model.getChildCount(node);
0894:                        int newIndex = -1;
0895:                        if (childCount > 1) {
0896:                            if (childIndex == 0) {
0897:                                newIndex = 0;
0898:                            } else {
0899:                                newIndex = childIndex - 1;
0900:                            }
0901:                        }
0902:
0903:                        logger.log(Level.FINE, "Target path found in tree");
0904:                        ((DefaultTreeModel) tree.getModel())
0905:                                .removeNodeFromParent(childNode);
0906:
0907:                        // WARNING: Be careful not to refer to component specified in
0908:                        // event, as has already been removed from
0909:                        // ComponentFactory's cache. Referring to it leads to reload
0910:                        // from server, which fails as well, as it
0911:                        // has been removed from server as well.
0912:
0913:                        // if the component just removed was the selected one, select a
0914:                        // new one
0915:                        if (guiContainer != null
0916:                                && guiContainer.getSelectedComponent().equals(
0917:                                        targetPath)) {
0918:                            ContelligentComponent componentToSelect = rootComponent;
0919:                            String selectPath;
0920:                            if (newIndex == -1 && targetDir != null
0921:                                    && !targetDir.equals("/")) {
0922:                                selectPath = targetDir;
0923:                            } else {
0924:                                DefaultMutableTreeNode newNode = (DefaultMutableTreeNode) model
0925:                                        .getChild(node, newIndex);
0926:                                while (!(newNode.getUserObject() instanceof  ComponentReference)) {
0927:                                    newIndex--;
0928:                                    if (newIndex == -1)
0929:                                        newIndex = node.getChildCount() - 1;
0930:                                    if (newIndex == 0)
0931:                                        break;
0932:                                    newNode = (DefaultMutableTreeNode) model
0933:                                            .getChild(node, newIndex);
0934:                                }
0935:                                if (newNode.getUserObject() instanceof  ComponentReference) {
0936:                                    selectPath = ((ComponentReference) newNode
0937:                                            .getUserObject()).getPath();
0938:                                } else {
0939:                                    selectPath = targetDir;
0940:                                }
0941:                            }
0942:                            logger.log(Level.FINE, "Selected path:"
0943:                                    + selectPath);
0944:                            try {
0945:                                componentToSelect = ComponentFactory
0946:                                        .getInstance().getComponent(selectPath);
0947:                            } catch (ComponentNotFoundException cnfe) {
0948:                                logger.log(Level.WARNING,
0949:                                        "Could not select component "
0950:                                                + selectPath, cnfe);
0951:                            }
0952:                            guiContainer
0953:                                    .setSelectedComponent(componentToSelect);
0954:                            guiContainer.renderSelectedComponent();
0955:                            selectComponent(componentToSelect);
0956:                        }
0957:                    }
0958:                } else {
0959:                    logger.log(Level.FINE, "Target path not part of the tree!");
0960:                }
0961:
0962:                // we have to check if user bookmark component has changed, because the bookmark list in menu has to be always
0963:                // up to date. every bookmark item is a bookmark action.
0964:                // get user:
0965:                String groupID = Session.getInstance().getUser().getPrincipal()
0966:                        .getGroupId();
0967:                String iD = Session.getInstance().getUser().getPrincipal()
0968:                        .getId();
0969:                // build path to user bookmark component:
0970:                String userPath = "/contelligent/home/" + groupID + "/" + iD;
0971:                String userBookmarkPath = userPath.concat("/bookmarks");
0972:                // check, if user bookmark component has changed:
0973:                if (targetPath.equals(userBookmarkPath)
0974:                        || targetPath.equals(userPath)) {
0975:                    if (moduleLoaded) {
0976:                        BookmarkManager bookmarkManager = BookmarkManager
0977:                                .getInstance();
0978:                        bookmarkManager.loadBookmarks();
0979:
0980:                        // update bookmark actions
0981:                        getView().getMenuAndToolbarComposer()
0982:                                .addTemporaryActionBundle(
0983:                                        ActionBundle.BOOKMARK_ACTIONS,
0984:                                        getBookmarkActions());
0985:                    }
0986:                }
0987:            }
0988:
0989:            public void onComponentChanged(ContelligentComponentEvent event) {
0990:                String targetPath = ComponentPath.toClientComponentPath(event
0991:                        .getTarget());
0992:                DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) tree
0993:                        .getModel().getRoot();
0994:                String rootPath = ComponentPath
0995:                        .getClientComponentDir(((ComponentReference) rootNode
0996:                                .getUserObject()).getPath());
0997:
0998:                // check if target node is already part of the tree
0999:                DefaultMutableTreeNode node = findNode(rootNode, rootPath,
1000:                        targetPath);
1001:                if (node != null) {
1002:                    logger.log(Level.FINE, "Target path found in tree");
1003:                    if (node.getUserObject() instanceof  ComponentReference) {
1004:                        try {
1005:                            node.removeAllChildren();
1006:                            ContelligentComponent component = ((ComponentReference) node
1007:                                    .getUserObject()).getComponent();
1008:                            ContelligentComponent selectedComponent = getSelectedComponent();
1009:                            boolean reselect = (selectedComponent != null && selectedComponent
1010:                                    .getParentComponent().equals(component));
1011:                            addSubcomponents(component, node);
1012:                            ((DefaultTreeModel) tree.getModel())
1013:                                    .nodeStructureChanged(node);
1014:                            if (reselect) {
1015:                                selectComponent(selectedComponent);
1016:                            }
1017:                        } catch (ComponentNotFoundException cnfe) {
1018:                            logger
1019:                                    .log(
1020:                                            Level.WARNING,
1021:                                            "ContelligentComponent not found while processing change event",
1022:                                            cnfe);
1023:                        }
1024:                    }
1025:                } else {
1026:                    logger.log(Level.FINE, "Target path not part of the tree!");
1027:                }
1028:
1029:                // we have to check if user bookmark component has changed, because the bookmark list in menu has to be always
1030:                // up to date. every bookmark item is a bookmark action.
1031:                // get user:
1032:                String groupID = Session.getInstance().getUser().getPrincipal()
1033:                        .getGroupId();
1034:                String iD = Session.getInstance().getUser().getPrincipal()
1035:                        .getId();
1036:                // build path to user bookmark component:
1037:                String userPath = "/contelligent/home/" + groupID + "/" + iD;
1038:                String userBookmarkPath = userPath.concat("/bookmarks");
1039:                // check, if user bookmark component has changed:
1040:                if (targetPath.equals(userBookmarkPath)
1041:                        || targetPath.equals(userPath)) {
1042:                    if (moduleLoaded) {
1043:                        BookmarkManager bookmarkManager = BookmarkManager
1044:                                .getInstance();
1045:                        bookmarkManager.loadBookmarks();
1046:
1047:                        // update bookmark actions
1048:                        getView().getMenuAndToolbarComposer()
1049:                                .addTemporaryActionBundle(
1050:                                        ActionBundle.BOOKMARK_ACTIONS,
1051:                                        getBookmarkActions());
1052:                    }
1053:                }
1054:            }
1055:
1056:            public void onComponentAddInProgress(
1057:                    ContelligentComponentDisplayEvent event) {
1058:                String targetDir = ComponentPath.getClientComponentDir(event
1059:                        .getTarget());
1060:                String targetName = ComponentPath.getComponentName(event
1061:                        .getTarget());
1062:
1063:                DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) tree
1064:                        .getModel().getRoot();
1065:                String rootPath = ComponentPath
1066:                        .getClientComponentDir(((ComponentReference) rootNode
1067:                                .getUserObject()).getPath());
1068:
1069:                // check if target node is already part of the tree
1070:                DefaultMutableTreeNode node = findNode(rootNode, rootPath,
1071:                        targetDir);
1072:                if (node != null) {
1073:                    logger.log(Level.FINE, "Target path found in tree");
1074:                    DefaultMutableTreeNode originalNode = null;
1075:                    // check if component already exists...
1076:                    for (int i = 0; i < node.getChildCount(); i++) {
1077:                        DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node
1078:                                .getChildAt(i);
1079:                        if (childNode.getUserObject() instanceof  ComponentReference) {
1080:                            logger.log(Level.FINEST, "Compare name '"
1081:                                    + targetName
1082:                                    + "' with '"
1083:                                    + ((ComponentReference) childNode
1084:                                            .getUserObject()).getName() + "'");
1085:                            if (((ComponentReference) childNode.getUserObject())
1086:                                    .getName().equals(targetName)) {
1087:                                // ...and remove it in that case, but remember it in
1088:                                // case this fails
1089:                                originalNode = new DefaultMutableTreeNode(
1090:                                        childNode.getUserObject());
1091:                                if (!childNode.isLeaf()) {
1092:                                    originalNode
1093:                                            .add(new DefaultMutableTreeNode(
1094:                                                    "[dummy]"));
1095:                                }
1096:                                logger.log(Level.FINE,
1097:                                        "Remove node with index " + i);
1098:                                ((DefaultTreeModel) tree.getModel())
1099:                                        .removeNodeFromParent(childNode);
1100:                                break;
1101:                            }
1102:                        } else if (childNode.getUserObject() instanceof  ProgressIndicator) {
1103:                            logger.log(Level.FINEST,
1104:                                    "found a ProgressIndicator instance for target '"
1105:                                            + targetName + "' ... reusing it");
1106:                            if (((ProgressIndicator) childNode.getUserObject())
1107:                                    .getName().equals(targetName)) {
1108:                                // ...and remove it in that case, but remember it in
1109:                                // case this fails
1110:                                originalNode = ((ProgressIndicator) childNode
1111:                                        .getUserObject()).getNode();
1112:                                logger.log(Level.FINE,
1113:                                        "Remove node with index " + i);
1114:                                ((DefaultTreeModel) tree.getModel())
1115:                                        .removeNodeFromParent(childNode);
1116:                                break;
1117:                            }
1118:                        }
1119:                    }
1120:                    DefaultMutableTreeNode addedNode = new DefaultMutableTreeNode(
1121:                            new ProgressIndicator(targetName,
1122:                                    Resources.addInProgressIcon, originalNode));
1123:                    // add dummy for children if component has some...
1124:                    addChildNode(node, addedNode);
1125:                }
1126:            }
1127:
1128:            public void onComponentAddAborted(
1129:                    ContelligentComponentDisplayEvent event) {
1130:                String targetDir = ComponentPath.getClientComponentDir(event
1131:                        .getTarget());
1132:                String targetName = ComponentPath.getComponentName(event
1133:                        .getTarget());
1134:
1135:                DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) tree
1136:                        .getModel().getRoot();
1137:                String rootPath = ComponentPath
1138:                        .getClientComponentDir(((ComponentReference) rootNode
1139:                                .getUserObject()).getPath());
1140:
1141:                revertProgressIndicator(rootNode, rootPath, targetDir,
1142:                        targetName);
1143:            }
1144:
1145:            public void onComponentRemoveInProgress(
1146:                    ContelligentComponentDisplayEvent event) {
1147:                String targetDir = ComponentPath.getClientComponentDir(event
1148:                        .getTarget());
1149:                String targetName = ComponentPath.getComponentName(event
1150:                        .getTarget());
1151:
1152:                DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) tree
1153:                        .getModel().getRoot();
1154:                String rootPath = ComponentPath
1155:                        .getClientComponentDir(((ComponentReference) rootNode
1156:                                .getUserObject()).getPath());
1157:
1158:                // check if target node is already part of the tree
1159:                DefaultMutableTreeNode node = findNode(rootNode, rootPath,
1160:                        targetDir);
1161:                if (node != null) {
1162:                    logger.log(Level.FINE, "Target path found in tree");
1163:                    // check if component already exists...
1164:                    for (int i = 0; i < node.getChildCount(); i++) {
1165:                        DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node
1166:                                .getChildAt(i);
1167:                        if (childNode.getUserObject() instanceof  ComponentReference) {
1168:                            logger.log(Level.FINEST, "Compare name '"
1169:                                    + targetName
1170:                                    + "' with '"
1171:                                    + ((ComponentReference) childNode
1172:                                            .getUserObject()).getName() + "'");
1173:                            if (((ComponentReference) childNode.getUserObject())
1174:                                    .getName().equals(targetName)) {
1175:                                // ...and remove it in that case
1176:                                logger.log(Level.FINE,
1177:                                        "Remove node with index " + i);
1178:                                DefaultMutableTreeNode originalNode = new DefaultMutableTreeNode(
1179:                                        childNode.getUserObject());
1180:                                if (!childNode.isLeaf()) {
1181:                                    originalNode
1182:                                            .add(new DefaultMutableTreeNode(
1183:                                                    "[dummy]"));
1184:                                }
1185:                                childNode.removeAllChildren();
1186:                                childNode.setUserObject(new ProgressIndicator(
1187:                                        targetName,
1188:                                        Resources.removeInProgressIcon,
1189:                                        originalNode));
1190:                                ((DefaultTreeModel) tree.getModel())
1191:                                        .nodeChanged(childNode);
1192:                                break;
1193:                            }
1194:                        }
1195:                    }
1196:                } else {
1197:                    logger.log(Level.FINE, "Target path not part of the tree!");
1198:                }
1199:            }
1200:
1201:            public void onComponentRemoveAborted(
1202:                    ContelligentComponentDisplayEvent event) {
1203:                String targetDir = ComponentPath.getClientComponentDir(event
1204:                        .getTarget());
1205:                String targetName = ComponentPath.getComponentName(event
1206:                        .getTarget());
1207:
1208:                DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) tree
1209:                        .getModel().getRoot();
1210:                String rootPath = ComponentPath
1211:                        .getClientComponentDir(((ComponentReference) rootNode
1212:                                .getUserObject()).getPath());
1213:
1214:                revertProgressIndicator(rootNode, rootPath, targetDir,
1215:                        targetName);
1216:            }
1217:
1218:            public void onComponentSelected(
1219:                    ContelligentComponentDisplayEvent event) {
1220:                String targetPath = ComponentPath.toClientComponentPath(event
1221:                        .getTarget());
1222:                if (event.getType() == ContelligentComponentDisplayEvent.COMPONENT_FOLLOW_SERVER
1223:                        && followSelectionAction
1224:                                .getValue(ContelligentAction.STATE) == ContelligentAction.ON) {
1225:                    selectComponent(targetPath);
1226:                }
1227:            }
1228:
1229:            public void onComponentEdit(ContelligentComponentDisplayEvent e) {
1230:                if (previewEditListener) {
1231:                    String targetPath = ComponentPath.toClientComponentPath(e
1232:                            .getTarget());
1233:                    // edit component...
1234:                    try {
1235:                        ContelligentComponent editComponent = ComponentFactory
1236:                                .getInstance().getComponent(targetPath);
1237:                        if (!editComponent.instanceOf(Type.PAGE)) {
1238:                            CreateComponentDialogView editDialog = new CreateComponentDialogView();
1239:                            editDialog.setRootComponent(editComponent);
1240:                            editDialog.setRootGUIDescription(getView()
1241:                                    .getGUIMapping().getGUIDescriptions(
1242:                                            editComponent)[0]);
1243:                            editDialog.setGUIMapping(getView().getGUIMapping());
1244:                            ModuleFrame moduleFrame = new ModuleFrame("edit",
1245:                                    editDialog, true);
1246:                            moduleFrame.pack();
1247:                            Dimension screenDim = Toolkit.getDefaultToolkit()
1248:                                    .getScreenSize();
1249:                            Rectangle winDim = moduleFrame.getBounds();
1250:                            moduleFrame.setLocation(
1251:                                    (screenDim.width - winDim.width) / 2,
1252:                                    (screenDim.height - winDim.height) / 2);
1253:                            moduleFrame.setVisible(true);
1254:                            moduleFrame.toFront();
1255:                        }
1256:                        // check if target node is already part of the tree
1257:                    } catch (ComponentNotFoundException cnfe) {
1258:                        ExceptionDialog.show(cnfe);
1259:                    } catch (ModuleInitException mie) {
1260:                        ExceptionDialog.show(mie);
1261:                    }
1262:                }
1263:            }
1264:
1265:            public void onComponentLocked(ContelligentLockEvent event) {
1266:                String targetPath = ComponentPath.toClientComponentPath(event
1267:                        .getTarget());
1268:                revalidatePath(targetPath);
1269:            }
1270:
1271:            public void onComponentUnlocked(ContelligentLockEvent event) {
1272:                String targetPath = ComponentPath.toClientComponentPath(event
1273:                        .getTarget());
1274:                revalidatePath(targetPath);
1275:            }
1276:
1277:            private void revalidatePath(String targetPath) {
1278:                DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) tree
1279:                        .getModel().getRoot();
1280:                String rootPath = ComponentPath
1281:                        .getClientComponentDir(((ComponentReference) rootNode
1282:                                .getUserObject()).getPath());
1283:                // check if target node is part of the tree
1284:                DefaultMutableTreeNode node = findNode(rootNode, rootPath,
1285:                        targetPath);
1286:                if (node != null) {
1287:                    logger.log(Level.FINE, "Target path found in tree");
1288:                    if (node.getUserObject() instanceof  ComponentReference) {
1289:                        try {
1290:                            ContelligentComponent component = ((ComponentReference) node
1291:                                    .getUserObject()).getComponent();
1292:                            updateLockActions(getSelectedComponent());
1293:                            tree.repaint();
1294:                        } catch (ComponentNotFoundException e) {
1295:                            logger
1296:                                    .log(Level.WARNING, "Component not found!",
1297:                                            e);
1298:                            // try to remove this from the model
1299:                            ((DefaultTreeModel) tree.getModel())
1300:                                    .removeNodeFromParent(node);
1301:                        }
1302:                    }
1303:                }
1304:            }
1305:
1306:            private void updateLockActions(ContelligentComponent component) {
1307:                if (component != null) {
1308:                    if (!vetoByWorkflow()) {
1309:                        if (ComponentFactory.getInstance().isLock(
1310:                                component.getPath(), false)) {
1311:                            Context parentContext = ComponentFactory
1312:                                    .getInstance().getParentContext();
1313:                            if (!getView().isEditInProgress()) {
1314:                                unlockAction
1315:                                        .setEnabled(parentContext == null
1316:                                                || (parentContext.canWrite() && parentContext
1317:                                                        .canDelete()));
1318:                            } else {
1319:                                unlockAction.setEnabled(false);
1320:                            }
1321:                        } else {
1322:                            unlockAction.setEnabled(false);
1323:                        }
1324:                        ComponentFactory.Lock lock = ComponentFactory
1325:                                .getInstance().getLock(component.getPath(),
1326:                                        false);
1327:                        if (lock != null) {
1328:                            lockAction.setEnabled(false);
1329:                        } else {
1330:                            ComponentFactory.Lock sharedLock = ComponentFactory
1331:                                    .getInstance().getLock(component.getPath(),
1332:                                            true);
1333:                            if (sharedLock != null) {
1334:                                if (sharedLock.getContext().equals(
1335:                                        ComponentFactory.getInstance()
1336:                                                .getCurrentContext().getName())) {
1337:                                    lockAction.setEnabled(!getView()
1338:                                            .isEditInProgress());
1339:                                } else {
1340:                                    lockAction.setEnabled(false);
1341:                                }
1342:                            } else {
1343:                                lockAction.setEnabled(!getView()
1344:                                        .isEditInProgress());
1345:                            }
1346:                        }
1347:                    }
1348:                }
1349:            }
1350:
1351:            private void revertProgressIndicator(
1352:                    DefaultMutableTreeNode rootNode, String rootPath,
1353:                    String targetDir, String targetName) {
1354:                // check if target node is already part of the tree
1355:                DefaultMutableTreeNode node = findNode(rootNode, rootPath,
1356:                        targetDir);
1357:                if (node != null) {
1358:                    logger.log(Level.FINE, "Target path found in tree");
1359:                    // check if component already exists...
1360:                    for (int i = 0; i < node.getChildCount(); i++) {
1361:                        DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node
1362:                                .getChildAt(i);
1363:                        if (childNode.getUserObject() instanceof  ProgressIndicator) {
1364:                            ProgressIndicator indicator = (ProgressIndicator) childNode
1365:                                    .getUserObject();
1366:                            if (indicator.getName().equals(targetName)) {
1367:                                // ...and remove it in that case
1368:                                logger.log(Level.FINE,
1369:                                        "Remove node with index " + i);
1370:                                ((DefaultTreeModel) tree.getModel())
1371:                                        .removeNodeFromParent(childNode);
1372:                                // check if this node should be reverted to original
1373:                                // node
1374:                                if (indicator.getNode() != null) {
1375:                                    node.add(indicator.getNode());
1376:                                }
1377:                            }
1378:                            // break;
1379:                        }
1380:                    }
1381:                    ((DefaultTreeModel) tree.getModel())
1382:                            .nodeStructureChanged(node);
1383:                } else {
1384:                    logger.log(Level.FINE, "Target path not part of the tree!");
1385:                }
1386:            }
1387:
1388:            public DefaultMutableTreeNode getChild(DefaultMutableTreeNode node,
1389:                    String childName) {
1390:                for (int i = 0; i < node.getChildCount(); i++) {
1391:                    DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node
1392:                            .getChildAt(i);
1393:                    if (childNode.getUserObject() instanceof  ComponentReference
1394:                            && ((ComponentReference) childNode.getUserObject())
1395:                                    .getName().equals(childName)) {
1396:                        return childNode;
1397:                    } else if (childNode.getUserObject() instanceof  ProgressIndicator
1398:                            && ((ProgressIndicator) childNode.getUserObject())
1399:                                    .getName().equals(childName)) {
1400:                        return childNode;
1401:                    } else if (childNode.getUserObject() instanceof  String
1402:                            && childNode.getUserObject().equals(childName)) {
1403:                        return childNode;
1404:                    }
1405:                }
1406:                return null;
1407:            }
1408:
1409:            public void setDragAndDropActions(int dragAndDropActions) {
1410:                this .dragAndDropActions = dragAndDropActions;
1411:            }
1412:
1413:            public int getDragAndDropActions() {
1414:                return dragAndDropActions;
1415:            }
1416:
1417:            public void setGuiContainer(GUIContainer guiContainer) {
1418:                this .guiContainer = guiContainer;
1419:            }
1420:
1421:            public void setPathSelectionManager(
1422:                    PathSelectionManager pathSelectionManager) {
1423:                this .pathSelectionManager = pathSelectionManager;
1424:                this .pathSelectionManager
1425:                        .addPathSelectionListener(new PathSelectionListener() {
1426:                            public void pathSelected(String path) {
1427:                                selectComponent(path);
1428:                            }
1429:
1430:                            public void selectionManagerClosed() {
1431:                            }
1432:                        });
1433:            }
1434:
1435:            public void setMaxVisibleChildren(int maxVisibleChildren) {
1436:                this .maxVisibleChildren = maxVisibleChildren;
1437:            }
1438:
1439:            public void setBrowseMode(int browseMode) {
1440:                this .browseMode = browseMode;
1441:            }
1442:
1443:            public void setMode(int mode) {
1444:                this .mode = mode;
1445:            }
1446:
1447:            public void setPreviewEditListener(boolean previewEditListener) {
1448:                this .previewEditListener = previewEditListener;
1449:            }
1450:
1451:            public void setFilter(ComponentFilter filter) {
1452:                this .filter = filter;
1453:            }
1454:
1455:            public void setIsRootVisible(boolean isRootVisible) {
1456:                this .isRootVisible = isRootVisible;
1457:            }
1458:
1459:            void setActions(Action[] actions) {
1460:                if (getView() != null) {
1461:                    getView().setActionBundle(ActionBundle.NAVIGATOR_ACTIONS,
1462:                            actions);
1463:                }
1464:            }
1465:
1466:            private void showPopupMenu(MouseEvent e) {
1467:                if (getView() != null) {
1468:                    getView().getMenuAndToolbarComposer().getPopupMenu().show(
1469:                            e.getComponent(), e.getX(), e.getY());
1470:                }
1471:            }
1472:
1473:            private DefaultMutableTreeNode findNode(
1474:                    DefaultMutableTreeNode node, String dir, String searchPath) {
1475:                if (node.getUserObject() instanceof  ComponentReference) {
1476:                    String path = dir;
1477:                    if (dir.equals("/")) {
1478:                        path = path
1479:                                + ((ComponentReference) node.getUserObject())
1480:                                        .getName();
1481:                    } else {
1482:                        path = path
1483:                                + "/"
1484:                                + ((ComponentReference) node.getUserObject())
1485:                                        .getName();
1486:                    }
1487:                    logger.log(Level.FINEST, "compare searchPath '"
1488:                            + searchPath + "' with '" + path + "'");
1489:                    if (path.equals(searchPath)) {
1490:                        // node found
1491:                        return node;
1492:                    } else {
1493:                        // check if one of the child nodes is the requested node
1494:                        for (int i = 0; i < node.getChildCount(); i++) {
1495:                            DefaultMutableTreeNode childNode = findNode(
1496:                                    (DefaultMutableTreeNode) node.getChildAt(i),
1497:                                    path, searchPath);
1498:                            if (childNode != null) {
1499:                                return childNode;
1500:                            }
1501:                        }
1502:                        return null;
1503:                    }
1504:                } else {
1505:                    return null;
1506:                }
1507:            }
1508:
1509:            String findTypeNameOfSelectedComponent() {
1510:                try {
1511:                    final TreePath[] selectionPaths = tree.getSelectionPaths();
1512:                    if (selectionPaths.length > 0) {
1513:                        DefaultMutableTreeNode firstNode = ((DefaultMutableTreeNode) selectionPaths[0]
1514:                                .getLastPathComponent());
1515:                        if (firstNode != null
1516:                                && firstNode.getUserObject() instanceof  ComponentReference) {
1517:                            ContelligentComponent component = ((ComponentReference) firstNode
1518:                                    .getUserObject()).getComponent();
1519:                            if (component.isBlueprint()) {
1520:                                return component.getDefinedBlueprintType();
1521:                            }
1522:                        }
1523:
1524:                    }
1525:                } catch (ComponentNotFoundException cnfe) {
1526:                    ExceptionDialog.show(cnfe);
1527:                }
1528:                return null;
1529:            }
1530:
1531:            void createType(String actionType) {
1532:                DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
1533:                        .getLastSelectedPathComponent();
1534:                // create new component on selected node
1535:                if (node != null
1536:                        && node.getUserObject() instanceof  ComponentReference
1537:                        && guiContainer != null
1538:                        && !getView().isEditInProgress()) {
1539:                    try {
1540:                        // remote add on server
1541:                        ContelligentComponent component = ((ComponentReference) node
1542:                                .getUserObject()).getComponent();
1543:                        TypeWizard wizard = new TypeWizard(component,
1544:                                actionType, getView().getEnvironment());
1545:                        final Type type = wizard.startWizard();
1546:                        final String packageName = wizard.getPackageName();
1547:
1548:                        if (type != null) {
1549:                            // XXX this is not too nice
1550:                            String xml = ContelligentConstants.XML_HEADER
1551:                                    + "<!DOCTYPE type-list PUBLIC \"-//finix AG/contelligent/Type List V1.0/EN\" \"http://www.c1-fse.de/contelligent/dtds/type-list_1_0.dtd\">\n<type-list>\n"
1552:                                    + type.toXML() + "\n</type-list>";
1553:                            ActionResult result = Actions.createType(getView()
1554:                                    .getEnvironment(), packageName, type
1555:                                    .getName(), xml);
1556:                            result.showErrors();
1557:                        }
1558:                    } catch (RemoteActionException e) {
1559:                        ExceptionDialog.show(e);
1560:                    } catch (ComponentNotFoundException cnfe) {
1561:                        ExceptionDialog.show(cnfe);
1562:                    } catch (PackageNotFoundException pnfe) {
1563:                        ExceptionDialog.show(pnfe);
1564:                    }
1565:                }
1566:            }
1567:
1568:            void deleteType(String typeName, boolean force,
1569:                    boolean deleteComponent) {
1570:                int answer = JOptionPane.NO_OPTION;
1571:                if (force) {
1572:                    answer = JOptionPane.showOptionDialog(ContelligentClient
1573:                            .getActiveFrame(), Resources.getLocalString(
1574:                            "delete_blueprint_force_question",
1575:                            new String[] { typeName }), Resources
1576:                            .getLocalString("comfirm_delete"),
1577:                            JOptionPane.YES_NO_OPTION,
1578:                            JOptionPane.QUESTION_MESSAGE, null, new String[] {
1579:                                    Resources.getLocalString("delete"),
1580:                                    Resources.getLocalString("cancel") },
1581:                            Resources.getLocalString("cancel"));
1582:                } else {
1583:                    answer = JOptionPane.showOptionDialog(ContelligentClient
1584:                            .getActiveFrame(), Resources.getLocalString(
1585:                            "delete_blueprint_question",
1586:                            new String[] { typeName }), Resources
1587:                            .getLocalString("comfirm_delete"),
1588:                            JOptionPane.YES_NO_OPTION,
1589:                            JOptionPane.QUESTION_MESSAGE, null, new String[] {
1590:                                    Resources.getLocalString("delete"),
1591:                                    Resources.getLocalString("cancel") },
1592:                            Resources.getLocalString("cancel"));
1593:                }
1594:                if (answer == JOptionPane.YES_OPTION) {
1595:                    try {
1596:                        ActionResult response = Actions.deleteType(getView()
1597:                                .getEnvironment(), typeName, force,
1598:                                deleteComponent);
1599:                        if (response.hasError()) {
1600:                            response
1601:                                    .showErrorsIgnore(Errors.INSTANCE_OF_TYPE_EXISTS);
1602:                        }
1603:                        Collection paths = response.getPaths();
1604:                        if (pathSelectionManager != null && paths.size() != 0) {
1605:                            pathSelectionManager.setPaths(Resources
1606:                                    .getLocalString("blueprint_usages_action"),
1607:                                    paths, new Action[] { new DeleteTypeAction(
1608:                                            this , typeName, true,
1609:                                            deleteComponent) });
1610:                            pathSelectionManager.showPaths();
1611:                        }
1612:                    } catch (RemoteActionException rae) {
1613:                        ExceptionDialog.show(rae);
1614:                    }
1615:                }
1616:            }
1617:
1618:            /**
1619:             * Only compares navigation nodes for next and previous and returns 0 if neither of the arguments is one.
1620:             */
1621:            public int compareNavigation(Object o1, Object o2) {
1622:                if (o1 instanceof  DefaultMutableTreeNode) {
1623:                    Object u1 = ((DefaultMutableTreeNode) o1).getUserObject();
1624:                    if (u1 instanceof  NodeNavigation) {
1625:                        NodeNavigation n1 = (NodeNavigation) u1;
1626:                        if (n1.getText().equals(
1627:                                Resources.getLocalString("next_nodes"))) {
1628:                            return 1;
1629:                        }
1630:                        if (n1.getText().equals(
1631:                                Resources.getLocalString("previous_nodes"))) {
1632:                            return -1;
1633:                        }
1634:                    }
1635:                }
1636:                if (o2 instanceof  DefaultMutableTreeNode) {
1637:                    Object u2 = ((DefaultMutableTreeNode) o2).getUserObject();
1638:                    if (u2 instanceof  NodeNavigation) {
1639:                        NodeNavigation n2 = (NodeNavigation) u2;
1640:                        if (n2.getText().equals(
1641:                                Resources.getLocalString("next_nodes"))) {
1642:                            return -1;
1643:                        }
1644:                        if (n2.getText().equals(
1645:                                Resources.getLocalString("previous_nodes"))) {
1646:                            return 1;
1647:                        }
1648:                    }
1649:                }
1650:                return 0;
1651:            }
1652:
1653:            public Action[] getActions() {
1654:                List<Action> actions = new ArrayList<Action>(50);
1655:                if (browseMode == BROWSABLE_VIEW) {
1656:                    actions.add(upAction);
1657:                }
1658:                if (editable) {
1659:                    actions.add(moveAction);
1660:                    actions.add(moveUpAction);
1661:                    actions.add(moveDownAction);
1662:                    actions.add(moveTopAction);
1663:                    actions.add(moveBottomAction);
1664:                    actions.add(goToAction);
1665:                    actions.add(goToLinkTarget);
1666:                    actions.add(findAction);
1667:                    actions.add(findTextAction);
1668:                    findTextAction.setEnabled(ServerInfo.getInstance()
1669:                            .hasSystemIndex());
1670:                    actions.add(findNameAction);
1671:                    actions.add(renderComponentAction);
1672:                    actions.add(createTypeInstanceAction);
1673:                    actions.add(deleteComponentAction);
1674:                    actions.add(copyComponentAction);
1675:                    actions.add(pasteComponentAction);
1676:                    actions.add(renameComponentAction);
1677:                    actions.add(reloadComponentAction);
1678:                    actions.add(previewAction);
1679:                    if (mode != RESTRICTED_MODE) {
1680:                        actions.add(sortAscendAction);
1681:                        actions.add(sortDescendAction);
1682:                        actions.add(goToBlueprintAction);
1683:                        actions.add(findInstancesAction);
1684:                        actions.add(findUsagesAction);
1685:                        actions.add(newWindowAction);
1686:                        actions.add(lastPreviewAction);
1687:                        actions.add(switchContextAction);
1688:                        actions.add(commitContextAction);
1689:                        actions.add(rollbackSubtreeAction);
1690:                        actions.add(showModifiedComponentsAction);
1691:                        actions.add(showDeletedComponentsAction);
1692:                        actions.add(showLockedComponentsAction);
1693:                        actions.add(followSelectionAction);
1694:                        actions.add(unlinkAction);
1695:                        actions.add(lockAction);
1696:                        actions.add(unlockAction);
1697:                    }
1698:                    if (mode == EXPERT_MODE) {
1699:                        actions.add(typeAction);
1700:                        actions.add(editPreviewAction);
1701:                        actions.add(createTypeAction);
1702:                        actions.add(updateTypeAction);
1703:                        actions.add(deleteTypeOnlyAction);
1704:                        actions.add(renameTypeAction);
1705:                        actions.add(convertTypeAction);
1706:                        if (ServerInfo.getInstance().isCleanupAllowed()) {
1707:                            actions.add(cleanUpBlueprintInstancesAction);
1708:                        }
1709:                        actions.add(addToBlueprintInstancesAction);
1710:                        actions.add(createContextAction);
1711:                        actions.add(editContextACLAction);
1712:                        actions.add(discardContextAction);
1713:                        actions.add(commitSubtreeAction);
1714:                        actions.add(toggleFinalAction);
1715:                        actions.add(exportSubtreeAction);
1716:                        actions.add(subtreeSizeAction);
1717:                        actions.add(importAction);
1718:                        String pType = PreferencesModule
1719:                                .getPublisherPreferences()
1720:                                .get(
1721:                                        PreferencesModule.PUBLISHER_TYPE,
1722:                                        PreferencesModule.DEFAULT_PUBLISHER_TYPE);
1723:                        String pName = PreferencesModule
1724:                                .getPublisherPreferences()
1725:                                .get(
1726:                                        PreferencesModule.PUBLISHER_NAME,
1727:                                        PreferencesModule.DEFAULT_PUBLISHER_NAME);
1728:                        String pId = PreferencesModule
1729:                                .getPublisherPreferences().get(
1730:                                        PreferencesModule.PUBLISHER_ID,
1731:                                        PreferencesModule.DEFAULT_PUBLISHER_ID);
1732:                        if ((pType != null) && (pName != null) && (pId != null)) {
1733:                            if ((pType.length() > 0) && (pName.length() > 0)
1734:                                    && (pId.length() > 0)) {
1735:                                if (pType.equals("basic")) {
1736:                                    actions.add(publisherAction);
1737:                                }
1738:                            }
1739:                        }
1740:                        actions.add(signAction);
1741:                    }
1742:                    actions.add(helpAction);
1743:                }
1744:                return (Action[]) actions.toArray(new Action[0]);
1745:            }
1746:
1747:            /**
1748:             * @return Array of bookmark related actions
1749:             */
1750:            public Action[] getBookmarkActions() {
1751:                // Get Collection of Bookmarks and (Bookmark-) Folders items
1752:                List<Action> actions = new ArrayList<Action>();
1753:                BookmarkManager bookmarkManager = BookmarkManager.getInstance();
1754:
1755:                // add Bookmark related actions
1756:                actions.add(createBookmarkAction);
1757:                actions.add(manageBookmarkAction);
1758:
1759:                actions.addAll(bookmarkManager.getBookmarksAsActionList(this ));
1760:
1761:                return (Action[]) actions.toArray(new Action[actions.size()]);
1762:            }
1763:
1764:            public void setEditable(boolean editable) {
1765:                this .editable = editable;
1766:                setActions(getActions());
1767:            }
1768:
1769:            public void update() {
1770:            }
1771:
1772:            public void rollback() {
1773:            }
1774:
1775:            public void commit() {
1776:            }
1777:
1778:            public void selectComponent(ContelligentComponent component) {
1779:                selectComponent(component.getPath());
1780:            }
1781:
1782:            public void selectComponent(String path) {
1783:                Frame frame = ContelligentClient.getActiveFrame();
1784:                frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1785:                try {
1786:                    TreePath tPath = findPathAndExpand(path);
1787:                    tree.setSelectionPath(tPath);
1788:                    tree.scrollPathToVisible(tPath);
1789:                    activateActions((DefaultMutableTreeNode) tree
1790:                            .getLastSelectedPathComponent());
1791:                } finally {
1792:                    frame.setCursor(Cursor
1793:                            .getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1794:                }
1795:            }
1796:
1797:            public ContelligentComponent getSelectedComponent() {
1798:                final TreePath[] selectionPaths = tree.getSelectionPaths();
1799:
1800:                if (selectionPaths != null && selectionPaths.length > 0) {
1801:                    DefaultMutableTreeNode firstNode = ((DefaultMutableTreeNode) selectionPaths[0]
1802:                            .getLastPathComponent());
1803:                    if (firstNode != null
1804:                            && firstNode.getUserObject() instanceof  ComponentReference) {
1805:                        try {
1806:                            ContelligentComponent component = ((ComponentReference) firstNode
1807:                                    .getUserObject()).getComponent();
1808:                            return component;
1809:                        } catch (ComponentNotFoundException cnfe) {
1810:                            logger.log(Level.SEVERE,
1811:                                    "Selected component could not be found",
1812:                                    cnfe);
1813:                        }
1814:                    }
1815:                }
1816:                return null;
1817:            }
1818:
1819:            protected void updateComponent() {
1820:            }
1821:
1822:            protected void componentChanged(ContelligentEvent event) {
1823:                update();
1824:            }
1825:
1826:            protected void childComponentAdded(ContelligentEvent event) {
1827:            }
1828:
1829:            protected void childComponentRemoved(ContelligentEvent event) {
1830:            }
1831:
1832:            protected void childComponentChanged(ContelligentEvent event) {
1833:            }
1834:
1835:            protected void descendentComponentChanged(ContelligentEvent event) {
1836:            }
1837:
1838:            private TreePath findPathAndExpand(String componentPath) {
1839:                DefaultMutableTreeNode currentNode = rootNode;
1840:                List<DefaultMutableTreeNode> path = new ArrayList<DefaultMutableTreeNode>();
1841:                path.add(currentNode);
1842:                // always make sure we stay under the root component
1843:                if (componentPath.indexOf(rootComponent.getPath()) != 0) {
1844:                    componentPath = rootComponent.getPath();
1845:                }
1846:                // make component path relative to root component...
1847:                String relativePath = componentPath.substring(rootComponent
1848:                        .getPath().length());
1849:                StringTokenizer tokenizer = new StringTokenizer(relativePath,
1850:                        "/");
1851:                while (tokenizer.hasMoreTokens()) {
1852:                    if (!path.isEmpty()) {
1853:                        tree.expandPath(new TreePath(path.toArray()));
1854:                    }
1855:                    String token = tokenizer.nextToken();
1856:                    DefaultMutableTreeNode childNode = addChildToPath(path,
1857:                            currentNode, token);
1858:                    if (childNode == null) {
1859:                        // check if children is existing as subcomponent but not visible
1860:                        // as tree node...
1861:                        Object userObject = currentNode.getUserObject();
1862:                        if (userObject instanceof  ComponentReference) {
1863:                            try {
1864:                                ContelligentComponent component = ((ComponentReference) userObject)
1865:                                        .getComponent();
1866:                                int index = component
1867:                                        .indexOfSubcomponent(token);
1868:                                int totalSize = component.getSubcomponents()
1869:                                        .size();
1870:                                if (index != -1) {
1871:                                    // add subcomponents as nodes that surround the
1872:                                    // wanted subcomponent
1873:                                    int start = 0;
1874:                                    if (index + (maxVisibleChildren / 2) >= totalSize) {
1875:                                        // If the index is near the bottom, simply put the pager as close to the end
1876:                                        // as possible. (Not before the start of the list though)
1877:                                        start = Math.max(0, totalSize
1878:                                                - maxVisibleChildren);
1879:                                    } else {
1880:                                        // Otherwise, just try for best fit. (Again, not before the start of the list)
1881:                                        start = Math.max(0, index
1882:                                                - maxVisibleChildren / 2);
1883:                                    }
1884:                                    addSubcomponents(component, currentNode,
1885:                                            start);
1886:                                    ((DefaultTreeModel) tree.getModel())
1887:                                            .nodeStructureChanged(currentNode);
1888:                                }
1889:                            } catch (ComponentNotFoundException e) {
1890:                                // ignore
1891:                            }
1892:                        }
1893:                        childNode = addChildToPath(path, currentNode, token);
1894:                    }
1895:                    currentNode = childNode;
1896:                    if (currentNode == null)
1897:                        break;
1898:                }
1899:                return new TreePath(path.toArray());
1900:            }
1901:
1902:            private DefaultMutableTreeNode addChildToPath(
1903:                    List<DefaultMutableTreeNode> path,
1904:                    DefaultMutableTreeNode currentNode, String token) {
1905:                int max = currentNode.getChildCount();
1906:                for (int i = 0; i < max; i++) {
1907:                    Object child = currentNode.getChildAt(i);
1908:                    if (token.equals(child.toString())) {
1909:                        if (child instanceof  DefaultMutableTreeNode) {
1910:                            currentNode = (DefaultMutableTreeNode) child;
1911:                        }
1912:                        path.add(currentNode);
1913:                        return currentNode;
1914:                    }
1915:                }
1916:                return null;
1917:            }
1918:
1919:            synchronized void addSubcomponents(ContelligentComponent component,
1920:                    DefaultMutableTreeNode node) {
1921:                addSubcomponents(component, node, 0);
1922:            }
1923:
1924:            // XXX synchronizing whole ExplorerEditor surely is too much, but this fixes
1925:            // concurrent modification of
1926:            // "component.getSubcomponents()"
1927:            private synchronized void addSubcomponents(
1928:                    ContelligentComponent component,
1929:                    DefaultMutableTreeNode node, int start) {
1930:                boolean isRoot = (component == rootComponent);
1931:
1932:                GUI[] gui = GUIFactory.getInstance().getGUI(component,
1933:                        getView());
1934:
1935:                // remove everything, but indicators
1936:                boolean needsRemove = true;
1937:                while (needsRemove) {
1938:                    needsRemove = false;
1939:                    for (int i = node.getChildCount() - 1; i >= 0; i--) {
1940:                        DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node
1941:                                .getChildAt(i);
1942:                        if (!(childNode.getUserObject() instanceof  ProgressIndicator)) {
1943:                            node.remove(i);
1944:                            needsRemove = true;
1945:                            break;
1946:                        }
1947:                    }
1948:                }
1949:                if (start == 0 && incrementalSearchString != null
1950:                        && incrementalSearchString.length() > 0) {
1951:                    // find start if search is used
1952:                    int counter = 0;
1953:                    search: while (true) {
1954:                        for (Iterator i = component.getSubcomponents()
1955:                                .iterator(); i.hasNext();) {
1956:                            String subComponentName = (String) i.next();
1957:                            try {
1958:                                ContelligentComponent subcomponent = ComponentFactory
1959:                                        .getInstance().getComponent(
1960:                                                component.getPath() + "/"
1961:                                                        + subComponentName);
1962:                                if (filter.accept(subcomponent)) {
1963:                                    if (subComponentName
1964:                                            .startsWith(incrementalSearchString)) {
1965:                                        start = counter;
1966:                                        break search;
1967:                                    }
1968:                                    counter++;
1969:                                }
1970:                            } catch (ComponentNotFoundException e) {
1971:                                logger.log(Level.SEVERE,
1972:                                        "ContelligentComponent not found!", e);
1973:                            }
1974:                        }
1975:                        Toolkit.getDefaultToolkit().beep();
1976:                        incrementalSearchString = incrementalSearchString
1977:                                .substring(0,
1978:                                        incrementalSearchString.length() - 1);
1979:                        if (incrementalSearchString.length() == 0)
1980:                            break;
1981:                        counter = 0;
1982:                    }
1983:                    if (start < maxVisibleChildren)
1984:                        start = 0;
1985:                }
1986:
1987:                if (!gui[0].hidesSubcomponents()
1988:                        || (mode != RESTRICTED_MODE && browseMode == TREE_VIEW)
1989:                        || isRoot) {
1990:                    if (node.getUserObject() instanceof  ComponentReference) {
1991:                        ((ComponentReference) node.getUserObject())
1992:                                .setStart(start);
1993:                    }
1994:                    if (start > 0) {
1995:                        node.add(new DefaultMutableTreeNode(new NodeNavigation(
1996:                                node, component, Resources
1997:                                        .getLocalString("previous_nodes"),
1998:                                Resources.previousIcon, Math.max(0, start
1999:                                        - maxVisibleChildren))));
2000:                    }
2001:                    int counter = 0;
2002:                    DefaultMutableTreeNode childNode = null, firstChild = null;
2003:                    boolean nodeSelected = false;
2004:                    for (Iterator i = component.getSubcomponents().iterator(); i
2005:                            .hasNext();) {
2006:                        String subComponentName = (String) i.next();
2007:                        try {
2008:                            ContelligentComponent subcomponent = ComponentFactory
2009:                                    .getInstance().getComponent(
2010:                                            component.getPath() + "/"
2011:                                                    + subComponentName);
2012:                            if (filter.accept(subcomponent)) {
2013:                                if (start <= counter
2014:                                        && counter - start <= maxVisibleChildren) {
2015:                                    if (counter - start == maxVisibleChildren) {
2016:                                        node
2017:                                                .add(new DefaultMutableTreeNode(
2018:                                                        new NodeNavigation(
2019:                                                                node,
2020:                                                                component,
2021:                                                                Resources
2022:                                                                        .getLocalString("next_nodes"),
2023:                                                                Resources.nextIcon,
2024:                                                                counter)));
2025:                                        break;
2026:                                    }
2027:                                    // add subcomponents to tree
2028:                                    childNode = createChildNode(subcomponent);
2029:                                    if (firstChild == null)
2030:                                        firstChild = childNode;
2031:                                    node.add(childNode);
2032:                                    // select first matching child if searchterm is set
2033:                                    if (!nodeSelected
2034:                                            && incrementalSearchString != null
2035:                                            && incrementalSearchString.length() > 0
2036:                                            && subComponentName
2037:                                                    .startsWith(incrementalSearchString)) {
2038:                                        nodeSelected = true;
2039:                                        selectedNode = childNode;
2040:                                    }
2041:                                }
2042:                                counter++;
2043:                            }
2044:                        } catch (ComponentNotFoundException e) {
2045:                            logger.log(Level.SEVERE,
2046:                                    "ContelligentComponent could not be added",
2047:                                    e);
2048:                            ExceptionDialog.show(e);
2049:                        }
2050:                    }
2051:                }
2052:            }
2053:
2054:            private DefaultMutableTreeNode createChildNode(
2055:                    ContelligentComponent component) {
2056:                DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(
2057:                        new ComponentReference(component));
2058:                GUI[] gui = GUIFactory.getInstance().getGUI(component,
2059:                        getView());
2060:                if ((!gui[0].hidesSubcomponents() || mode != RESTRICTED_MODE)
2061:                        && browseMode == TREE_VIEW) {
2062:                    // has subcomponents?
2063:                    if (component.hasSubcomponents()
2064:                            && !component.instanceOf(Type.LARGE_FOLDER)) {
2065:                        childNode.add(new DefaultMutableTreeNode(
2066:                                "[subcomponents]"));
2067:                    }
2068:                }
2069:                return childNode;
2070:            }
2071:
2072:            /**
2073:             * Returns the clipboard to use for cut/copy/paste.
2074:             */
2075:            Clipboard getClipboard(JComponent c) {
2076:                if (canAccessSystemClipboard()) {
2077:                    return c.getToolkit().getSystemClipboard();
2078:                }
2079:                Clipboard clipboard = (Clipboard) sun.awt.AppContext
2080:                        .getAppContext().get(SandboxClipboardKey);
2081:                if (clipboard == null) {
2082:                    clipboard = new Clipboard(
2083:                            "Sandboxed ContelligentComponent Clipboard");
2084:                    sun.awt.AppContext.getAppContext().put(SandboxClipboardKey,
2085:                            clipboard);
2086:                }
2087:                return clipboard;
2088:            }
2089:
2090:            /**
2091:             * Returns true if it is safe to access the system Clipboard. If the environment is headless or the security manager
2092:             * does not allow access to the system clipboard, a private clipboard is used.
2093:             */
2094:            boolean canAccessSystemClipboard() {
2095:                if (canAccessSystemClipboard) {
2096:                    if (GraphicsEnvironment.isHeadless()) {
2097:                        canAccessSystemClipboard = false;
2098:                        return false;
2099:                    }
2100:
2101:                    SecurityManager sm = System.getSecurityManager();
2102:                    if (sm != null) {
2103:                        try {
2104:                            sm.checkSystemClipboardAccess();
2105:                            return true;
2106:                        } catch (SecurityException se) {
2107:                            canAccessSystemClipboard = false;
2108:                            return false;
2109:                        }
2110:                    }
2111:                    return true;
2112:                }
2113:                return false;
2114:            }
2115:
2116:            public void onTypeCreated(TypeEvent e) {
2117:                createTypeInstanceAction.calculateMenuStructure();
2118:                getView().getMenuAndToolbarComposer().compose();
2119:                String blueprintPath = e.getBlueprintPath();
2120:                if (blueprintPath != null) {
2121:                    // reload newly defined blueprint component as it now needs a sign
2122:                    // of being a blueprint
2123:                    ComponentFactory
2124:                            .getInstance()
2125:                            .fireComponentChangeEvent(
2126:                                    new ContelligentComponentEvent(
2127:                                            this ,
2128:                                            blueprintPath,
2129:                                            ContelligentComponentEvent.COMPONENT_CHANGED));
2130:                }
2131:                // XXX force update of gui container to display possibly modified type
2132:                if (guiContainer != null)
2133:                    guiContainer.setSelectedComponent(guiContainer
2134:                            .getSelectedComponent());
2135:            }
2136:
2137:            public void onTypeChanged(TypeEvent e) {
2138:                createTypeInstanceAction.calculateMenuStructure();
2139:                getView().getMenuAndToolbarComposer().compose();
2140:                String blueprintPath = e.getBlueprintPath();
2141:                if (blueprintPath != null) {
2142:                    // reload newly defined blueprint component as it now needs a sign
2143:                    // of being a blueprint
2144:                    ComponentFactory
2145:                            .getInstance()
2146:                            .fireComponentChangeEvent(
2147:                                    new ContelligentComponentEvent(
2148:                                            this ,
2149:                                            blueprintPath,
2150:                                            ContelligentComponentEvent.COMPONENT_CHANGED));
2151:                }
2152:                // XXX force update of gui container to display possibly modified type
2153:                if (guiContainer != null)
2154:                    guiContainer.setSelectedComponent(guiContainer
2155:                            .getSelectedComponent());
2156:
2157:            }
2158:
2159:            public void onTypeDeleted(TypeEvent e) {
2160:                createTypeInstanceAction.calculateMenuStructure();
2161:                getView().getMenuAndToolbarComposer().compose();
2162:                String blueprintPath = e.getBlueprintPath();
2163:                if (blueprintPath != null) {
2164:                    if (ComponentFactory.getInstance().isCached(blueprintPath)) {
2165:                        // reload newly defined blueprint component as it now needs a
2166:                        // sign of being a blueprint
2167:                        ComponentFactory
2168:                                .getInstance()
2169:                                .fireComponentChangeEvent(
2170:                                        new ContelligentComponentEvent(
2171:                                                this ,
2172:                                                blueprintPath,
2173:                                                ContelligentComponentEvent.COMPONENT_CHANGED));
2174:                    }
2175:                }
2176:                // XXX force update of gui container to display possibly modified type
2177:                if (guiContainer != null)
2178:                    guiContainer.setSelectedComponent(guiContainer
2179:                            .getSelectedComponent());
2180:            }
2181:
2182:            private final class ExplorerMouseAdapter extends MouseAdapter {
2183:                public void mouseReleased(MouseEvent e) {
2184:                    if (e.isPopupTrigger() && editable) {
2185:                        showPopupMenu(e);
2186:                    }
2187:                }
2188:
2189:                public void mouseClicked(MouseEvent e) {
2190:                    // Alt key is added to the mask here to allow 9.0 style node
2191:                    // selection by holding down alt
2192:                    if (e.getButton() == MouseEvent.BUTTON1
2193:                            && ((e.getModifiersEx() & (MouseEvent.SHIFT_DOWN_MASK
2194:                                    | MouseEvent.CTRL_DOWN_MASK | MouseEvent.ALT_DOWN_MASK)) == 0)) {
2195:                        incrementalSearchString = "";
2196:
2197:                        TreePath path = tree.getPathForLocation(e.getX(), e
2198:                                .getY());
2199:                        if (path != null) {
2200:                            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
2201:                                    .getLastPathComponent();
2202:                            try {
2203:                                if (node.getUserObject() instanceof  ProgressIndicator) {
2204:                                    return;
2205:                                }
2206:                                if (node.getUserObject() instanceof  NodeNavigation) {
2207:                                    navigate(node);
2208:                                    return;
2209:                                }
2210:                                if (!(node.getUserObject() instanceof  ComponentReference)) {
2211:                                    logger
2212:                                            .log(
2213:                                                    Level.SEVERE,
2214:                                                    "User object in node ["
2215:                                                            + node
2216:                                                            + "] is not of type ComponentReference");
2217:                                    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node
2218:                                            .getParent();
2219:                                    node.removeFromParent();
2220:                                    ((DefaultTreeModel) tree.getModel())
2221:                                            .reload(parent);
2222:                                    tree.validate();
2223:                                    return;
2224:                                }
2225:                                ContelligentComponent component = ((ComponentReference) node
2226:                                        .getUserObject()).getComponent();
2227:                                setCursor(Cursor
2228:                                        .getPredefinedCursor(Cursor.WAIT_CURSOR));
2229:                                if (guiContainer != null
2230:                                        && !getView().isEditInProgress()) {
2231:                                    guiContainer.renderSelectedComponent();
2232:                                }
2233:                                // Browse deeper...
2234:                                browseRootComponent = ((ComponentReference) node
2235:                                        .getUserObject()).getComponent();
2236:                                GUI[] gui = GUIFactory.getInstance().getGUI(
2237:                                        browseRootComponent, getView());
2238:                                if (browseMode == BROWSABLE_VIEW
2239:                                        && (mode != RESTRICTED_MODE || !gui[0]
2240:                                                .hidesSubcomponents())) {
2241:                                    setCursor(Cursor
2242:                                            .getPredefinedCursor(Cursor.WAIT_CURSOR));
2243:                                    upAction.setEnabled(true);
2244:                                    setActions(getActions());
2245:                                    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(
2246:                                            new ComponentReference(
2247:                                                    browseRootComponent));
2248:                                    addSubcomponents(browseRootComponent,
2249:                                            rootNode);
2250:                                    tree
2251:                                            .setModel(new DefaultTreeModel(
2252:                                                    rootNode));
2253:                                }
2254:                                setCursor(Cursor.getDefaultCursor());
2255:                            } catch (ComponentNotFoundException cnfe) {
2256:                                logger.log(Level.SEVERE,
2257:                                        "ContelligentComponent not found at node ["
2258:                                                + node + "]", cnfe);
2259:                            }
2260:                        }
2261:                    }
2262:                }
2263:
2264:                public void mousePressed(MouseEvent e) {
2265:                    if (e.isPopupTrigger() && editable) {
2266:                        showPopupMenu(e);
2267:                    }
2268:                    TreePath path = tree.getPathForLocation(e.getX(), e.getY());
2269:                    if (path != null) {
2270:                        if (tree.getSelectionPaths() != null
2271:                                && tree.getSelectionPaths().length > 0) {
2272:                            if ((e.getModifiersEx() & (MouseEvent.SHIFT_DOWN_MASK | MouseEvent.CTRL_DOWN_MASK)) == 0) {
2273:                                // Always reset selection on normal click, including
2274:                                // right mouse button
2275:                                tree.clearSelection();
2276:                                tree.setSelectionPath(path);
2277:                            } else {
2278:                                // prevent selection of nodes with different parents (to
2279:                                // enable multiselect)
2280:                                for (int i = 0; i < tree.getSelectionPaths().length; i++) {
2281:                                    if (!path.getParentPath().equals(
2282:                                            tree.getSelectionPaths()[i]
2283:                                                    .getParentPath())) {
2284:                                        tree.clearSelection();
2285:                                        tree.setSelectionPath(path);
2286:                                        break;
2287:                                    }
2288:                                }
2289:                            }
2290:                        }
2291:                        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
2292:                                .getLastPathComponent();
2293:                        try {
2294:                            Object o = node.getUserObject();
2295:                            if (o instanceof  ComponentReference) {
2296:                                // Ignore NodeNavigation objects here
2297:                                ContelligentComponent component = ((ComponentReference) o)
2298:                                        .getComponent();
2299:
2300:                                activateActions(node);
2301:                                if (guiContainer != null)
2302:                                    guiContainer
2303:                                            .setSelectedComponent(component);
2304:                            }
2305:                        } catch (ComponentNotFoundException cnfe) {
2306:                            logger.log(Level.SEVERE,
2307:                                    "ContelligentComponent not found at node ["
2308:                                            + node + "]", cnfe);
2309:                        }
2310:                    }
2311:                }
2312:
2313:            }
2314:
2315:            void navigate(DefaultMutableTreeNode node) {
2316:                NodeNavigation navigation = (NodeNavigation) node
2317:                        .getUserObject();
2318:                addSubcomponents(navigation.getComponent(), navigation
2319:                        .getNode(), navigation.getStart());
2320:                ((DefaultTreeModel) tree.getModel()).reload(navigation
2321:                        .getNode());
2322:                tree.scrollPathToVisible(new TreePath(node.getPath()));
2323:                tree.validate();
2324:            }
2325:
2326:            private void activateActions(DefaultMutableTreeNode node) {
2327:                if (node == null)
2328:                    return;
2329:                try {
2330:                    if (!vetoByWorkflow()) {
2331:                        findInstancesAction.update();
2332:                        goToBlueprintAction.update();
2333:                        updateTypeAction.update();
2334:                        createTypeAction.update();
2335:                        deleteTypeOnlyAction.update();
2336:                        renameTypeAction.update();
2337:                        convertTypeAction.update();
2338:                        if (ServerInfo.getInstance().isCleanupAllowed()) {
2339:                            cleanUpBlueprintInstancesAction.update();
2340:                        }
2341:                        addToBlueprintInstancesAction.update();
2342:                    }
2343:                    helpAction.update();
2344:                    // toggle actions
2345:                    ContelligentComponent component = ((ComponentReference) node
2346:                            .getUserObject()).getComponent();
2347:                    if (component.getType().getName().equals(Type.LINK)) {
2348:                        goToLinkTarget.setEnabled(true);
2349:                    } else {
2350:                        goToLinkTarget.setEnabled(false);
2351:                    }
2352:                    // lock actions
2353:                    updateLockActions(component);
2354:                    // get parent (to check for sorted context)
2355:                    if (!vetoByWorkflow() && component.hasParent()) {
2356:                        ContelligentComponent parent = ComponentFactory
2357:                                .getInstance().getComponent(
2358:                                        component.getParentPath());
2359:                        if (parent.instanceOf(Type.SORTED_FOLDER)) {
2360:                            sortAscendAction.setEnabled(false);
2361:                            sortDescendAction.setEnabled(false);
2362:                            // check for first child
2363:                            if ((DefaultMutableTreeNode) node.getParent() != null) {
2364:                                if ((((DefaultMutableTreeNode) node.getParent())
2365:                                        .getFirstChild() == node)) {
2366:                                    moveUpAction.setEnabled(false);
2367:                                    moveTopAction.setEnabled(false);
2368:                                } else {
2369:                                    moveUpAction.setEnabled(!getView()
2370:                                            .isEditInProgress());
2371:                                    moveTopAction.setEnabled(!getView()
2372:                                            .isEditInProgress());
2373:                                }
2374:                                // check for last child
2375:                                if ((((DefaultMutableTreeNode) node.getParent())
2376:                                        .getLastChild() == node)) {
2377:                                    moveDownAction.setEnabled(false);
2378:                                    moveBottomAction.setEnabled(false);
2379:                                } else {
2380:                                    moveDownAction.setEnabled(!getView()
2381:                                            .isEditInProgress());
2382:                                    moveBottomAction.setEnabled(!getView()
2383:                                            .isEditInProgress());
2384:                                }
2385:                            }
2386:                        } else {
2387:                            moveUpAction.setEnabled(false);
2388:                            moveDownAction.setEnabled(false);
2389:                            moveTopAction.setEnabled(false);
2390:                            moveBottomAction.setEnabled(false);
2391:                            sortAscendAction.setEnabled(true);
2392:                            sortDescendAction.setEnabled(true);
2393:                        }
2394:                        renameComponentAction.setEnabled((!getView()
2395:                                .isEditInProgress())
2396:                                && ComponentFactory.getInstance()
2397:                                        .getCurrentContext().canWrite());
2398:                    } else {
2399:                        moveUpAction.setEnabled(false);
2400:                        moveDownAction.setEnabled(false);
2401:                        moveTopAction.setEnabled(false);
2402:                        moveBottomAction.setEnabled(false);
2403:                        sortAscendAction.setEnabled(false);
2404:                        sortDescendAction.setEnabled(false);
2405:                        renameComponentAction.setEnabled(false);
2406:                    }
2407:                    if (!vetoByWorkflow()) {
2408:                        pasteComponentAction.setEnabled(componentToCopy != null
2409:                                && component.allowsSubcomponents());
2410:                        deleteComponentAction.setEnabled(!getView()
2411:                                .isEditInProgress()
2412:                                && ComponentFactory.getInstance()
2413:                                        .getCurrentContext().canDelete());
2414:                        toggleFinalAction.setEnabled((!getView()
2415:                                .isEditInProgress())
2416:                                && (ComponentFactory.getInstance()
2417:                                        .getCurrentContext().isRootContext()));
2418:                        editPreviewAction.setEnabled(!getView()
2419:                                .isEditInProgress());
2420:                        publisherAction.setEnabled(!getView()
2421:                                .isEditInProgress());
2422:                        signAction.setEnabled(!getView().isEditInProgress());
2423:                        tree.setDropEnabled(!getView().isEditInProgress());
2424:                    } else {
2425:                        pasteComponentAction.setEnabled(false);
2426:                        deleteComponentAction.setEnabled(false);
2427:                        toggleFinalAction.setEnabled(false);
2428:                        editPreviewAction.setEnabled(false);
2429:                        publisherAction.setEnabled(false);
2430:                        signAction.setEnabled(false);
2431:                        tree.setDropEnabled(false);
2432:                    }
2433:                    if (component.isReadOnly() || !component.canWrite()) {
2434:                        moveUpAction.setEnabled(false);
2435:                        moveDownAction.setEnabled(false);
2436:                        moveTopAction.setEnabled(false);
2437:                        moveBottomAction.setEnabled(false);
2438:                        pasteComponentAction.setEnabled(false);
2439:                        deleteComponentAction.setEnabled(false);
2440:                        lockAction.setEnabled(false);
2441:                        // Allow unlock just in case...
2442:                        createTypeInstanceAction.setEnabled(false);
2443:                        unlinkAction.setEnabled(false);
2444:                        createTypeAction.setEnabled(false);
2445:                        updateTypeAction.setEnabled(false);
2446:                        deleteTypeOnlyAction.setEnabled(false);
2447:                        renameComponentAction.setEnabled(false);
2448:                        toggleFinalAction.setEnabled(false);
2449:                        editPreviewAction.setEnabled(false);
2450:                        publisherAction.setEnabled(false);
2451:                        signAction.setEnabled(false);
2452:                        convertTypeAction.setEnabled(false);
2453:                    } else {
2454:                        if (!(vetoByWorkflow() || !ComponentFactory
2455:                                .getInstance().getCurrentContext().canWrite())) {
2456:                            // These don't seem to be properly reset elsewhere
2457:                            createTypeInstanceAction.setEnabled(!getView()
2458:                                    .isEditInProgress());
2459:                            unlinkAction.setEnabled(!getView()
2460:                                    .isEditInProgress());
2461:                        }
2462:                    }
2463:                    if (component.getPath().equals("")) {
2464:                        deleteComponentAction.setEnabled(false);
2465:                        unlinkAction.setEnabled(false);
2466:                        createTypeAction.setEnabled(false);
2467:                        renameComponentAction.setEnabled(false);
2468:                        toggleFinalAction.setEnabled(false);
2469:                        editPreviewAction.setEnabled(false);
2470:                        publisherAction.setEnabled(false);
2471:                        signAction.setEnabled(false);
2472:                        convertTypeAction.setEnabled(false);
2473:                    }
2474:                } catch (ComponentNotFoundException e) {
2475:                    logger.log(Level.WARNING, "Component not found!", e);
2476:                }
2477:            }
2478:
2479:            private boolean vetoByWorkflow() {
2480:                return (getView().getAllowEditInWorkflowOnly() && ComponentFactory
2481:                        .getInstance().getCurrentContext().isRootContext());
2482:            }
2483:
2484:            void updateActiveActionsCheckingWorkflowAndACL() {
2485:                Context currentContext = ComponentFactory.getInstance()
2486:                        .getCurrentContext();
2487:                Context parentContext = ComponentFactory.getInstance()
2488:                        .getParentContext();
2489:
2490:                if (parentContext != null) {
2491:                    commitSubtreeAction.setEnabled(parentContext.canWrite()
2492:                            && getView().getAllowCommit());
2493:                    commitContextAction.setEnabled(parentContext.canWrite()
2494:                            && getView().getAllowCommit());
2495:                    rollbackSubtreeAction
2496:                            .setEnabled(currentContext.canDelete());
2497:                    discardContextAction.setEnabled(currentContext.canDelete());
2498:                    showModifiedComponentsAction.setEnabled(true);
2499:                    showDeletedComponentsAction.setEnabled(true);
2500:                    editContextACLAction.setEnabled(true);
2501:                } else {
2502:                    discardContextAction.setEnabled(false);
2503:                    rollbackSubtreeAction.setEnabled(false);
2504:                    commitContextAction.setEnabled(false);
2505:                    commitSubtreeAction.setEnabled(false);
2506:                    showModifiedComponentsAction.setEnabled(false);
2507:                    showDeletedComponentsAction.setEnabled(false);
2508:                    editContextACLAction.setEnabled(true);
2509:                }
2510:                if (vetoByWorkflow() || !currentContext.canDelete()) {
2511:                    deleteComponentAction.setEnabled(false);
2512:                } else {
2513:                    deleteComponentAction.setEnabled(true);
2514:                }
2515:                if (vetoByWorkflow()
2516:                        || (parentContext != null && (!parentContext.canWrite() || !parentContext
2517:                                .canDelete()))) {
2518:                    unlockAction.setEnabled(false);
2519:                } else {
2520:                    unlockAction.setEnabled(!getView().isEditInProgress());
2521:                }
2522:                if (vetoByWorkflow()) {
2523:                    lockAction.setEnabled(false);
2524:                } else {
2525:                    lockAction.setEnabled(!getView().isEditInProgress());
2526:                }
2527:
2528:                if (vetoByWorkflow() || !currentContext.canWrite()) {
2529:                    tree.setDragEnabled(false);
2530:                    tree.setDropEnabled(false);
2531:                    renameComponentAction.setEnabled(false);
2532:                    pasteComponentAction.setEnabled(false);
2533:                    copyComponentAction.setEnabled(false);
2534:                    toggleFinalAction.setEnabled(false);
2535:                    createTypeAction.setEnabled(false);
2536:                    updateTypeAction.setEnabled(false);
2537:                    convertTypeAction.setEnabled(false);
2538:                    moveUpAction.setEnabled(false);
2539:                    moveDownAction.setEnabled(false);
2540:                    sortAscendAction.setEnabled(false);
2541:                    sortDescendAction.setEnabled(false);
2542:                    editPreviewAction.setEnabled(false);
2543:                    createTypeInstanceAction.setEnabled(false);
2544:                    createTypeInstanceAction.calculateMenuStructure();
2545:                    tree.setDragEnabled(false);
2546:                    findInstancesAction.update();
2547:                    goToBlueprintAction.update();
2548:                    createTypeAction.setEnabled(false);
2549:                    deleteTypeOnlyAction.setEnabled(false);
2550:                    renameTypeAction.setEnabled(false);
2551:                    convertTypeAction.setEnabled(false);
2552:                    addToBlueprintInstancesAction.setEnabled(false);
2553:                    if (ServerInfo.getInstance().isCleanupAllowed()) {
2554:                        cleanUpBlueprintInstancesAction.setEnabled(false);
2555:                    }
2556:                } else {
2557:                    tree.setDragEnabled(true);
2558:                    tree.setDropEnabled(!getView().isEditInProgress());
2559:                    copyComponentAction.setEnabled(true);
2560:                    createTypeInstanceAction.setEnabled(!getView()
2561:                            .isEditInProgress());
2562:                    createTypeInstanceAction.calculateMenuStructure();
2563:                    editPreviewAction.setEnabled(!getView().isEditInProgress());
2564:                    findInstancesAction.update();
2565:                    goToBlueprintAction.update();
2566:                    createTypeAction.update();
2567:                    deleteTypeOnlyAction.update();
2568:                    renameTypeAction.update();
2569:                    convertTypeAction.update();
2570:                    addToBlueprintInstancesAction.update();
2571:                    if (ServerInfo.getInstance().isCleanupAllowed()) {
2572:                        cleanUpBlueprintInstancesAction.update();
2573:                    }
2574:                }
2575:            }
2576:
2577:            void preview(String mode, boolean useLastPreviewConfiguration) {
2578:                // preview
2579:                if (getSelectedComponent() != null) {
2580:                    String extension = "html";
2581:
2582:                    // Grab the actual extension for Binary components.
2583:                    // Note: This would not work for Fragment components but since
2584:                    // we are only doing this for Binaries anyway, we dont have
2585:                    // to care. Also, it always retrieves the extension from the default
2586:                    // category instead of whatever will be selected through the
2587:                    // preview.
2588:                    // We just assume that all categories of a Binary will always
2589:                    // contain
2590:                    // the same type of file.
2591:                    String resourceIdentifier = ContelligentCategoryManager
2592:                            .createUniqueCategoryIdentifier(
2593:                                    getSelectedComponent()
2594:                                            .getContentCategories(), null);
2595:                    // System.out.println("Current identifier is:
2596:                    // ["+resourceIdentifier+"]");
2597:                    Object resource = getSelectedComponent().getResource(
2598:                            resourceIdentifier);
2599:                    if (resource instanceof  ContelligentBinaryResource) {
2600:                        extension = ((ContelligentBinaryResource) resource)
2601:                                .getExtension();
2602:                    }
2603:
2604:                    String previewURL = ServerInfo.getInstance()
2605:                            .getAnonServer()
2606:                            + getSelectedComponent().getPath()
2607:                            + "."
2608:                            + extension
2609:                            + "?"
2610:                            + Session.getInstance()
2611:                                    .getContelligentSessionHandle()
2612:                            + "&previewMode=" + mode;
2613:                    if (PreviewManager.getInstance().getPreviews().size() > 0) {
2614:                        String date, path;
2615:                        String lastSelectedPreview = PreferencesModule
2616:                                .getPreferences().get(
2617:                                        PreferencesModule.PREVIEW_NAME,
2618:                                        PreferencesModule.DEFAULT_PREVIEW_NAME);
2619:                        if (useLastPreviewConfiguration) {
2620:                            List previewList = PreviewManager.getInstance()
2621:                                    .getPreviews();
2622:                            PreviewManager.Preview preview = (PreviewManager.Preview) previewList
2623:                                    .get(0);
2624:                            for (Iterator i = previewList.iterator(); i
2625:                                    .hasNext();) {
2626:                                PreviewManager.Preview pre2 = (PreviewManager.Preview) i
2627:                                        .next();
2628:                                if (pre2.getDisplay().equals(
2629:                                        lastSelectedPreview)) {
2630:                                    preview = pre2;
2631:                                }
2632:                            }
2633:                            date = preview.getDate();
2634:                            path = preview.getPath();
2635:                        } else {
2636:                            PreviewOptionPane previewPane = new PreviewOptionPane(
2637:                                    PreviewManager.getInstance().getPreviews());
2638:                            if (previewPane.showDialog(lastSelectedPreview) == JOptionPane.OK_OPTION) {
2639:                                date = previewPane.getDate();
2640:                                path = previewPane.getPath();
2641:                                lastSelectedPreview = previewPane
2642:                                        .getSelectedPreviewName();
2643:                                PreferencesModule.getPreferences().put(
2644:                                        PreferencesModule.PREVIEW_NAME,
2645:                                        lastSelectedPreview);
2646:                            } else {
2647:                                return;
2648:                            }
2649:                        }
2650:                        previewURL = previewURL + "&previewDate=" + date
2651:                                + "&previewConfig=" + path + "&currentTime="
2652:                                + System.currentTimeMillis();
2653:                    }
2654:                    MainPanel.showURL(previewURL);
2655:                }
2656:            }
2657:
2658:            /**
2659:             * Checks if there are any outstanding edit processes. If none, it returns false; else it opens an error dialog and
2660:             * returns true.
2661:             */
2662:            protected boolean openEditors() {
2663:                int count = ComponentFactory.getInstance()
2664:                        .countEditedComponents();
2665:                if (count > 0) {
2666:                    JOptionPane
2667:                            .showOptionDialog(
2668:                                    ContelligentClient.getActiveFrame(),
2669:                                    Resources.getLocalString(
2670:                                            "unsaved_editors_found",
2671:                                            new String[] { new Integer(count)
2672:                                                    .toString() }),
2673:                                    Resources
2674:                                            .getLocalString("unsaved_editors_found_title"),
2675:                                    JOptionPane.OK_OPTION,
2676:                                    JOptionPane.ERROR_MESSAGE, null,
2677:                                    new String[] { Resources
2678:                                            .getLocalString("ok") }, Resources
2679:                                            .getLocalString("ok"));
2680:                    return true;
2681:                } else {
2682:                    return false;
2683:                }
2684:            }
2685:
2686:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.