consulo.util.dataholder.Key Java Examples

The following examples show how to use consulo.util.dataholder.Key. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContentFolderImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public <T> void setPropertyValue(@Nonnull Key<T> key, @Nullable T value) {
  myPropertiesByKeyCache = null;

  if (value == null && myProperties == null) {
    return;
  }

  if (value == null) {
    myProperties.remove(key.toString());
  }
  else {
    if (myProperties == null) {
      myProperties = new HashMap<String, Object>();
    }

    myProperties.put(key.toString(), value);
  }
}
 
Example #2
Source File: RepositoryChangesBrowser.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Object getData(@Nonnull Key<?> dataId) {
  if (CommittedChangesBrowserUseCase.DATA_KEY == dataId) {
    return myUseCase;
  }

  else if (VcsDataKeys.SELECTED_CHANGES == dataId) {
    final List<Change> list = myViewer.getSelectedChanges();
    return list.toArray(new Change[list.size()]);
  }
  else if (VcsDataKeys.CHANGE_LEAD_SELECTION == dataId) {
    final Change highestSelection = myViewer.getHighestLeadSelection();
    return (highestSelection == null) ? new Change[]{} : new Change[]{highestSelection};
  }
  else {
    final TypeSafeDataProviderAdapter adapter = new TypeSafeDataProviderAdapter(this);
    return adapter.getData(dataId);
  }
}
 
Example #3
Source File: AbstractArtifactsBeforeRunTaskProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
public AbstractArtifactsBeforeRunTaskProvider(Project project, Key<T> id) {
  myProject = project;
  myId = id;
  project.getMessageBus().connect().subscribe(ArtifactManager.TOPIC, new ArtifactListener() {
    @Override
    public void artifactRemoved(@Nonnull Artifact artifact) {
      final RunManagerEx runManager = RunManagerEx.getInstanceEx(myProject);
      for (RunConfiguration configuration : runManager.getAllConfigurationsList()) {
        final List<T> tasks = runManager.getBeforeRunTasks(configuration, getId());
        for (AbstractArtifactsBeforeRunTask task : tasks) {
          final String artifactName = artifact.getName();
          final List<ArtifactPointer> pointersList = task.getArtifactPointers();
          final ArtifactPointer[] pointers = pointersList.toArray(new ArtifactPointer[pointersList.size()]);
          for (ArtifactPointer pointer : pointers) {
            if (pointer.getName().equals(artifactName) && ArtifactManager.getInstance(myProject).findArtifact(artifactName) == null) {
              task.removeArtifact(pointer);
            }
          }
        }
      }
    }
  });
}
 
Example #4
Source File: DiffPanelImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Object getData(@Nonnull Key<?> dataId) {
  if (PlatformDataKeys.DIFF_VIEWER == dataId) {
    return myDiffPanel;
  }
  if (FocusDiffSide.DATA_KEY == dataId) {
    return myDiffPanel.myCurrentSide == null ? null : myFocusDiffSide;
  }
  if (CommonDataKeys.NAVIGATABLE == dataId) {
    final DiffSideView currentSide = myDiffPanel.myCurrentSide;
    if (currentSide != null) {
      return new DiffNavigatable(currentSide);
    }
  }
  if (PlatformDataKeys.HELP_ID == dataId) {
    return "reference.dialogs.diff.file";
  }

  return super.getData(dataId);
}
 
Example #5
Source File: EditorGutterComponentImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Object getData(@Nonnull @NonNls Key dataId) {
  if (myEditor.isDisposed()) return null;

  if (EditorGutter.KEY == dataId) {
    return this;
  }
  if (CommonDataKeys.EDITOR == dataId) {
    return myEditor;
  }
  if (EditorGutterComponentEx.LOGICAL_LINE_AT_CURSOR == dataId) {
    if (myLastActionableClick == null) return null;
    return myLastActionableClick.myLogicalLineAtCursor;
  }
  if (EditorGutterComponentEx.ICON_CENTER_POSITION == dataId) {
    if (myLastActionableClick == null) return null;
    return myLastActionableClick.myIconCenterPosition;
  }
  return null;
}
 
Example #6
Source File: AnsiEscapeDecoder.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private List<Pair<String, Key>> processTextChunk(@Nullable List<Pair<String, Key>> buffer,
                                                 @Nonnull String text,
                                                 @Nonnull Key outputType,
                                                 @Nonnull ColoredTextAcceptor textAcceptor) {
  Key attributes = getCurrentOutputAttributes(outputType);
  if (textAcceptor instanceof ColoredChunksAcceptor) {
    if (buffer == null) {
      buffer = ContainerUtil.newArrayListWithCapacity(1);
    }
    buffer.add(Pair.create(text, attributes));
  }
  else {
    textAcceptor.coloredTextAvailable(text, attributes);
  }
  return buffer;
}
 
Example #7
Source File: FileSearchEverywhereContributor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Object getDataForItem(@Nonnull Object element, @Nonnull Key dataId) {
  if (CommonDataKeys.PSI_FILE == dataId && element instanceof PsiFile) {
    return element;
  }

  if (SearchEverywhereDataKeys.ITEM_STRING_DESCRIPTION == dataId && element instanceof PsiFile) {
    String path = ((PsiFile)element).getVirtualFile().getPath();
    path = FileUtil.toSystemIndependentName(path);
    if (myProject != null) {
      String basePath = myProject.getBasePath();
      if (basePath != null) {
        path = FileUtil.getRelativePath(basePath, path, '/');
      }
    }
    return path;
  }

  return super.getDataForItem(element, dataId);
}
 
Example #8
Source File: MapBackedFMap.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public KeyFMap minus(@Nonnull Key<?> key) {
  int oldSize = size();
  int keyCode = key.hashCode();
  if (!containsKey(keyCode)) {
    return this;
  }
  if (oldSize == ArrayBackedFMap.ARRAY_THRESHOLD + 1) {
    int[] keys = keys();
    Object[] values = getValues();
    int i = ArrayUtil.indexOf(keys, keyCode);
    keys = ArrayUtil.remove(keys, i);
    values = ArrayUtil.remove(values, i);
    return new ArrayBackedFMap(keys, values);
  }
  return new MapBackedFMap(this, keyCode);
}
 
Example #9
Source File: SearchReplaceComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Object getData(@Nonnull @NonNls Key dataId) {
  if (SpeedSearchSupply.SPEED_SEARCH_CURRENT_QUERY == dataId) {
    return mySearchTextComponent.getText();
  }
  if (TouchbarDataKeys.ACTIONS_KEY == dataId) {
    if (myTouchbarActions == null) {
      myTouchbarActions = new DefaultActionGroup();
      myTouchbarActions.add(new PrevOccurrenceAction());
      myTouchbarActions.add(new NextOccurrenceAction());
    }
    return myTouchbarActions;
  }
  return myDataProviderDelegate != null ? myDataProviderDelegate.getData(dataId) : null;
}
 
Example #10
Source File: TextEditorComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Object getData(@Nonnull final Key<?> dataId) {
  final Editor e = validateCurrentEditor();
  if (e == null || e.isDisposed()) return null;

  // There's no FileEditorManager for default project (which is used in diff command-line application)
  if (!myProject.isDisposed() && !myProject.isDefault()) {
    final Object o = FileEditorManager.getInstance(myProject).getData(dataId, e, e.getCaretModel().getCurrentCaret());
    if (o != null) return o;
  }

  if (CommonDataKeys.EDITOR == dataId) {
    return e;
  }
  if (CommonDataKeys.VIRTUAL_FILE == dataId) {
    return myFile.isValid() ? myFile : null;  // fix for SCR 40329
  }
  return null;
}
 
Example #11
Source File: DesktopIdeFrameImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Object getData(@Nonnull Key<?> dataId) {
  if (CommonDataKeys.PROJECT == dataId) {
    if (myProject != null) {
      return myProject.isInitialized() ? myProject : null;
    }
  }

  if (IdeFrame.KEY == dataId) {
    return this;
  }

  return null;
}
 
Example #12
Source File: ApplyPatchViewer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Object getData(@Nonnull @NonNls Key<?> dataId) {
  if (CommonDataKeys.PROJECT == dataId) {
    return myProject;
  }
  else if (DiffDataKeys.PREV_NEXT_DIFFERENCE_ITERABLE == dataId) {
    return myPrevNextDifferenceIterable;
  }
  return null;
}
 
Example #13
Source File: DirectoryGroupingRule.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void calcData(final Key<?> key, final DataSink sink) {
  if (!isValid()) return;
  if (LangDataKeys.PSI_ELEMENT == key) {
    sink.put(LangDataKeys.PSI_ELEMENT, myPackage);
  }
}
 
Example #14
Source File: GeneralIdBasedToSMTRunnerEventsConvertor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void onUncapturedOutput(@Nonnull final String text, final Key outputType) {
  addToInvokeLater(() -> {
    Node activeNode = findActiveNode();
    SMTestProxy activeProxy = activeNode.getProxy();
    activeProxy.addOutput(text, outputType);
  });
}
 
Example #15
Source File: GlassPaneDialogWrapperPeer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Object getData(@Nonnull Key<?> dataId) {
  final DialogWrapper wrapper = myDialogWrapper.get();
  if (wrapper instanceof DataProvider) {
    return ((DataProvider)wrapper).getData(dataId);
  }
  else if (wrapper instanceof TypeSafeDataProvider) {
    TypeSafeDataProviderAdapter adapter = new TypeSafeDataProviderAdapter((TypeSafeDataProvider)wrapper);
    return adapter.getData(dataId);
  }
  return null;
}
 
Example #16
Source File: EditorTabbedContainer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Object getData(@Nonnull Key<?> dataId) {
  if (CommonDataKeys.PROJECT == dataId) {
    return myProject;
  }
  if (CommonDataKeys.VIRTUAL_FILE == dataId) {
    final VirtualFile selectedFile = myWindow.getSelectedFile();
    return selectedFile != null && selectedFile.isValid() ? selectedFile : null;
  }
  if (DesktopEditorWindow.DATA_KEY == dataId) {
    return myWindow;
  }
  if (PlatformDataKeys.HELP_ID == dataId) {
    return HELP_ID;
  }

  if (CloseAction.CloseTarget.KEY == dataId) {
    TabInfo selected = myTabs.getSelectedInfo();
    if (selected != null) {
      return EditorTabbedContainer.this;
    }
  }

  if (DesktopEditorWindow.DATA_KEY == dataId) {
    return myWindow;
  }

  return null;
}
 
Example #17
Source File: RunnerLayoutUiImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Object getData(@Nonnull @NonNls Key dataId) {
  if (QuickActionProvider.KEY == dataId || RunnerContentUi.KEY == dataId) {
    return myContentUI;
  }
  return null;
}
 
Example #18
Source File: RunAnythingPopupUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private DataContext getDataContext() {
  HashMap<Key, Object> dataMap = new HashMap<>();
  dataMap.put(CommonDataKeys.PROJECT, getProject());
  dataMap.put(LangDataKeys.MODULE, getModule());
  dataMap.put(CommonDataKeys.VIRTUAL_FILE, getWorkDirectory());
  dataMap.put(EXECUTOR_KEY, getExecutor());
  dataMap.put(RunAnythingProvider.EXECUTING_CONTEXT, myChooseContextAction.getSelectedContext());
  return SimpleDataContext.getSimpleContext(dataMap, myActionEvent.getDataContext());
}
 
Example #19
Source File: LookupItem.java    From consulo with Apache License 2.0 5 votes vote down vote up
public <T> void setAttribute(Key<T> key, T value){
  if (value == null && myAttributes != null) {
    myAttributes.remove(key);
    return;
  }

  if (myAttributes == null){
    myAttributes = new HashMap<Object, Object>(5);
  }
  myAttributes.put(key, value);
}
 
Example #20
Source File: OnesideTextDiffViewer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Object getData(@Nonnull @NonNls Key<?> dataId) {
  if (DiffDataKeys.CURRENT_EDITOR == dataId) {
    return getEditor();
  }
  return super.getData(dataId);
}
 
Example #21
Source File: DesktopToolWindowContentUi.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public Object getData(@Nonnull @NonNls Key<?> dataId) {
  if (PlatformDataKeys.TOOL_WINDOW == dataId) return myWindow;

  if (CloseAction.CloseTarget.KEY == dataId) {
    return computeCloseTarget();
  }

  return null;
}
 
Example #22
Source File: DiffRequestProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
@Override
public Object getData(@NonNls Key<?> dataId) {
  if (DiffDataKeys.WRAPPING_DIFF_VIEWER == dataId) {
    return myWrapperViewer;
  }
  if (DiffDataKeys.DIFF_VIEWER == dataId) {
    return myViewer;
  }
  return null;
}
 
Example #23
Source File: FindInProjectUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void calcData(@Nonnull Key key, @Nonnull DataSink sink) {
  if (UsageView.USAGE_SCOPE == key) {
    SearchScope scope = getScopeFromModel(myProject, myFindModel);
    sink.put(UsageView.USAGE_SCOPE, scope);
  }
}
 
Example #24
Source File: OutputLineSplitterTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testReadingSeveralStreams() throws Exception {
  final Map<Key, List<String>> written = new ConcurrentHashMap<Key, List<String>>();
  for (final Key each : ALL_TYPES) {
    written.put(each, new ArrayList<String>());
    execute(new Runnable() {
      @Override
      public void run() {
        Random r = new Random();
        for (int i = 0; i < 1000; i++) {
          String s = StringUtil.repeat("A", 100 + r.nextInt(1000));
          if (r.nextInt(1) == 1) s += "\n";

          mySplitter.process(s, each);
          List<String> list = written.get(each);
          if (!list.isEmpty()) {
            String last = list.get(list.size() - 1);
            if (!last.endsWith("\n")) {
              list.set(list.size() - 1, last + s);
              continue;
            }
          }
          list.add(s);
        }
      }
    }).get();
  }

  mySplitter.flush();

  for (Key eachType : ALL_TYPES) {
    assertOrderedEquals(myOutput.get(eachType), written.get(eachType));
  }
}
 
Example #25
Source File: XWatchesViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Object getData(@Nonnull Key<?> dataId) {
  if (XWatchesView.DATA_KEY == dataId) {
    return this;
  }
  return super.getData(dataId);
}
 
Example #26
Source File: HttpFileEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public <T> void putUserData(@Nonnull Key<T> key, @Nullable T value) {
  final TextEditor textEditor = myPanel.getFileEditor();
  if (textEditor != null) {
    textEditor.putUserData(key, value);
  }
  else {
    myUserDataHolder.putUserData(key, value);
  }
}
 
Example #27
Source File: DefaultLogFilterModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public MyProcessingResult processLine(String line) {
  final String type = LogConsolePreferences.getType(line);
  Key contentType = type != null
                    ? LogConsolePreferences.getProcessOutputTypes(type)
                    : (LogConsolePreferences.ERROR.equals(myPrevType) ? ProcessOutputTypes.STDERR : ProcessOutputTypes.STDOUT);
  if (type != null) {
    myPrevType = type;
  }
  final boolean applicable = isApplicable(line);
  return new MyProcessingResult(contentType, applicable, null);
}
 
Example #28
Source File: FileGroupingRule.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void calcData(final Key<?> key, final DataSink sink) {
  if (!isValid()) return;
  if (key == CommonDataKeys.VIRTUAL_FILE) {
    sink.put(CommonDataKeys.VIRTUAL_FILE, myFile);
  }
  if (key == CommonDataKeys.PSI_ELEMENT) {
    sink.put(CommonDataKeys.PSI_ELEMENT, getPsiFile());
  }
}
 
Example #29
Source File: HackyDataContext.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T getData(@Nonnull Key<T> dataId) {
  if (values.keySet().contains(dataId)) {
    return (T)values.get(dataId);
  }
  //noinspection UseOfSystemOutOrSystemErr
  System.out.println("Please add " + dataId + " key in " + getClass().getName());
  return null;
}
 
Example #30
Source File: TwosideDiffViewer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Object getData(@Nonnull @NonNls Key<?> dataId) {
  if (CommonDataKeys.VIRTUAL_FILE == dataId) {
    return DiffUtil.getVirtualFile(myRequest, getCurrentSide());
  }
  else if (DiffDataKeys.CURRENT_CONTENT == dataId) {
    return getCurrentSide().select(myRequest.getContents());
  }
  return super.getData(dataId);
}