Java Code Examples for com.intellij.openapi.ui.DialogWrapper#showAndGet()

The following examples show how to use com.intellij.openapi.ui.DialogWrapper#showAndGet() . 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: DelimitedListAction.java    From StringManipulation with Apache License 2.0 4 votes vote down vote up
private Pair<Boolean, Settings> showDialog(Editor editor) {
	final DelimitedListDialog dialog = new DelimitedListDialog(this, editor);
	DialogWrapper dialogWrapper = new DialogWrapper(editor.getProject()) {
		{
			init();
			setTitle("Delimited List Options");
		}

		@Override
		protected void dispose() {
			super.dispose();
			dialog.dispose();
		}

		@Override
		public JComponent getPreferredFocusedComponent() {
			return dialog.destDelimiter;
		}

		@Override
		protected String getDimensionServiceKey() {
			return "StringManipulation.DelimitedListDialog";
		}

		@Override
		protected JComponent createCenterPanel() {
			return dialog.contentPane;
		}

		@Override
		protected void doOKAction() {
			super.doOKAction();
		}
	};

	boolean okPressed = dialogWrapper.showAndGet();
	if (!okPressed) {
		return Pair.create(false, null);
	}

	return Pair.create(true, dialog.toSettings());
}
 
Example 2
Source File: SortTokensAction.java    From StringManipulation with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("Duplicates")
@Nullable
protected SortTokensModel getSortSettings(final Editor editor) {
	final SortTokensGui dialog = new SortTokensGui(PluginPersistentStateComponent.getInstance().guessSortTokensModel(editor), editor);
	DialogWrapper dialogWrapper = new DialogWrapper(editor.getProject()) {
		{
			init();
			setTitle("Sort Tokens");
		}

		@Nullable
		@Override
		public JComponent getPreferredFocusedComponent() {
			return dialog.getPreferredFocusedComponent();
		}

		@Nullable
		@Override
		protected String getDimensionServiceKey() {
			return "StringManipulation.SortTokensDialog";
		}

		@Nullable
		@Override
		protected JComponent createCenterPanel() {
			return dialog.root;
		}


		@Override
		protected void doOKAction() {
			super.doOKAction();
		}
	};

	boolean b = dialogWrapper.showAndGet();
	if (!b) {
		return null;
	}
	SortTokensModel settings = dialog.getModel();
	PluginPersistentStateComponent.getInstance().storeModel(settings);
	return settings;
}
 
Example 3
Source File: SortLinesBySubSelectionAction.java    From StringManipulation with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("Duplicates")
@Nullable
protected SortSettings getSortSettings(final Editor editor) {
	final SortTypeDialog dialog = new SortTypeDialog(PluginPersistentStateComponent.getInstance().getSortSettings(), false, editor) {
		@Override
		protected List<String> sort(Editor editor1, SortSettings settings) {
			List<CaretState> caretsAndSelections = editor1.getCaretModel().getCaretsAndSelections();
			IdeUtils.sort(caretsAndSelections);
			List<SubSelectionSortLine> lines = getLines(editor, getSettings(), caretsAndSelections);

			List<SubSelectionSortLine> sortedLines = settings.getSortType().sortLines(lines, settings.getBaseComparator(), settings.getCollatorLanguageTag());

			List<String> result = new ArrayList<>();
			for (SubSelectionSortLine sortedLine : sortedLines) {
				result.add(sortedLine.line);
			}
			return result;
		}
	};
	DialogWrapper dialogWrapper = new DialogWrapper(editor.getProject()) {
		{
			init();
			setTitle("Sort Lines by Subselection");
		}

		@Nullable
		@Override
		public JComponent getPreferredFocusedComponent() {
			return dialog.insensitive;
		}

		@Nullable
		@Override
		protected String getDimensionServiceKey() {
			return "StringManipulation.SortLinesBySubSelection";
		}

		@Nullable
		@Override
		protected JComponent createCenterPanel() {
			return dialog.contentPane;
		}

		@Override
		protected void doOKAction() {
			super.doOKAction();
		}

	};

	boolean b = dialogWrapper.showAndGet();
	if (!b) {
		return null;
	}
	SortSettings sortSettings = dialog.getSettings().preserveLeadingSpaces(false).preserveTrailingSpecialCharacters(false);
	PluginPersistentStateComponent.getInstance().setSortSettings(sortSettings);
	return sortSettings;
}
 
Example 4
Source File: SortAction.java    From StringManipulation with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("Duplicates")
@Nullable
protected SortSettings getSortSettings(final Editor editor) {
	final SortTypeDialog dialog = new SortTypeDialog(getSortSettings(storeKey), true, editor);
	DialogWrapper dialogWrapper = new DialogWrapper(editor.getProject()) {
		{
			init();
			setTitle("Sort Lines");
		}

		@Nullable
		@Override
		public JComponent getPreferredFocusedComponent() {
			return dialog.insensitive;
		}

		@Nullable
		@Override
		protected String getDimensionServiceKey() {
			return "StringManipulation.SortTypeDialog";
		}

		@Nullable
		@Override
		protected JComponent createCenterPanel() {
			return dialog.contentPane;
		}


		@Override
		protected void doOKAction() {
			super.doOKAction();
		}
	};

	boolean b = dialogWrapper.showAndGet();
	if (!b) {
		return null;
	}
	SortSettings settings = dialog.getSettings();
	PluginPersistentStateComponent.getInstance().setSortSettings(settings);
	return settings;
}
 
Example 5
Source File: DecodeBase64Action.java    From StringManipulation with Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public Pair<Boolean, Charset> beforeWriteAction(Editor editor, DataContext dataContext) {
	final Base64EncodingDialog base64EncodingDialog = new Base64EncodingDialog();
	DialogWrapper dialogWrapper = new DialogWrapper(editor.getProject()) {
		{
			init();
			setTitle("Choose Charset");
		}

		@Nullable
		@Override
		public JComponent getPreferredFocusedComponent() {
			return base64EncodingDialog.myComboBox;
		}

		@Nullable
		@Override
		protected String getDimensionServiceKey() {
			return "StringManipulation.Base64DecodingDialog";
		}

		@Nullable
		@Override
		protected JComponent createCenterPanel() {
			return base64EncodingDialog.myComboBox;
		}

		@Override
		protected void doOKAction() {
			super.doOKAction();
		}
	};

	boolean b = dialogWrapper.showAndGet();
	if (!b) {
		return stopExecution();
	}

	try {
		Charset charset = Charset.forName(base64EncodingDialog.getCharset());
		return continueExecution(charset);
	} catch (Exception e) {
		Messages.showErrorDialog(editor.getProject(), String.valueOf(e), "Invalid Charset");
		return stopExecution();
	}
}
 
Example 6
Source File: DecodeHexAction.java    From StringManipulation with Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public Pair<Boolean, Charset> beforeWriteAction(Editor editor, DataContext dataContext) {
    String dimensionServiceKey = getDimensionServiceKey();
    DialogWrapper dialogWrapper = new DialogWrapper(editor.getProject()) {
        {
            init();
            setTitle("Choose Charset");
        }

        @Nullable
        @Override
        public JComponent getPreferredFocusedComponent() {
            return charsetComboBox;
        }

        @Nullable
        @Override
        protected String getDimensionServiceKey() {
            return dimensionServiceKey;
        }

        @Nullable
        @Override
        protected JComponent createCenterPanel() {
            return charsetComboBox;
        }

        @Override
        protected void doOKAction() {
            super.doOKAction();
        }
    };

    boolean b = dialogWrapper.showAndGet();
    if (!b) {
        return stopExecution();
    }

    try {
        Charset charset = Charset.forName(getCharset());
        return continueExecution(charset);
    } catch (Exception e) {
        Messages.showErrorDialog(editor.getProject(), String.valueOf(e), "Invalid Charset");
        return stopExecution();
    }
}
 
Example 7
Source File: EncodeBase64Action.java    From StringManipulation with Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public Pair<Boolean, Base64EncodingDialog> beforeWriteAction(Editor editor, DataContext dataContext) {
	final Base64EncodingDialog base64EncodingDialog = new Base64EncodingDialog();
	DialogWrapper dialogWrapper = new DialogWrapper(editor.getProject()) {
		{
			init();
			setTitle("Base64 Encoding Options");
		}

		@Nullable
		@Override
		public JComponent getPreferredFocusedComponent() {
			return base64EncodingDialog.myComboBox;
		}

		@Nullable
		@Override
		protected String getDimensionServiceKey() {
			return "StringManipulation.Base64EncodingDialog";
		}

		@Nullable
		@Override
		protected JComponent createCenterPanel() {
			return base64EncodingDialog.contentPane;
		}

		@Override
		protected void doOKAction() {
			super.doOKAction();
		}
	};

	boolean b = dialogWrapper.showAndGet();
	if (!b) {
		return stopExecution();
	}


	try {
		Charset.forName(base64EncodingDialog.getCharset());
	} catch (Exception e) {
		Messages.showErrorDialog(editor.getProject(), String.valueOf(e), "Invalid Charset");
		return stopExecution();
	}
	return continueExecution(base64EncodingDialog);
}
 
Example 8
Source File: FileDocumentManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void handleErrorsOnSave(@Nonnull Map<Document, IOException> failures) {
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    IOException ioException = ContainerUtil.getFirstItem(failures.values());
    if (ioException != null) {
      throw new RuntimeException(ioException);
    }
    return;
  }
  for (IOException exception : failures.values()) {
    LOG.warn(exception);
  }

  final String text = StringUtil.join(failures.values(), Throwable::getMessage, "\n");

  final DialogWrapper dialog = new DialogWrapper(null) {
    {
      init();
      setTitle(UIBundle.message("cannot.save.files.dialog.title"));
    }

    @Override
    protected void createDefaultActions() {
      super.createDefaultActions();
      myOKAction.putValue(Action.NAME, UIBundle.message(myOnClose ? "cannot.save.files.dialog.ignore.changes" : "cannot.save.files.dialog.revert.changes"));
      myOKAction.putValue(DEFAULT_ACTION, null);

      if (!myOnClose) {
        myCancelAction.putValue(Action.NAME, CommonBundle.getCloseButtonText());
      }
    }

    @Override
    protected JComponent createCenterPanel() {
      final JPanel panel = new JPanel(new BorderLayout(0, 5));

      panel.add(new JLabel(UIBundle.message("cannot.save.files.dialog.message")), BorderLayout.NORTH);

      final JTextPane area = new JTextPane();
      area.setText(text);
      area.setEditable(false);
      area.setMinimumSize(new Dimension(area.getMinimumSize().width, 50));
      panel.add(new JBScrollPane(area, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);

      return panel;
    }
  };

  if (dialog.showAndGet()) {
    for (Document document : failures.keySet()) {
      reloadFromDisk(document);
    }
  }
}