Java Code Examples for com.intellij.openapi.project.Project

The following are top voted examples for showing how to use com.intellij.openapi.project.Project. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: educational-plugin   File: StudyShowHintAction.java   View source code 6 votes vote down vote up
public void showHint(Project project) {
  Course course = StudyTaskManager.getInstance(project).getCourse();
  if (course == null) {
    return;
  }
  StudyState studyState = new StudyState(StudyUtils.getSelectedStudyEditor(project));
  if (!studyState.isValid()) {
    return;
  }
  PsiFile file = PsiManager.getInstance(project).findFile(studyState.getVirtualFile());
  final Editor editor = studyState.getEditor();
  int offset = editor.getCaretModel().getOffset();
  AnswerPlaceholder answerPlaceholder = studyState.getTaskFile().getAnswerPlaceholder(offset);
  if (file == null) {
    return;
  }
  EduUsagesCollector.hintShown();

  final StudyToolWindow hintComponent = getHint(project, answerPlaceholder).getStudyToolWindow();
  hintComponent.setPreferredSize(new Dimension(400, 150));
  showHintPopUp(project, studyState, editor, hintComponent);
}
 
Example 2
Project: educational-plugin   File: StudyCheckUtils.java   View source code 6 votes vote down vote up
public static void showTestResultsToolWindow(@NotNull final Project project, @NotNull final String message) {
  ApplicationManager.getApplication().invokeLater(() -> {
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    ToolWindow window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID);
    if (window == null) {
      toolWindowManager.registerToolWindow(StudyTestResultsToolWindowFactoryKt.ID, true, ToolWindowAnchor.BOTTOM);
      window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID);
      new StudyTestResultsToolWindowFactory().createToolWindowContent(project, window);
    }

    final Content[] contents = window.getContentManager().getContents();
    for (Content content : contents) {
      final JComponent component = content.getComponent();
      if (component instanceof ConsoleViewImpl) {
        ((ConsoleViewImpl)component).clear();
        ((ConsoleViewImpl)component).print(message, ConsoleViewContentType.ERROR_OUTPUT);
        window.setAvailable(true,null);
        window.show(null);
      }
    }
  });
}
 
Example 3
Project: intellij-idea-plugin-connector-for-aws-lambda   File: MessageHelper.java   View source code 6 votes vote down vote up
private static void showMessage(final Project project, final MessageType messageType, final String format, final Object[] args) {
    StatusBar statusBar = windowManager.getStatusBar(project);
    if(statusBar == null || statusBar.getComponent() == null){
        return;
    }
    String message = String.format(format, args);
    jbPopupFactory.createHtmlTextBalloonBuilder(message, messageType, null)
                .setFadeoutTime(7500)
                .createBalloon()
                .show(RelativePoint.getNorthEastOf(statusBar.getComponent()), Balloon.Position.atRight);

    if(messageType == MessageType.INFO){
        log.info(message);
    }
    else if(messageType == MessageType.WARNING) {
        log.warn(message);
    }
    else{
        log.debug(message);
    }
}
 
Example 4
Project: intellij-plugin   File: AggregateNode.java   View source code 6 votes vote down vote up
@Override
protected MultiMap<PsiFile, ClassNode> computeChildren(@Nullable PsiFile psiFile) {
    MultiMap<PsiFile, ClassNode> children = new MultiMap<>();
    children.putValue(aggregateRoot.getContainingFile(), new AggregateRootNode(this, aggregateRoot));
    Project project = getProject();
    if (project != null) {
        JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
        PsiClass entityInterface = javaPsiFacade.findClass(ENTITY_INTERFACE, GlobalSearchScope.allScope(project));
        PsiClass valueObjectInterface = javaPsiFacade.findClass(VO_INTERFACE, GlobalSearchScope.allScope(project));
        if (entityInterface != null && valueObjectInterface != null) {
            for (PsiClass psiClass : psiPackage.getClasses(GlobalSearchScope.allScope(project))) {
                if (psiClass.isInheritor(entityInterface, true) && !psiClass.equals(aggregateRoot)) {
                    children.putValue(psiClass.getContainingFile(), new EntityNode(this, psiClass));
                } else if (psiClass.isInheritor(valueObjectInterface, true)) {
                    children.putValue(psiClass.getContainingFile(), new ValueObjectNode(this, psiClass));
                }
            }
        }
    }
    return children;
}
 
Example 5
Project: hybris-integration-intellij-idea-plugin   File: HybrisEnumLiteralItemReference.java   View source code 6 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(final boolean incompleteCode) {
    Project project = myElement.getProject();
    final String enumLiteralJavaModelName = myElement.getText().replaceAll("\"", "").toUpperCase();

    final PsiShortNamesCache psiShortNamesCache = PsiShortNamesCache.getInstance(project);
    final PsiField[] javaEnumLiteralFields = psiShortNamesCache.getFieldsByName(
        enumLiteralJavaModelName, GlobalSearchScope.allScope(project)
    );

    final Set<PsiField> enumFields = stream(javaEnumLiteralFields)
        .filter(literal -> literal.getParent() != null)
        .filter(literal -> literal.getParent() instanceof ClsClassImpl)
        .filter(literal -> ((ClsClassImpl) literal.getParent()).isEnum())
        .collect(Collectors.toSet());

    return PsiElementResolveResult.createResults(enumFields);
}
 
Example 6
Project: educational-plugin   File: EduPluginConfiguratorBase.java   View source code 6 votes vote down vote up
@Override
public PsiDirectory createLessonContent(@NotNull Project project, @NotNull Lesson lesson, @Nullable IdeView view, @NotNull PsiDirectory parentDirectory) {
  NewModuleAction newModuleAction = new NewModuleAction();
  String courseDirPath = parentDirectory.getVirtualFile().getPath();
  Module utilModule = ModuleManager.getInstance(project).findModuleByName(EduIntelliJNames.UTIL);
  if (utilModule == null) {
    return null;
  }
  newModuleAction.createModuleFromWizard(project, null, new AbstractProjectWizard("", project, "") {
    @Override
    public StepSequence getSequence() {
      return null;
    }

    @Override
    public ProjectBuilder getProjectBuilder() {
      return new EduLessonModuleBuilder(courseDirPath, lesson, utilModule);
    }
  });
  return parentDirectory.findSubdirectory(EduNames.LESSON + lesson.getIndex());
}
 
Example 7
Project: AppleScript-IDEA   File: ApplicationDictionaryImpl.java   View source code 6 votes vote down vote up
public ApplicationDictionaryImpl(@NotNull Project project, @NotNull XmlFile dictionaryXmlFile,
                                 @NotNull String applicationName, @Nullable File applicationBundleFile) {
  this.project = project;
  this.dictionaryFile = dictionaryXmlFile.getVirtualFile();
  readDictionaryFromXmlFile(dictionaryXmlFile);
  this.applicationName = applicationName;
  if (applicationBundleFile != null) {
    this.applicationBundleFile = applicationBundleFile;
    setIconFromBundle(applicationBundleFile);
  }
  if (StringUtil.isEmpty(dictionaryName))
    dictionaryName = this.applicationName;
  LOG.info("Dictionary [" + dictionaryName + "] for application [" + this.applicationName + "] " +
          "initialized In project[" + project.getName() + "] " + " Commands: " + dictionaryCommandMap.size() +
          ". " + "Classes: " + dictionaryClassMap.size());
}
 
Example 8
Project: reasonml-idea-plugin   File: BsToolWindowFactory.java   View source code 6 votes vote down vote up
@Override
public void createToolWindowContent(@NotNull final Project project, @NotNull ToolWindow toolWindow) {
    SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true);

    BsConsole console = new BsConsole(project);
    panel.setContent(console.getComponent());

    ActionToolbar toolbar = console.createToolbar();
    panel.setToolbar(toolbar.getComponent());

    Content content = ContentFactory.SERVICE.getInstance().createContent(panel, "", true);
    toolWindow.getContentManager().addContent(content);

    // Start compiler
    BsCompiler bsc = BucklescriptProjectComponent.getInstance(project).getCompiler();
    if (bsc != null) {
        bsc.addListener(new BsOutputListener(project));
        ProcessHandler handler = bsc.getHandler();
        if (handler == null) {
            console.print("Bsb not found, check the event logs.", ERROR_OUTPUT);
        } else {
            console.attachToProcess(handler);
        }
        bsc.startNotify();
    }
}
 
Example 9
Project: educational-plugin   File: StudyUtils.java   View source code 6 votes vote down vote up
@Nullable
public static StudyToolWindow getStudyToolWindow(@NotNull final Project project) {
  if (project.isDisposed()) return null;

  ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW);
  if (toolWindow != null) {
    Content[] contents = toolWindow.getContentManager().getContents();
    for (Content content: contents) {
      JComponent component = content.getComponent();
      if (component != null && component instanceof StudyToolWindow) {
        return (StudyToolWindow)component;
      }
    }
  }
  return null;
}
 
Example 10
Project: TS-IJ   File: TSGlobalNSCallCompletionContributor.java   View source code 6 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    String namespace = parameters.getPosition().getPrevSibling().getPrevSibling().getText();

    Project project = parameters.getOriginalFile().getProject();
    Collection<TSFnDeclStmt> functions = TSUtil.getFunctionList(project);

    for (TSFnDeclStmt function : functions) {
        if (function.getFunctionType() == TSFunctionType.GLOBAL)
            continue;
        if (namespace != null && !function.getNamespace().equalsIgnoreCase(namespace))
            continue;

        result.addElement(
                LookupElementBuilder.create(function.getFunctionName())
                        .withCaseSensitivity(false)
                        .withPresentableText(function.getNamespace() + "::" + function.getFunctionName())
                        .withTailText(function.getArgList())
                        .withInsertHandler(TSCaseCorrectingInsertHandler.INSTANCE)
        );
    }
}
 
Example 11
Project: intellij-randomness   File: DataInsertAction.java   View source code 6 votes vote down vote up
/**
 * Inserts the string generated by {@link #generateString()} at the caret(s) in the editor.
 *
 * @param event the performed action
 */
@Override
public final void actionPerformed(final AnActionEvent event) {
    final Editor editor = event.getData(CommonDataKeys.EDITOR);
    if (editor == null) {
        return;
    }
    final Project project = event.getData(CommonDataKeys.PROJECT);
    final Document document = editor.getDocument();
    final CaretModel caretModel = editor.getCaretModel();

    final Runnable replaceCaretSelections = () -> caretModel.getAllCarets().forEach(caret -> {
        final int start = caret.getSelectionStart();
        final int end = caret.getSelectionEnd();

        final String string = generateString();
        final int newEnd = start + string.length();

        document.replaceString(start, end, string);
        caret.setSelection(start, newEnd);
    });

    WriteCommandAction.runWriteCommandAction(project, replaceCaretSelections);
}
 
Example 12
Project: intellij-spring-assistant   File: SuggestionIndexServiceImpl.java   View source code 6 votes vote down vote up
@Nullable
@Override
public MetadataNode findDeepestExactMatch(Project project, Module module,
    List<String> containerElements) {
  if (moduleNameToSanitisedRootSearchIndex.containsKey(module.getName())) {
    String[] pathSegments =
        containerElements.stream().flatMap(element -> stream(toPathSegments(element)))
            .toArray(String[]::new);
    MetadataNode searchStartNode = moduleNameToSanitisedRootSearchIndex.get(module.getName())
        .get(MetadataNode.sanitize(pathSegments[0]));
    if (searchStartNode != null) {
      if (pathSegments.length > 1) {
        return searchStartNode.findDeepestMatch(pathSegments, 1, true);
      }
      return searchStartNode;
    }
  }
  return null;
}
 
Example 13
Project: idea-php-typo3-plugin   File: IconIndex.java   View source code 6 votes vote down vote up
@NotNull
public static PsiElement[] getIconDefinitionElements(@NotNull Project project, @NotNull String identifier) {
    Map<VirtualFile, IconStub> iconDefinitionByIdentifier = getIconDefinitionByIdentifier(project, identifier);
    if (iconDefinitionByIdentifier.size() > 0) {
        return iconDefinitionByIdentifier
                .keySet()
                .stream()
                .map(virtualFile -> {
                    IconStub iconStub = iconDefinitionByIdentifier.get(virtualFile);
                    PsiFile file = PsiManager.getInstance(project).findFile(virtualFile);
                    return file != null ? file.findElementAt(iconStub.getTextRange().getStartOffset()) : null;
                })
                .filter(Objects::nonNull)
                .toArray(PsiElement[]::new);
    }

    return new PsiElement[0];
}
 
Example 14
Project: Android-ORM-ASPlugin   File: ClassEntity.java   View source code 6 votes vote down vote up
public void addAnnotation(Project project) {
    for (FieldEntity entity : getFieldList()) {
        entity.addAnnotation(project);
    }

    editTableAnnotation(project, tablePsiAnnotation, getSelectedEntities().size() == 0);

    PsiJavaFile javaFile = (PsiJavaFile) psiClass.getContainingFile();
    Utils.saveDocument(javaFile);

    Utils.addImport(project, javaFile, null, AormConstants.tableQName, AormConstants.columnQName);
    Utils.optimizeImport(project, psiClass);

    CodeStyleManager.getInstance(project).reformat(psiClass);
    Utils.saveDocument(psiClass.getContainingFile());
}
 
Example 15
Project: MultiHighlight   File: MultiHighlightAction.java   View source code 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
    final PsiFile psiFile = e.getRequiredData(CommonDataKeys.PSI_FILE);
    
    CommandProcessor.getInstance().executeCommand(project, () -> {
        try {
            MultiHighlightHandler.invoke(project, editor, psiFile);
        } catch (IndexNotReadyException ex) {
            DumbService.getInstance(project)
                    .showDumbModeNotification("MultiHighlight requires indices "
                            + "and cannot be performed until they are built");
        }
    }, "MultiHighlight", null);
}
 
Example 16
Project: ValueClassGenerator   File: ValueClass.java   View source code 5 votes vote down vote up
public List<PsiElement> getGeneratedPsiElements(Project project) {
    PsiClass classFromText =
            JavaPsiFacade.getInstance(project).getElementFactory().createClassFromText(
                    new ValueClass(variables, sourceClass).asString(), null);
    classFromText.setName(sourceClass.getName());

    List<PsiElement> result = new ArrayList<>();
    Stream.of(classFromText.getAllFields()).forEach(psiField -> result.add(psiField));
    Stream.of(classFromText.getInnerClasses()).forEach(psiClass -> result.add(psiClass));
    Stream.of(classFromText.getMethods()).forEach(psiClass -> result.add(psiClass)); // getMethod contains all constructors
    return result;
}
 
Example 17
Project: json2java4idea   File: NewClassDialog.java   View source code 5 votes vote down vote up
private Builder(@NotNull Project project, @Nonnull Json2JavaBundle bundle) {
    this.project = project;
    this.bundle = bundle;
    this.nameValidator = new NullValidator();
    this.jsonValidator = new NullValidator();
    this.actionListener = new ActionListener() {
    };
}
 
Example 18
Project: CodeGen   File: DBGeneratorAction.java   View source code 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Project project = PsiUtil.getProject(e);
    DumbService dumbService = DumbService.getInstance(project);
    if (dumbService.isDumb()) {
        dumbService.showDumbModeNotification(CodeGenBundle.message("codegen.plugin.is.not.available.during.indexing"));
        return;
    }

    Iterator<DbElement> iterator = DatabaseView.getSelectedElements(e.getDataContext(), DbElement.class).iterator();

    List<DbTable> tables = new ArrayList<>();
    while (iterator.hasNext()) {
        DbElement table = iterator.next();
        if (table instanceof DbTable) {
            tables.add((DbTable) table);
        }
    }

    ColumnEditorFrame frame = new ColumnEditorFrame();
    frame.newColumnEditorByDb(new IdeaContext(project), tables);
    frame.setSize(800, 550);
    frame.setLocationRelativeTo(null);
    frame.setAlwaysOnTop(true);
    frame.setResizable(false);
    frame.setVisible(true);
}
 
Example 19
Project: IntelliJ-codestyle-sync   File: OnActionSync.java   View source code 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = e.getProject();
    if (project == null) {
        return;
    }
    new CodeStyleManager(project.getBasePath()).sync();
}
 
Example 20
Project: DeBrug   File: VisualisatieToestanden.java   View source code 5 votes vote down vote up
void TransformToPng() {
  Project project = MPSDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext());
  String filegv = ProjectBaseDirectory.getInstance(project).getBaseDir().getCanonicalPath() + "/graphviz/visualiser.gv";
  String filepng = ProjectBaseDirectory.getInstance(project).getBaseDir().getCanonicalPath() + "/graphviz/visualiser.png";
  String[] commandarray = {"/bin/sh", "-c", "neato " + "-Tpng " + filegv + " > " + filepng};
  System.out.println("Running command");
  String result = ExecuteCommand(commandarray);
  System.out.println("Command executed with result" + result);
}
 
Example 21
Project: yii2support   File: UnusedParameterLocalQuickFix.java   View source code 5 votes vote down vote up
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement item = descriptor.getPsiElement();

    PsiElement context = item.getContext();
    if (context instanceof ArrayCreationExpression) {
        ArrayCreationExpression params = (ArrayCreationExpression) item.getParent();

        PsiUtil.deleteArrayElement(item);

        if (!params.getHashElements().iterator().hasNext()) {
            if (params.getPrevSibling() instanceof PsiWhiteSpace) {
                params.getPrevSibling().delete();
            }
            params.getPrevSibling().delete();
            params.delete();
        }
    }
    if (context instanceof ParameterList && context.getParent() instanceof FunctionReference) {
        FunctionReference functionReference = (FunctionReference) context.getParent();
        if (functionReference.getName() != null && functionReference.getName().equals("compact")) {
            PsiUtil.deleteFunctionParam(item);

            if (functionReference.getParameters().length == 0) {
                PsiUtil.deleteFunctionParam(functionReference);
            }
        }
    }
}
 
Example 22
Project: yii2support   File: MissedViewLocalQuickFix.java   View source code 5 votes vote down vote up
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final PsiElement element = descriptor.getPsiElement().getParent();
    PsiDirectory directory;
    String path = null;

    if (element instanceof StringLiteralExpression) {
        path = ((StringLiteralExpression) element).getContents();
    }

    if (path == null) {
        return;
    }

    if (path.startsWith("/")) {
        directory = ViewsUtil.getRootDirectory(element);
        path = path.substring(1);
    } else {
        directory = ViewsUtil.getContextDirectory(element);
    }

    if (directory == null) {
        return;
    }

    while (directory != null && path.contains("/")) {
        final String subdirectory = path.substring(0, path.indexOf('/'));
        path = path.substring(path.indexOf('/') + 1);

        directory = directory.findSubdirectory(subdirectory);
    }

    if (directory != null) {
        if (!path.contains(".")) {
            path = path + ".php";
        }

        final PsiFile viewPsiFile = directory.createFile(path);
        FileEditorManager.getInstance(project).openFile(viewPsiFile.getVirtualFile(), true);

        final FileTemplate[] templates = FileTemplateManager.getDefaultInstance().getTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY);
        FileTemplate template = null;
        for (FileTemplate fileTemplate : templates) {
            if (fileTemplate.getName().equals("PHP File")) {
                template = fileTemplate;
                break;
            }
        }

        if (template != null && viewPsiFile.getViewProvider().getDocument() != null) {
            final Properties properties = FileTemplateManager.getDefaultInstance().getDefaultProperties();
            template.setLiveTemplateEnabled(true);
            template.setReformatCode(true);
            try {
                viewPsiFile.getViewProvider().getDocument().insertString(0, template.getText(properties));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 23
Project: jfrog-idea-plugin   File: SelectAllCheckbox.java   View source code 5 votes vote down vote up
void setListeners(@NotNull Project project, @NotNull Map<FilterType, Boolean> selectionMap, @NotNull List<SelectionCheckbox> checkBoxMenuItems) {
    removeListeners();
    addItemListener(e -> {
        selectionMap.entrySet().forEach(booleanEntry -> booleanEntry.setValue(isSelected()));

        for (JBCheckBoxMenuItem i : checkBoxMenuItems) {
            if (i.isSelected() != isSelected()) {
                i.doClick(0);
            }
        }
        MessageBus messageBus = project.getMessageBus();
        messageBus.syncPublisher(Events.ON_SCAN_FILTER_CHANGE).update();
    });
}
 
Example 24
Project: MultiHighlight   File: MultiHighlightHandler.java   View source code 5 votes vote down vote up
private static void searchSelection(Editor editor, Project project) {
    final SelectionModel selectionModel = editor.getSelectionModel();
    if (!selectionModel.hasSelection()) {
        selectionModel.selectWordAtCaret(false);
    }
    
    final String text = selectionModel.getSelectedText();
    if (text == null) {
        return;
    }
    
    if (editor instanceof EditorWindow) {
        // highlightUsages selection in the whole editor, not injected fragment only
        editor = ((EditorWindow) editor).getDelegate();
    }
    
    EditorSearchSession oldSearch = EditorSearchSession.get(editor);
    if (oldSearch != null) {
        if (oldSearch.hasMatches()) {
            String oldText = oldSearch.getTextInField();
            if (!oldSearch.getFindModel().isRegularExpressions()) {
                oldText = StringUtil.escapeToRegexp(oldText);
                oldSearch.getFindModel().setRegularExpressions(true);
            }
            
            String newText = oldText + '|' + StringUtil.escapeToRegexp(text);
            oldSearch.setTextInField(newText);
            return;
        }
    }
    
    EditorSearchSession.start(editor, project).getFindModel().setRegularExpressions(false);
}
 
Example 25
Project: idea-php-typo3-plugin   File: NewExtensionFileAction.java   View source code 5 votes vote down vote up
public void update(AnActionEvent event) {
    Project project = getEventProject(event);
    if (project == null) {
        this.setStatus(event, false);
        return;
    }

    if (DumbService.isDumb(project)) {
        this.setStatus(event, false);
        return;
    }

    this.setStatus(event, ExtensionUtility.getExtensionDirectory(event) != null);
}
 
Example 26
Project: educational-plugin   File: StudyRefreshTaskFileAction.java   View source code 5 votes vote down vote up
private static void showBalloon(@NotNull final Project project, @NotNull final MessageType messageType) {
  BalloonBuilder balloonBuilder =
    JBPopupFactory.getInstance().createHtmlTextBalloonBuilder("You can start again now", messageType, null);
  final Balloon balloon = balloonBuilder.createBalloon();
  StudyEditor selectedStudyEditor = StudyUtils.getSelectedStudyEditor(project);
  assert selectedStudyEditor != null;
  balloon.show(StudyUtils.computeLocation(selectedStudyEditor.getEditor()), Balloon.Position.above);
  Disposer.register(project, balloon);
}
 
Example 27
Project: Android-ORM-ASPlugin   File: Utils.java   View source code 5 votes vote down vote up
public static PsiDirectory getSubDir(Project project, VirtualFile vf) {
    if (vf.isDirectory()) {
        return PsiManager.getInstance(project).findDirectory(vf);
    } else {
        return getSubDir(project, vf.getParent());
    }
}
 
Example 28
Project: educational-plugin   File: StudyToolWindow.java   View source code 5 votes vote down vote up
public void setEmptyText(@NotNull Project project) {
  if (StudyTaskManager.getInstance(project).getToolWindowMode() == StudyToolWindowMode.EDITING) {
    mySplitPane.setFirstComponent(myContentPanel);
    StudyTaskManager.getInstance(project).setTurnEditingMode(true);
  }
  setTaskText(EMPTY_TASK_TEXT, project);
}
 
Example 29
Project: chocolate-cakephp   File: PsiUtil.java   View source code 5 votes vote down vote up
@NotNull
public static Collection<PsiFile> convertVirtualFilesToPsiFiles(@NotNull Project project, @NotNull Collection<VirtualFile> files) {

    Collection<PsiFile> psiFiles = new HashSet<>();
    PsiManager psiManager = PsiManager.getInstance(project);

    for (VirtualFile file : files) {
        PsiFile psiFile = psiManager.findFile(file);
        if(psiFile != null) {
            psiFiles.add(psiFile);
        }
    }

    return psiFiles;
}
 
Example 30
Project: educational-plugin   File: CCCreateLesson.java   View source code 5 votes vote down vote up
@Override
@Nullable
protected PsiDirectory createItemDir(@NotNull final Project project, @NotNull final StudyItem item,
                                  @Nullable final IdeView view, @NotNull final PsiDirectory parentDirectory,
                                  @NotNull final Course course) {
  EduPluginConfigurator configurator = EduPluginConfigurator.INSTANCE.forLanguage(course.getLanguageById());
  if (configurator == null) {
    return null;
  }
  return configurator.createLessonContent(project, (Lesson)item, view, parentDirectory);
}
 
Example 31
Project: Android-ORM-ASPlugin   File: Utils.java   View source code 5 votes vote down vote up
public static PsiJavaDirectoryImpl getJavaDir(Project project, VirtualFile vf) {
    PsiDirectory dir = Utils.getSubDir(project, vf);
    if (dir instanceof PsiJavaDirectoryImpl) {
        return (PsiJavaDirectoryImpl) dir;
    }
    return null;
}
 
Example 32
Project: educational-plugin   File: StudyUtils.java   View source code 5 votes vote down vote up
@Nullable
public static Editor getSelectedEditor(@NotNull final Project project) {
  final StudyEditor studyEditor = getSelectedStudyEditor(project);
  if (studyEditor != null) {
    return studyEditor.getEditor();
  }
  return null;
}
 
Example 33
Project: hybris-integration-intellij-idea-plugin   File: BpDiagramDataModel.java   View source code 5 votes vote down vote up
public BpDiagramDataModel(final Project project, final BpGraphNode rootBpGraphNode) {
    super(project, ServiceManager.getService(BpDiagramProvider.class));

    for (BpGraphNode bpGraphNode : rootBpGraphNode.getNodesMap().values()) {
        final BpDiagramFileNode bpDiagramFileNode = new BpDiagramFileNode(bpGraphNode);

        this.nodesMap.put(bpGraphNode.getGenericAction().getId(), bpDiagramFileNode);
    }
}
 
Example 34
Project: roc-completion   File: RocDocumentationProvider.java   View source code 5 votes vote down vote up
@Nullable
@Override
public String fetchExternalDocumentation(Project project, PsiElement psiElement, List<String> list)
{
    if (!CompletionPreloader.isRocConfigFile(psiElement.getContainingFile()))
    {
        return null;
    }

    String qualifiedName = list.get(0);
    SettingContainer completions = CompletionPreloader.getCompletions();

    Setting setting = completions.getSetting(qualifiedName);

    if (setting == null)
    {
        return "Just a container. Try looking at the sub-nodes instead.";
    }

    String description = escapeHtml(setting.getDescription());
    String descriptionTemplate = "<p>%s</p>";
    String documentation = String.format(descriptionTemplate, description);

    String defaultValue = escapeHtml(setting.getDefaultValue());

    if (defaultValue.length() == 0)
    {
        return documentation;
    }

    String defaultValueTemplate = "<p>Default value: %s</p>";
    String defaultValueDocumentation = String.format(defaultValueTemplate, defaultValue);

    return documentation.concat(defaultValueDocumentation);
}
 
Example 35
Project: json2java4idea   File: PsiTypeConverterTest.java   View source code 5 votes vote down vote up
@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    final Project project = getProject();
    final PsiManager psiManager = PsiManager.getInstance(project);
    underTest = new PsiTypeConverter(psiManager);
}
 
Example 36
Project: educational-plugin   File: CCSubtaskEditorNotificationProvider.java   View source code 5 votes vote down vote up
public SwitchSubtaskPopupStep(@Nullable String title,
                              List<Integer> values,
                              @NotNull TaskWithSubtasks task,
                              @NotNull Project project) {
  super(title, values);
  myTask = task;
  myProject = project;
}
 
Example 37
Project: json2java4idea   File: ProjectModule.java   View source code 5 votes vote down vote up
@Override
public void configure(@Nonnull Binder binder) {
    binder.bind(Project.class)
            .toInstance(project);

    // Binding InputValidator related classes
    binder.bind(InputValidator.class)
            .annotatedWith(Name.NAME_VALIDATOR.annotation())
            .to(NameValidator.class);
    binder.bind(InputValidator.class)
            .annotatedWith(Name.JSON_VALIDATOR.annotation())
            .to(JsonValidator.class);
    binder.bind(InputValidator.class)
            .annotatedWith(Name.CLASS_PREFIX_VALIDATOR.annotation())
            .to(ClassPrefixValidator.class);
    binder.bind(InputValidator.class)
            .annotatedWith(Name.CLASS_SUFFIX_VALIDATOR.annotation())
            .to(ClassSuffixValidator.class);

    // Binding NamePolicy classes
    binder.bind(NamePolicy.class)
            .annotatedWith(Name.CLASS_NAME_POLICY.annotation())
            .to(ClassNamePolicy.class);
    binder.bind(NamePolicy.class)
            .annotatedWith(Name.FIELD_NAME_POLICY.annotation())
            .to(FieldNamePolicy.class);
    binder.bind(NamePolicy.class)
            .annotatedWith(Name.METHOD_NAME_POLICY.annotation())
            .to(MethodNamePolicy.class);
    binder.bind(NamePolicy.class)
            .annotatedWith(Name.PARAMETER_NAME_POLICY.annotation())
            .to(ParameterNamePolicy.class);

    // Binding other classes
    binder.bind(Json2JavaBundle.class)
            .toInstance(Json2JavaBundle.getInstance());

    // Installation factory modules
    binder.install(new FactoryModuleBuilder().build(CommandActionFactory.class));
}
 
Example 38
Project: educational-plugin   File: CCPushLesson.java   View source code 5 votes vote down vote up
@Override
public void update(@NotNull AnActionEvent e) {
  e.getPresentation().setEnabledAndVisible(false);
  final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
  final Project project = e.getData(CommonDataKeys.PROJECT);
  if (view == null || project == null) {
    return;
  }
  final Course course = StudyTaskManager.getInstance(project).getCourse();
  if (course == null || !(course instanceof RemoteCourse)) {
    return;
  }
  if (!course.getCourseMode().equals(CCUtils.COURSE_MODE)) return;
  final PsiDirectory[] directories = view.getDirectories();
  if (directories.length == 0 || directories.length > 1) {
    return;
  }

  final PsiDirectory lessonDir = directories[0];
  if (lessonDir == null || !lessonDir.getName().contains("lesson")) {
    return;
  }
  final Lesson lesson = course.getLesson(lessonDir.getName());
  if (lesson != null && ((RemoteCourse)course).getId() > 0) {
    e.getPresentation().setEnabledAndVisible(true);
    if (lesson.getId() <= 0) {
      e.getPresentation().setText("Upload Lesson to Stepik");
    }
  }
}
 
Example 39
Project: educational-plugin   File: CCPushCourse.java   View source code 5 votes vote down vote up
@Override
public void update(@NotNull AnActionEvent e) {
  Presentation presentation = e.getPresentation();
  Project project = e.getProject();
  presentation.setEnabledAndVisible(project != null && CCUtils.isCourseCreator(project));
  if (project != null) {
    final Course course = StudyTaskManager.getInstance(project).getCourse();
    if (course instanceof RemoteCourse) {
      presentation.setText("Update Course on Stepik");
    }
  }
}
 
Example 40
Project: AppleScript-IDEA   File: LoadDictionaryAction.java   View source code 5 votes vote down vote up
public void actionPerformed(final AnActionEvent e) {
  DataContext dataContext = e.getDataContext();
  final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
  if (view == null) return;
  final PsiDirectory[] directories = view.getDirectories();

  PsiDirectory currentDirectory = directories.length > 0 ? directories[0] : null;
  final Project project = e.getData(CommonDataKeys.PROJECT);
  if (project == null) return;

  VirtualFile directoryFile = currentDirectory != null ? currentDirectory.getVirtualFile() : project.getBaseDir();
  openLoadDirectoryDialog(project, directoryFile, null);
}