public void mousePressed()

in tapestry/src/main/java/com/intellij/tapestry/intellij/view/ViewMouseListener.java [43:135]


    public void mousePressed(MouseEvent event) {
        if (_tapestryProjectViewPane.getTree().getSelectionPath() != null && _tapestryProjectViewPane.getTree().getSelectionPaths().length < 2) {
            Object selectedNode = ((DefaultMutableTreeNode) _tapestryProjectViewPane.getTree().getSelectionPath().getLastPathComponent()).getUserObject();
            Module module = (Module) _tapestryProjectViewPane.getData(PlatformCoreDataKeys.MODULE.getName());

            // If dragged node isn't a Page or Component or Mixin don't drag
            if (!(selectedNode instanceof PageNode) && !(selectedNode instanceof ComponentNode) && !(selectedNode instanceof MixinNode)) {
                return;
            }

            // If there's no file opened don't drag
            if (FileEditorManager.getInstance(_tapestryProjectViewPane.getProject()).getSelectedFiles().length == 0) {
                return;
            }

            PsiFile fileInEditor = PsiManager.getInstance(_tapestryProjectViewPane.getProject()).findFile(
                    FileDocumentManager.getInstance().getFile(FileEditorManager.getInstance(_tapestryProjectViewPane.getProject()).getSelectedTextEditor().getDocument())
            );
            FileType typeFileInEditor = fileInEditor.getFileType();

            // If the file in editor isn't either JAVA or TML don't drag
            if (!(fileInEditor instanceof PsiClassOwner) && !typeFileInEditor.equals(TmlFileType.INSTANCE)) {
                return;
            }

            // If the file in editor isn't writable or isn't part of the module where the drag is from don't drag
            Module moduleForFile = ProjectRootManager.getInstance(_tapestryProjectViewPane.getProject()).getFileIndex().getModuleForFile(fileInEditor.getVirtualFile());
            if (!fileInEditor.isWritable() || moduleForFile == null || !moduleForFile.equals(module)) {
                return;
            }

            // If the file in the editor is a TML file
            if (typeFileInEditor.equals(TmlFileType.INSTANCE)) {
                // If the file doesn't declare the Tapestry namespace don't drag
                if (TapestryUtils.getTapestryNamespacePrefix((XmlFile) fileInEditor) == null) {
                    return;
                }

                // Don't drag mixins to templates
                if (selectedNode instanceof MixinNode) {
                    return;
                }
            }

            // If the file in the editor is a JAVA file
            if (fileInEditor instanceof PsiClassOwner) {
                PsiClass psiClass = IdeaUtils.findPublicClass(fileInEditor);

                if (psiClass == null) {
                    return;
                }

                IntellijJavaClassType elementClass = new IntellijJavaClassType(module, psiClass.getContainingFile());
                PresentationLibraryElement presentationLibraryElement;
                try {
                    // Check if the drop target is a valid presentation element
                    presentationLibraryElement = PresentationLibraryElement.createProjectElementInstance(elementClass, TapestryModuleSupportLoader.getTapestryProject(module));
                } catch (NotTapestryElementException e) {
                    return;
                }

                // If dropping on a page class
                if (presentationLibraryElement.getElementType().equals(PresentationLibraryElement.ElementType.PAGE))
                // Can only drop Pages and Components
                {
                    if (!(selectedNode instanceof PageNode) && !(selectedNode instanceof ComponentNode)) {
                        return;
                    }
                }

                // If dropping on a component class
                if (presentationLibraryElement.getElementType().equals(PresentationLibraryElement.ElementType.COMPONENT))
                // Can only drop Pages and Components
                {
                    if (!(selectedNode instanceof PageNode) && !(selectedNode instanceof ComponentNode) && !(selectedNode instanceof MixinNode)) {
                        return;
                    }
                }

                // If dropping on a mixin class
                if (presentationLibraryElement.getElementType().equals(PresentationLibraryElement.ElementType.MIXIN))
                // Can only drop Pages and Components
                {
                    if (!(selectedNode instanceof PageNode)) {
                        return;
                    }
                }
            }

            _firstMouseEvent = event;
            event.consume();
        }
    }