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;
}
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);
}
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;
}
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;
}
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);
}
Aggregations