Search in sources :

Example 11 with ExternalProjectPojo

use of com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo in project intellij-community by JetBrains.

the class ExternalSystemTasksTreeModel method ensureProjectNodeExists.

/**
   * Ensures that current model has a top-level node which corresponds to the given external project info holder
   *
   * @param project target external project info holder
   */
@SuppressWarnings("unchecked")
@NotNull
public ExternalSystemNode<ExternalProjectPojo> ensureProjectNodeExists(@NotNull ExternalProjectPojo project) {
    ExternalSystemNode<?> root = getRoot();
    // Remove outdated projects.
    for (int i = root.getChildCount() - 1; i >= 0; i--) {
        ExternalSystemNode<?> child = root.getChildAt(i);
        ExternalSystemNodeDescriptor<?> descriptor = child.getDescriptor();
        Object element = descriptor.getElement();
        if (element instanceof ExternalProjectPojo) {
            ExternalProjectPojo pojo = (ExternalProjectPojo) element;
            if (pojo.getPath().equals(project.getPath())) {
                if (!pojo.getName().equals(project.getName())) {
                    pojo.setName(project.getName());
                    descriptor.setName(project.getName());
                    nodeChanged(child);
                }
                return (ExternalSystemNode<ExternalProjectPojo>) child;
            }
        }
    }
    ExternalProjectPojo element = new ExternalProjectPojo(project.getName(), project.getPath());
    ExternalSystemNodeDescriptor<ExternalProjectPojo> descriptor = descriptor(element, myUiAware.getProjectIcon());
    ExternalSystemNode<ExternalProjectPojo> result = new ExternalSystemNode<>(descriptor);
    insertNodeInto(result, root);
    return result;
}
Also used : ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with ExternalProjectPojo

use of com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo in project intellij-community by JetBrains.

the class ExternalProjectPathField method createPanel.

@NotNull
public static MyPathAndProjectButtonPanel createPanel(@NotNull final Project project, @NotNull final ProjectSystemId externalSystemId) {
    final EditorTextField textField = createTextField(project, externalSystemId);
    final FixedSizeButton selectRegisteredProjectButton = new FixedSizeButton();
    selectRegisteredProjectButton.setIcon(AllIcons.Actions.Module);
    String tooltipText = ExternalSystemBundle.message("run.configuration.tooltip.choose.registered.project", externalSystemId.getReadableName());
    selectRegisteredProjectButton.setToolTipText(tooltipText);
    selectRegisteredProjectButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final Ref<JBPopup> popupRef = new Ref<>();
            final Tree tree = buildRegisteredProjectsTree(project, externalSystemId);
            tree.setBorder(IdeBorderFactory.createEmptyBorder(8));
            Runnable treeSelectionCallback = () -> {
                TreePath path = tree.getSelectionPath();
                if (path != null) {
                    Object lastPathComponent = path.getLastPathComponent();
                    if (lastPathComponent instanceof ExternalSystemNode) {
                        Object e1 = ((ExternalSystemNode) lastPathComponent).getDescriptor().getElement();
                        if (e1 instanceof ExternalProjectPojo) {
                            ExternalProjectPojo pojo = (ExternalProjectPojo) e1;
                            textField.setText(pojo.getPath());
                            Editor editor = textField.getEditor();
                            if (editor != null) {
                                collapseIfPossible(editor, externalSystemId, project);
                            }
                        }
                    }
                }
                popupRef.get().closeOk(null);
            };
            JBPopup popup = new PopupChooserBuilder(tree).setTitle(ExternalSystemBundle.message("run.configuration.title.choose.registered.project", externalSystemId.getReadableName())).setResizable(true).setItemChoosenCallback(treeSelectionCallback).setAutoselectOnMouseMove(true).setCloseOnEnter(false).createPopup();
            popupRef.set(popup);
            popup.showUnderneathOf(selectRegisteredProjectButton);
        }
    });
    return new MyPathAndProjectButtonPanel(textField, selectRegisteredProjectButton);
}
Also used : ActionEvent(java.awt.event.ActionEvent) ExternalSystemNode(com.intellij.openapi.externalSystem.service.task.ui.ExternalSystemNode) Ref(com.intellij.openapi.util.Ref) ActionListener(java.awt.event.ActionListener) TreePath(javax.swing.tree.TreePath) EditorTextField(com.intellij.ui.EditorTextField) Tree(com.intellij.ui.treeStructure.Tree) ExternalSystemTasksTree(com.intellij.openapi.externalSystem.service.task.ui.ExternalSystemTasksTree) Editor(com.intellij.openapi.editor.Editor) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) FixedSizeButton(com.intellij.openapi.ui.FixedSizeButton) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with ExternalProjectPojo

use of com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo in project intellij-community by JetBrains.

the class ExternalProjectPathField method createTextField.

@NotNull
private static EditorTextField createTextField(@NotNull final Project project, @NotNull final ProjectSystemId externalSystemId) {
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
    assert manager != null;
    final AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project);
    final ExternalSystemUiAware uiAware = ExternalSystemUiUtil.getUiAware(externalSystemId);
    TextFieldCompletionProvider provider = new TextFieldCompletionProviderDumbAware() {

        @Override
        protected void addCompletionVariants(@NotNull String text, int offset, @NotNull String prefix, @NotNull CompletionResultSet result) {
            for (Map.Entry<ExternalProjectPojo, Collection<ExternalProjectPojo>> entry : settings.getAvailableProjects().entrySet()) {
                String rootProjectPath = entry.getKey().getPath();
                String rootProjectName = uiAware.getProjectRepresentationName(rootProjectPath, null);
                ExternalProjectPathLookupElement rootProjectElement = new ExternalProjectPathLookupElement(rootProjectName, rootProjectPath);
                result.addElement(rootProjectElement);
                for (ExternalProjectPojo subProject : entry.getValue()) {
                    String p = subProject.getPath();
                    if (rootProjectPath.equals(p)) {
                        continue;
                    }
                    String subProjectName = uiAware.getProjectRepresentationName(p, rootProjectPath);
                    ExternalProjectPathLookupElement subProjectElement = new ExternalProjectPathLookupElement(subProjectName, p);
                    result.addElement(subProjectElement);
                }
            }
            result.stopHere();
        }
    };
    EditorTextField result = provider.createEditor(project, false, editor -> {
        collapseIfPossible(editor, externalSystemId, project);
        editor.getSettings().setShowIntentionBulb(false);
    });
    result.setBorder(UIUtil.getTextFieldBorder());
    result.setOneLineMode(true);
    result.setOpaque(true);
    result.setBackground(UIUtil.getTextFieldBackground());
    return result;
}
Also used : AbstractExternalSystemLocalSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) NotNull(org.jetbrains.annotations.NotNull) ExternalSystemUiAware(com.intellij.openapi.externalSystem.ExternalSystemUiAware) TextFieldCompletionProviderDumbAware(com.intellij.util.TextFieldCompletionProviderDumbAware) EditorTextField(com.intellij.ui.EditorTextField) TextFieldCompletionProvider(com.intellij.util.TextFieldCompletionProvider) Collection(java.util.Collection) Map(java.util.Map) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with ExternalProjectPojo

use of com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo in project intellij-community by JetBrains.

the class ExternalProjectPathField method buildRegisteredProjectsTree.

@NotNull
private static Tree buildRegisteredProjectsTree(@NotNull Project project, @NotNull ProjectSystemId externalSystemId) {
    ExternalSystemTasksTreeModel model = new ExternalSystemTasksTreeModel(externalSystemId);
    ExternalSystemTasksTree result = new ExternalSystemTasksTree(model, ContainerUtilRt.<String, Boolean>newHashMap(), project, externalSystemId);
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
    assert manager != null;
    AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project);
    Map<ExternalProjectPojo, Collection<ExternalProjectPojo>> projects = settings.getAvailableProjects();
    List<ExternalProjectPojo> rootProjects = ContainerUtilRt.newArrayList(projects.keySet());
    ContainerUtil.sort(rootProjects);
    for (ExternalProjectPojo rootProject : rootProjects) {
        model.ensureSubProjectsStructure(rootProject, projects.get(rootProject));
    }
    return result;
}
Also used : ExternalSystemTasksTreeModel(com.intellij.openapi.externalSystem.service.task.ui.ExternalSystemTasksTreeModel) AbstractExternalSystemLocalSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings) ExternalSystemTasksTree(com.intellij.openapi.externalSystem.service.task.ui.ExternalSystemTasksTree) Collection(java.util.Collection) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with ExternalProjectPojo

use of com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo in project intellij-community by JetBrains.

the class ToolWindowModuleService method processData.

@Override
protected void processData(@NotNull final Collection<DataNode<ModuleData>> nodes, @NotNull Project project) {
    if (nodes.isEmpty()) {
        return;
    }
    ProjectSystemId externalSystemId = nodes.iterator().next().getData().getOwner();
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
    assert manager != null;
    final MultiMap<DataNode<ProjectData>, DataNode<ModuleData>> grouped = ExternalSystemApiUtil.groupBy(nodes, ProjectKeys.PROJECT);
    Map<ExternalProjectPojo, Collection<ExternalProjectPojo>> data = ContainerUtilRt.newHashMap();
    for (Map.Entry<DataNode<ProjectData>, Collection<DataNode<ModuleData>>> entry : grouped.entrySet()) {
        data.put(ExternalProjectPojo.from(entry.getKey().getData()), ContainerUtilRt.map2List(entry.getValue(), MAPPER));
    }
    AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project);
    Set<String> pathsToForget = detectRenamedProjects(data, settings.getAvailableProjects());
    if (!pathsToForget.isEmpty()) {
        settings.forgetExternalProjects(pathsToForget);
    }
    Map<ExternalProjectPojo, Collection<ExternalProjectPojo>> projects = ContainerUtilRt.newHashMap(settings.getAvailableProjects());
    projects.putAll(data);
    settings.setAvailableProjects(projects);
}
Also used : AbstractExternalSystemLocalSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) MultiMap(com.intellij.util.containers.MultiMap)

Aggregations

ExternalProjectPojo (com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo)17 AbstractExternalSystemLocalSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings)5 Collection (java.util.Collection)5 NotNull (org.jetbrains.annotations.NotNull)5 ExternalTaskExecutionInfo (com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo)4 ExternalTaskPojo (com.intellij.openapi.externalSystem.model.execution.ExternalTaskPojo)4 MultiMap (com.intellij.util.containers.MultiMap)3 Map (java.util.Map)3 ExternalSystemUiAware (com.intellij.openapi.externalSystem.ExternalSystemUiAware)2 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)2 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)2 ExternalSystemTasksTree (com.intellij.openapi.externalSystem.service.task.ui.ExternalSystemTasksTree)2 EditorTextField (com.intellij.ui.EditorTextField)2 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)1 Editor (com.intellij.openapi.editor.Editor)1 DataNode (com.intellij.openapi.externalSystem.model.DataNode)1 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)1 InternalExternalProjectInfo (com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)1 ExternalProjectBuildClasspathPojo (com.intellij.openapi.externalSystem.model.project.ExternalProjectBuildClasspathPojo)1 TaskData (com.intellij.openapi.externalSystem.model.task.TaskData)1