Java Code Examples for com.intellij.util.ArrayUtil#isEmpty()

The following examples show how to use com.intellij.util.ArrayUtil#isEmpty() . 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: AbstractCommonCheckinAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
protected LocalChangeList getInitiallySelectedChangeList(@Nonnull VcsContext context, @Nonnull Project project) {
  LocalChangeList result;
  ChangeListManager manager = ChangeListManager.getInstance(project);
  ChangeList[] changeLists = context.getSelectedChangeLists();

  if (!ArrayUtil.isEmpty(changeLists)) {
    // convert copy to real
    result = manager.findChangeList(changeLists[0].getName());
  }
  else {
    Change[] changes = context.getSelectedChanges();
    result = !ArrayUtil.isEmpty(changes) ? manager.getChangeList(changes[0]) : manager.getDefaultChangeList();
  }

  return result;
}
 
Example 2
Source File: VcsLogCachesInvalidator.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void invalidateCaches() {
  if (PersistentUtil.LOG_CACHE.exists()) {
    String[] children = PersistentUtil.LOG_CACHE.list();
    if (!ArrayUtil.isEmpty(children)) {
      FileUtil.createIfDoesntExist(PersistentUtil.getCorruptionMarkerFile());
    }
  }
}
 
Example 3
Source File: CloneDvcsDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Check destination directory and set appropriate error text if there are problems
 *
 * @return true if destination components are OK.
 */
private boolean checkDestination() {
  if (myParentDirectory.getText().length() == 0 || myDirectoryName.getText().length() == 0) {
    setErrorText(null);
    setOKActionEnabled(false);
    return false;
  }
  File file = new File(myParentDirectory.getText(), myDirectoryName.getText());
  if (file.exists() && (!file.isDirectory()) || !ArrayUtil.isEmpty(file.list())) {
    setErrorText(DvcsBundle.message("clone.destination.exists.error", file));
    setOKActionEnabled(false);
    return false;
  }
  return true;
}
 
Example 4
Source File: VcsContextWrapper.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
@Override
public File[] getSelectedIOFiles() {
  File[] files = myContext.getData(VcsDataKeys.IO_FILE_ARRAY);
  if (!ArrayUtil.isEmpty(files)) return files;

  File file = myContext.getData(VcsDataKeys.IO_FILE);
  return file != null ? new File[]{file} : null;
}
 
Example 5
Source File: MoveChangesToAnotherListAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected boolean isEnabled(@Nonnull AnActionEvent e) {
  Project project = e.getData(CommonDataKeys.PROJECT);
  if (project == null || !ProjectLevelVcsManager.getInstance(project).hasActiveVcss()) {
    return false;
  }

  return !VcsUtil.isEmpty(e.getData(ChangesListView.UNVERSIONED_FILES_DATA_KEY)) ||
         !ArrayUtil.isEmpty(e.getData(VcsDataKeys.CHANGES)) ||
         !ArrayUtil.isEmpty(e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY));
}
 
Example 6
Source File: MacPathChooserDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void choose(@Nullable VirtualFile toSelect, @Nonnull Consumer<List<VirtualFile>> callback) {
  if (toSelect != null && toSelect.getParent() != null) {

    String directoryName;
    String fileName = null;
    if (toSelect.isDirectory()) {
      directoryName = toSelect.getCanonicalPath();
    }
    else {
      directoryName = toSelect.getParent().getCanonicalPath();
      fileName = toSelect.getPath();
    }
    myFileDialog.setDirectory(directoryName);
    myFileDialog.setFile(fileName);
  }


  myFileDialog.setFilenameFilter((dir, name) -> {
    File file = new File(dir, name);
    return myFileChooserDescriptor.isFileSelectable(fileToVirtualFile(file));
  });

  myFileDialog.setMultipleMode(myFileChooserDescriptor.isChooseMultiple());

  final CommandProcessorEx commandProcessor = ApplicationManager.getApplication() != null ? (CommandProcessorEx)CommandProcessor.getInstance() : null;
  final boolean appStarted = commandProcessor != null;


  if (appStarted) {
    commandProcessor.enterModal();
    LaterInvocator.enterModal(myFileDialog);
  }

  Component parent = myParent.get();
  try {
    myFileDialog.setVisible(true);
  }
  finally {
    if (appStarted) {
      commandProcessor.leaveModal();
      LaterInvocator.leaveModal(myFileDialog);
      if (parent != null) {
        IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
          IdeFocusManager.getGlobalInstance().requestFocus(parent, true);
        });
      }
    }
  }

  File[] files = myFileDialog.getFiles();
  List<VirtualFile> virtualFileList = getChosenFiles(Stream.of(files));
  virtualFiles = virtualFileList.toArray(VirtualFile.EMPTY_ARRAY);

  if (!virtualFileList.isEmpty()) {
    try {
      if (virtualFileList.size() == 1) {
        myFileChooserDescriptor.isFileSelectable(virtualFileList.get(0));
      }
      myFileChooserDescriptor.validateSelectedFiles(virtualFiles);
    }
    catch (Exception e) {
      if (parent == null) {
        Messages.showErrorDialog(myProject, e.getMessage(), myTitle);
      }
      else {
        Messages.showErrorDialog(parent, e.getMessage(), myTitle);
      }

      return;
    }

    if (!ArrayUtil.isEmpty(files)) {
      callback.consume(virtualFileList);
      return;
    }
  }
  if (callback instanceof FileChooser.FileChooserConsumer) {
    ((FileChooser.FileChooserConsumer)callback).cancelled();
  }
}
 
Example 7
Source File: WinPathChooserDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void choose(@Nullable VirtualFile toSelect, @Nonnull Consumer<List<VirtualFile>> callback) {
  if (toSelect != null && toSelect.getParent() != null) {

    String directoryName;
    String fileName = null;
    if (toSelect.isDirectory()) {
      directoryName = toSelect.getCanonicalPath();
    }
    else {
      directoryName = toSelect.getParent().getCanonicalPath();
      fileName = toSelect.getPath();
    }
    myFileDialog.setDirectory(directoryName);
    myFileDialog.setFile(fileName);
  }


  myFileDialog.setFilenameFilter((dir, name) -> {
    File file = new File(dir, name);
    return myFileChooserDescriptor.isFileSelectable(fileToVirtualFile(file));
  });

  myFileDialog.setMultipleMode(myFileChooserDescriptor.isChooseMultiple());

  final CommandProcessorEx commandProcessor = ApplicationManager.getApplication() != null ? (CommandProcessorEx)CommandProcessor.getInstance() : null;
  final boolean appStarted = commandProcessor != null;


  if (appStarted) {
    commandProcessor.enterModal();
    LaterInvocator.enterModal(myFileDialog);
  }

  Component parent = myParent.get();
  try {
    myFileDialog.setVisible(true);
  }
  finally {
    if (appStarted) {
      commandProcessor.leaveModal();
      LaterInvocator.leaveModal(myFileDialog);
      if (parent != null) parent.requestFocus();
    }
  }

  File[] files = myFileDialog.getFiles();
  List<VirtualFile> virtualFileList = getChosenFiles(Stream.of(files));
  virtualFiles = virtualFileList.toArray(VirtualFile.EMPTY_ARRAY);

  if (!virtualFileList.isEmpty()) {
    try {
      if (virtualFileList.size() == 1) {
        myFileChooserDescriptor.isFileSelectable(virtualFileList.get(0));
      }
      myFileChooserDescriptor.validateSelectedFiles(virtualFiles);
    }
    catch (Exception e) {
      if (parent == null) {
        Messages.showErrorDialog(myProject, e.getMessage(), myTitle);
      }
      else {
        Messages.showErrorDialog(parent, e.getMessage(), myTitle);
      }

      return;
    }

    if (!ArrayUtil.isEmpty(files)) {
      callback.consume(virtualFileList);
    }
    else if (callback instanceof FileChooser.FileChooserConsumer) {
      ((FileChooser.FileChooserConsumer)callback).cancelled();
    }
  }
}
 
Example 8
Source File: ScheduleForAdditionAction.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * {@link #isStatusForAddition(FileStatus)} checks file status to be {@link FileStatus.UNKNOWN} (if not overridden).
 * As an optimization, we assume that if {@link ChangesListView.UNVERSIONED_FILES_DATA_KEY} is empty, but {@link VcsDataKeys.CHANGES} is
 * not, then there will be either versioned (files from changes, hijacked files, locked files, switched files) or ignored files in
 * {@link VcsDataKeys.VIRTUAL_FILE_STREAM}. So there will be no files with {@link FileStatus.UNKNOWN} status and we should not explicitly
 * check {@link VcsDataKeys.VIRTUAL_FILE_STREAM} files in this case.
 */
protected boolean checkVirtualFiles(@Nonnull AnActionEvent e) {
  return ArrayUtil.isEmpty(e.getData(VcsDataKeys.CHANGES));
}