use of com.intellij.diagram.DiagramBuilder in project intellij-plugins by JetBrains.
the class FlashUmlTest method testExpandCollapse2.
public void testExpandCollapse2() throws Exception {
File projectRoot = new File(getVirtualFile(BASE_PATH + getTestName(false)).getPath());
String[] files = { getTestName(false) + "/com/test/MyButton.mxml" };
DiagramBuilder builder = doTestImpl(projectRoot, files, ArrayUtil.EMPTY_STRING_ARRAY, moduleScopeProvider(), EnumSet.allOf(FlashUmlDependenciesSettingsOption.class), null);
String originQName = "com.test.MyButton";
DiagramProvider<Object> provider = DiagramProvider.findByID(FlashUmlProvider.ID);
FlashUmlDataModel model = (FlashUmlDataModel) builder.getDataModel();
collapseNode(model, JSTestUtils.findClassByQName("com.test.MyButton", myModule.getModuleScope()));
assertModel("2", provider, originQName, model);
}
use of com.intellij.diagram.DiagramBuilder in project intellij-plugins by JetBrains.
the class FlashUmlTest method testExpandCollapse.
public void testExpandCollapse() throws Exception {
File projectRoot = new File(getVirtualFile(BASE_PATH + getTestName(false)).getPath());
String[] files = { getTestName(false) + "/Classes.as", getTestName(false) + "/com/test/MyButton.mxml", getTestName(false) + "/com/test/MyButton2.mxml" };
DiagramBuilder builder = doTestImpl(projectRoot, files, new String[] { "com.test.Bar", "Root", "com.test.MyButton" }, moduleScopeProvider(), EnumSet.allOf(FlashUmlDependenciesSettingsOption.class), null);
String originQName = "com.test.Foo";
DiagramProvider<Object> provider = DiagramProvider.findByID(FlashUmlProvider.ID);
FlashUmlDataModel model = (FlashUmlDataModel) builder.getDataModel();
collapseNode(model, JSTestUtils.findClassByQName("com.test.Bar", myModule.getModuleScope()));
assertModel("2", provider, originQName, model);
expandNode(model, "com.test");
assertModel("3", provider, originQName, model);
collapseNode(model, JSTestUtils.findClassByQName("Root", myModule.getModuleScope()));
assertModel("3", provider, originQName, model);
}
use of com.intellij.diagram.DiagramBuilder in project intellij-plugins by JetBrains.
the class NewJSClassUmlActionBase method prepare.
@Override
@Nullable
public CreateClassParameters prepare(AnActionEvent e) {
DiagramBuilder diagramBuilder = getBuilder(e);
if (diagramBuilder == null)
return null;
final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
if (project == null) {
return null;
}
Pair<PsiDirectory, String> dirAndPackage = getPackageToCreateIn((FlashUmlDataModel) diagramBuilder.getDataModel());
if (dirAndPackage.first == null) {
Collection<VirtualFile> dirs = DirectoryIndex.getInstance(project).getDirectoriesByPackageName(dirAndPackage.second, false).findAll();
final PsiManager psiManager = PsiManager.getInstance(project);
PsiDirectory[] psiDirs = ContainerUtil.map2Array(dirs, PsiDirectory.class, virtualFile -> psiManager.findDirectory(virtualFile));
PsiDirectory dir = DirectoryChooserUtil.selectDirectory(project, psiDirs, null, null);
if (dir == null) {
return null;
}
dirAndPackage = Pair.create(dir, dirAndPackage.second);
}
return showDialog(project, dirAndPackage);
}
use of com.intellij.diagram.DiagramBuilder in project intellij-plugins by JetBrains.
the class FlashUmlTest method doTestImpl.
private DiagramBuilder doTestImpl(@Nullable File projectRoot, String[] files, String[] additionalClasses, Computable<GlobalSearchScope> scopeProvider, @Nullable EnumSet<FlashUmlDependenciesSettingsOption> dependencies, @Nullable String expectedFileNamePrefix) throws Exception {
List<VirtualFile> vFiles = new ArrayList<>(files.length);
for (String file : files) {
vFiles.add(getVirtualFile(BASE_PATH + file));
}
ApplicationManager.getApplication().runWriteAction(() -> {
final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
ContentEntry[] contentEntries = rootModel.getContentEntries();
for (ContentEntry contentEntry : contentEntries) {
rootModel.removeContentEntry(contentEntry);
}
rootModel.commit();
});
configureByFiles(projectRoot, VfsUtilCore.toVirtualFileArray(vFiles));
final LinkedHashMap<Integer, String> markers = JSTestUtils.extractPositionMarkers(getProject(), getEditor().getDocument());
assertFalse(markers.isEmpty());
DiagramBuilder builder = null;
int i = 1;
for (Map.Entry<Integer, String> marker : markers.entrySet()) {
getEditor().getCaretModel().moveToOffset(marker.getKey());
i++;
String expectedPrefix = StringUtil.isNotEmpty(marker.getValue()) ? marker.getValue() : expectedFileNamePrefix;
final DataContext dataContext = DataManager.getInstance().getDataContext();
final DiagramProvider[] providers = DiagramProvider.findProviders(dataContext, "unknown");
final FlashUmlProvider provider = ContainerUtil.findInstance(providers, FlashUmlProvider.class);
assertNotNull("Flash UML provider not found", provider);
final String actualOriginFqn = provider.getVfsResolver().getQualifiedName(provider.getElementManager().findInDataContext(dataContext));
final Object actualOrigin = provider.getVfsResolver().resolveElementByFQN(actualOriginFqn, getProject());
builder = UmlGraphBuilderFactory.create(myProject, provider, actualOrigin, null);
Disposer.register(getTestRootDisposable(), builder);
final DiagramDataModel<Object> model = builder.getDataModel();
DiagramConfiguration configuration = DiagramConfiguration.getConfiguration();
String originalCategories = configuration.categories.get(provider.getID());
if (dependencies != null) {
model.setShowDependencies(true);
EnumSet<FlashUmlDependenciesSettingsOption> disabledOptions = EnumSet.complementOf(dependencies);
configuration.categories.put(provider.getID(), StringUtil.join(disabledOptions, option -> option.getDisplayName(), ";"));
} else {
model.setShowDependencies(false);
}
try {
model.refreshDataModel();
// first limit elements by scope
Collection<DiagramNode<Object>> nodesToRemove = new ArrayList<>();
for (DiagramNode<Object> node : model.getNodes()) {
if (node.getIdentifyingElement() instanceof JSClass && !scopeProvider.compute().contains(((JSClass) node.getIdentifyingElement()).getContainingFile().getVirtualFile())) {
nodesToRemove.add(node);
}
}
for (DiagramNode<Object> node : nodesToRemove) {
model.removeNode(node);
}
builder.updateGraph();
// then add explicitly required classes
for (String aClass : additionalClasses) {
JSClass c = JSTestUtils.findClassByQName(aClass, GlobalSearchScope.allScope(myProject));
final DiagramNode node = model.addElement(c);
if (node != null) {
builder.createDraggedNode(node, node.getTooltip(), DiagramUtils.getBestPositionForNode(builder));
builder.updateGraph();
}
}
assertModel(expectedPrefix, provider, actualOriginFqn, model);
} finally {
configuration.categories.put(provider.getID(), originalCategories);
}
}
assert builder != null;
return builder;
}
use of com.intellij.diagram.DiagramBuilder in project intellij-plugins by JetBrains.
the class NewJSClassUmlActionBase method getPackageToCreateIn.
private static Pair<PsiDirectory, String> getPackageToCreateIn(FlashUmlDataModel model) {
final DiagramBuilder builder = model.getBuilder();
String aPackage = null;
PsiDirectory directory = null;
final List<Node> nodes = GraphViewUtil.getSelectedNodes(builder.getGraph());
if (nodes.size() == 1) {
DiagramNode node = builder.getNodeObject(nodes.get(0));
if (node != null) {
if (node.getIdentifyingElement() instanceof String) {
aPackage = (String) node.getIdentifyingElement();
directory = null;
} else {
final JSClass selectedClass = (JSClass) node.getIdentifyingElement();
directory = PlatformPackageUtil.getDirectory(selectedClass);
aPackage = StringUtil.getPackageName(selectedClass.getQualifiedName());
}
}
}
if (aPackage == null) {
JSClass initialClass = (JSClass) model.getInitialElement();
if (initialClass != null) {
directory = PlatformPackageUtil.getDirectory(initialClass);
aPackage = StringUtil.getPackageName(initialClass.getQualifiedName());
} else {
directory = null;
aPackage = model.getInitialPackage();
}
}
return Pair.create(directory, aPackage);
}
Aggregations