Search in sources :

Example 1 with TektonTreeStructure

use of com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure in project intellij-tekton by redhat-developer.

the class WindowToolFactory method createToolWindowContent.

@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
    try {
        ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
        TektonTreeStructure structure = new TektonTreeStructure(project);
        StructureTreeModel<TektonTreeStructure> model = buildModel(structure, project);
        new MutableTektonModelSynchronizer<>(model, structure, structure);
        Tree tree = new Tree(new AsyncTreeModel(model, project));
        tree.putClientProperty(Constants.STRUCTURE_PROPERTY, structure);
        tree.setCellRenderer(new NodeRenderer());
        ActionManager actionManager = ActionManager.getInstance();
        ActionGroup group = (ActionGroup) actionManager.getAction("com.redhat.devtools.intellij.tektoncd.tree");
        PopupHandler.installPopupHandler(tree, group, ActionPlaces.POPUP, actionManager, new TektonTreePopupMenuListener());
        new TektonTreeDoubleClickListener(tree);
        TknCliFactory.getInstance().getTkn(project).whenComplete((tkn, err) -> {
            HubModel hubModel = new HubModel(project, tkn, null);
            JPanel hubItemsListPanel = new HubItemPanelsBoard(hubModel, getDoSelectAction(project, hubModel)).withRecommended().withInstalled().build(Optional.empty());
            OnePixelSplitter tabPanel = createTabPanel(new JBScrollPane(tree), hubItemsListPanel);
            toolWindow.getContentManager().addContent(contentFactory.createContent(tabPanel, "", false));
            executeOnProjectClosing(project, () -> {
                structure.dispose();
                hubModel.dispose();
            });
        });
    } catch (IllegalAccessException | InvocationTargetException | InstantiationException | NoSuchMethodException e) {
        throw new RuntimeException((e));
    }
}
Also used : JPanel(javax.swing.JPanel) AsyncTreeModel(com.intellij.ui.tree.AsyncTreeModel) TektonTreeStructure(com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure) TektonTreeDoubleClickListener(com.redhat.devtools.intellij.tektoncd.listener.TektonTreeDoubleClickListener) HubItemPanelsBoard(com.redhat.devtools.intellij.tektoncd.ui.hub.HubItemPanelsBoard) OnePixelSplitter(com.intellij.ui.OnePixelSplitter) HubModel(com.redhat.devtools.intellij.tektoncd.ui.hub.HubModel) ContentFactory(com.intellij.ui.content.ContentFactory) MutableTektonModelSynchronizer(com.redhat.devtools.intellij.tektoncd.tree.MutableTektonModelSynchronizer) InvocationTargetException(java.lang.reflect.InvocationTargetException) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) ActionManager(com.intellij.openapi.actionSystem.ActionManager) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) Tree(com.intellij.ui.treeStructure.Tree) TektonTreePopupMenuListener(com.redhat.devtools.intellij.tektoncd.listener.TektonTreePopupMenuListener) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 2 with TektonTreeStructure

use of com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure in project intellij-tekton by redhat-developer.

the class TreeHelper method getTkn.

public static Tkn getTkn(Project project) {
    try {
        TektonTreeStructure treeStructure = (TektonTreeStructure) getTree(project).getClientProperty(Constants.STRUCTURE_PROPERTY);
        TektonRootNode root = (TektonRootNode) treeStructure.getRootElement();
        return root.getTkn();
    } catch (Exception ex) {
        return null;
    }
}
Also used : TektonRootNode(com.redhat.devtools.intellij.tektoncd.tree.TektonRootNode) TektonTreeStructure(com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure) IOException(java.io.IOException)

Example 3 with TektonTreeStructure

use of com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure in project intellij-tekton by redhat-developer.

the class DeleteAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath[] path, Object[] selected, Tkn tkncli) {
    ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_CRUD + "delete resource");
    ParentableNode[] elements = Arrays.stream(selected).map(item -> getElement(item)).toArray(ParentableNode[]::new);
    ExecHelper.submit(() -> {
        String deleteText = getDeleteText(tkncli, elements);
        int resultDialog = UIHelper.executeInUI(() -> {
            DeleteDialog delDialog = new DeleteDialog(null, getTitle(elements), deleteText, getDeleteChkText(elements));
            delDialog.show();
            if (delDialog.isOK()) {
                return delDialog.hasToDeleteRelatedResources() ? OK_DELETE_RESOURCES_CODE : OK_DELETE_CODE;
            }
            return CANCEL_CODE;
        });
        if (resultDialog != CANCEL_CODE) {
            String namespace = elements[0].getNamespace();
            boolean deleteRelatedResources = resultDialog == OK_DELETE_RESOURCES_CODE;
            Map<Class, List<ParentableNode>> resourcesByClass = TreeHelper.getResourcesByClass(elements);
            for (Class type : resourcesByClass.keySet()) {
                try {
                    deleteResources(type, resourcesByClass, namespace, deleteRelatedResources, tkncli);
                    ((TektonTreeStructure) getTree(anActionEvent).getClientProperty(Constants.STRUCTURE_PROPERTY)).fireModified(resourcesByClass.get(type).get(0).getParent());
                    telemetry.property(TelemetryService.PROP_RESOURCE_KIND, type.getSimpleName()).property(TelemetryService.PROP_RESOURCE_RELATED, String.valueOf(deleteRelatedResources)).success().send();
                } catch (IOException e) {
                    telemetry.error(anonymizeResource(null, namespace, e.getMessage())).send();
                    UIHelper.executeInUI(() -> Messages.showErrorDialog("Error: " + e.getLocalizedMessage(), "Error"));
                }
            }
        }
    });
}
Also used : ClusterTaskNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTaskNode) Arrays(java.util.Arrays) RefUsage(com.redhat.devtools.intellij.tektoncd.ui.toolwindow.findusage.RefUsage) TreeHelper(com.redhat.devtools.intellij.tektoncd.utils.TreeHelper) KIND_TASK(com.redhat.devtools.intellij.tektoncd.Constants.KIND_TASK) ConditionNode(com.redhat.devtools.intellij.tektoncd.tree.ConditionNode) Tkn(com.redhat.devtools.intellij.tektoncd.tkn.Tkn) PipelineRunNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode) TaskNode(com.redhat.devtools.intellij.tektoncd.tree.TaskNode) Constants(com.redhat.devtools.intellij.tektoncd.Constants) TriggerTemplateNode(com.redhat.devtools.intellij.tektoncd.tree.TriggerTemplateNode) ExecHelper(com.redhat.devtools.intellij.common.utils.ExecHelper) Map(java.util.Map) TelemetryService(com.redhat.devtools.intellij.tektoncd.telemetry.TelemetryService) Messages(com.intellij.openapi.ui.Messages) UIHelper(com.redhat.devtools.intellij.common.utils.UIHelper) ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) TaskRunNode(com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode) AnonymizeUtils.anonymizeResource(com.redhat.devtools.intellij.telemetry.core.util.AnonymizeUtils.anonymizeResource) KIND_CLUSTERTASK(com.redhat.devtools.intellij.tektoncd.Constants.KIND_CLUSTERTASK) TreePath(javax.swing.tree.TreePath) IOException(java.io.IOException) NAME_PREFIX_CRUD(com.redhat.devtools.intellij.tektoncd.telemetry.TelemetryService.NAME_PREFIX_CRUD) ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) DeleteDialog(com.redhat.devtools.intellij.tektoncd.ui.DeleteDialog) Collectors(java.util.stream.Collectors) TektonTreeStructure(com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure) PipelineNode(com.redhat.devtools.intellij.tektoncd.tree.PipelineNode) List(java.util.List) ClusterTriggerBindingNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTriggerBindingNode) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) EventListenerNode(com.redhat.devtools.intellij.tektoncd.tree.EventListenerNode) ResourceNode(com.redhat.devtools.intellij.tektoncd.tree.ResourceNode) TriggerBindingNode(com.redhat.devtools.intellij.tektoncd.tree.TriggerBindingNode) TektonTreeStructure(com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure) IOException(java.io.IOException) DeleteDialog(com.redhat.devtools.intellij.tektoncd.ui.DeleteDialog) ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage) List(java.util.List)

Example 4 with TektonTreeStructure

use of com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure in project intellij-tekton by redhat-developer.

the class RefreshAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent, TreePath path, Object selected) {
    ActionMessage telemetry = TelemetryService.instance().action(NAME_PREFIX_MISC + "refresh");
    selected = StructureTreeAction.getElement(selected);
    TektonTreeStructure structure = (TektonTreeStructure) getTree(anActionEvent).getClientProperty(Constants.STRUCTURE_PROPERTY);
    structure.fireModified(selected);
    telemetry.property(PROP_RESOURCE_KIND, selected.getClass().getSimpleName()).send();
}
Also used : TektonTreeStructure(com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure) ActionMessage(com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage)

Example 5 with TektonTreeStructure

use of com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure in project intellij-tekton by redhat-developer.

the class RefreshQueue method update.

public void update() {
    while (!queue.isEmpty()) {
        ParentableNode element = queue.poll();
        Tree tree = TreeHelper.getTree(element.getRoot().getProject());
        TektonTreeStructure treeStructure = (TektonTreeStructure) tree.getClientProperty(Constants.STRUCTURE_PROPERTY);
        treeStructure.fireModified(element);
    }
}
Also used : ParentableNode(com.redhat.devtools.intellij.tektoncd.tree.ParentableNode) TektonTreeStructure(com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure) Tree(com.intellij.ui.treeStructure.Tree)

Aggregations

TektonTreeStructure (com.redhat.devtools.intellij.tektoncd.tree.TektonTreeStructure)8 ParentableNode (com.redhat.devtools.intellij.tektoncd.tree.ParentableNode)3 IOException (java.io.IOException)3 Tree (com.intellij.ui.treeStructure.Tree)2 PipelineRunNode (com.redhat.devtools.intellij.tektoncd.tree.PipelineRunNode)2 TaskRunNode (com.redhat.devtools.intellij.tektoncd.tree.TaskRunNode)2 ActionMessage (com.redhat.devtools.intellij.telemetry.core.service.TelemetryMessageBuilder.ActionMessage)2 NodeRenderer (com.intellij.ide.util.treeView.NodeRenderer)1 Notification (com.intellij.notification.Notification)1 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)1 ActionManager (com.intellij.openapi.actionSystem.ActionManager)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Messages (com.intellij.openapi.ui.Messages)1 OnePixelSplitter (com.intellij.ui.OnePixelSplitter)1 JBScrollPane (com.intellij.ui.components.JBScrollPane)1 ContentFactory (com.intellij.ui.content.ContentFactory)1 AsyncTreeModel (com.intellij.ui.tree.AsyncTreeModel)1 ExecHelper (com.redhat.devtools.intellij.common.utils.ExecHelper)1 UIHelper (com.redhat.devtools.intellij.common.utils.UIHelper)1 Constants (com.redhat.devtools.intellij.tektoncd.Constants)1