use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.
the class PsiDocumentManagerImplTest method testChangeDocumentThenEnterModalDialogThenCallPerformWhenAllCommittedShouldFireWhileInsideModal.
public void testChangeDocumentThenEnterModalDialogThenCallPerformWhenAllCommittedShouldFireWhileInsideModal() throws IOException {
VirtualFile vFile = getVirtualFile(createTempFile("a.txt", "abc"));
PsiFile psiFile = findFile(vFile);
final Document document = getDocument(psiFile);
final DialogWrapper dialog = new DialogWrapper(getProject()) {
@Nullable
@Override
protected JComponent createCenterPanel() {
return null;
}
};
disposeOnTearDown(() -> dialog.close(DialogWrapper.OK_EXIT_CODE));
ApplicationManager.getApplication().runWriteAction(() -> {
// commit thread is paused
document.setText("xx");
LaterInvocator.enterModal(dialog);
});
assertNotSame(ModalityState.NON_MODAL, ApplicationManager.getApplication().getCurrentModalityState());
// may or may not commit in background by default when modality changed
waitTenSecondsForCommit(document);
// but, when performWhenAllCommitted() in modal context called, should re-add documents into queue nevertheless
boolean[] calledPerformWhenAllCommitted = new boolean[1];
getPsiDocumentManager().performWhenAllCommitted(() -> calledPerformWhenAllCommitted[0] = true);
// must commit now
waitTenSecondsForCommit(document);
assertTrue(getPsiDocumentManager().isCommitted(document));
assertTrue(calledPerformWhenAllCommitted[0]);
}
use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.
the class MacMessagesTest method actionPerformed.
@Override
public void actionPerformed(final AnActionEvent anActionEvent) {
JDialog controlDialog = new JDialog();
controlDialog.setTitle("Messages testing control panel");
controlDialog.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
controlDialog.setModal(false);
controlDialog.setFocusableWindowState(false);
controlDialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Container cp = controlDialog.getContentPane();
cp.setLayout(new FlowLayout());
JButton showDialogWrapperButton = new JButton("Show a dialog wrapper");
showDialogWrapperButton.setFocusable(false);
FocusManagerImpl fmi = FocusManagerImpl.getInstance();
final Project p = fmi.getLastFocusedFrame().getProject();
showDialogWrapperButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
DialogWrapper dw = new SimpleDialogWrapper(p);
dw.setTitle(dw.getWindow().getName());
dw.show();
}
});
JButton showMessageButton = new JButton("Show a message");
showDialogWrapperButton.setFocusable(false);
showMessageButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
showTestMessage(p);
}
});
JButton showProgressIndicatorButton = new JButton("Show progress indicator");
showProgressIndicatorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final Task task = new Task.Modal(null, "Test task", true) {
public void run(@NotNull final ProgressIndicator indicator) {
ApplicationManager.getApplication().invokeAndWait(() -> {
FocusManagerImpl fmi1 = FocusManagerImpl.getInstance();
final Project p1 = fmi1.getLastFocusedFrame().getProject();
showTestMessage(p1);
}, ModalityState.any());
}
@Override
public void onCancel() {
}
};
ProgressManager.getInstance().run(task);
}
});
cp.add(showDialogWrapperButton);
cp.add(showMessageButton);
cp.add(showProgressIndicatorButton);
controlDialog.pack();
controlDialog.setVisible(true);
}
use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.
the class ShowUIDefaultsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final UIDefaults defaults = UIManager.getDefaults();
Enumeration keys = defaults.keys();
final Object[][] data = new Object[defaults.size()][2];
int i = 0;
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
data[i][0] = key;
data[i][1] = defaults.get(key);
i++;
}
Arrays.sort(data, (o1, o2) -> StringUtil.naturalCompare(o1[0].toString(), o2[0].toString()));
final Project project = getEventProject(e);
new DialogWrapper(project) {
{
setTitle("Edit LaF Defaults");
setModal(false);
init();
}
public JBTable myTable;
@Nullable
@Override
public JComponent getPreferredFocusedComponent() {
return myTable;
}
@Nullable
@Override
protected String getDimensionServiceKey() {
return project == null ? null : "UI.Defaults.Dialog";
}
@Override
protected JComponent createCenterPanel() {
final JBTable table = new JBTable(new DefaultTableModel(data, new Object[] { "Name", "Value" }) {
@Override
public boolean isCellEditable(int row, int column) {
return column == 1 && getValueAt(row, column) instanceof Color;
}
}) {
@Override
public boolean editCellAt(int row, int column, EventObject e) {
if (isCellEditable(row, column) && e instanceof MouseEvent) {
final Object color = getValueAt(row, column);
final Color newColor = ColorPicker.showDialog(this, "Choose Color", (Color) color, true, null, true);
if (newColor != null) {
final ColorUIResource colorUIResource = new ColorUIResource(newColor);
final Object key = getValueAt(row, 0);
UIManager.put(key, colorUIResource);
setValueAt(colorUIResource, row, column);
}
}
return false;
}
};
table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
final JPanel panel = new JPanel(new BorderLayout());
final JLabel label = new JLabel(value == null ? "" : value.toString());
panel.add(label, BorderLayout.CENTER);
if (value instanceof Color) {
final Color c = (Color) value;
label.setText(String.format("[r=%d,g=%d,b=%d] hex=0x%s", c.getRed(), c.getGreen(), c.getBlue(), ColorUtil.toHex(c)));
label.setForeground(ColorUtil.isDark(c) ? Color.white : Color.black);
panel.setBackground(c);
return panel;
} else if (value instanceof Icon) {
try {
final Icon icon = new IconWrap((Icon) value);
if (icon.getIconHeight() <= 20) {
label.setIcon(icon);
}
label.setText(String.format("(%dx%d) %s)", icon.getIconWidth(), icon.getIconHeight(), label.getText()));
} catch (Throwable e1) {
//
}
return panel;
} else if (value instanceof Border) {
try {
final Insets i = ((Border) value).getBorderInsets(null);
label.setText(String.format("[%d, %d, %d, %d] %s", i.top, i.left, i.bottom, i.right, label.getText()));
return panel;
} catch (Exception ignore) {
}
}
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
});
final JBScrollPane pane = new JBScrollPane(table);
new TableSpeedSearch(table, (o, cell) -> cell.column == 1 ? null : String.valueOf(o));
table.setShowGrid(false);
final JPanel panel = new JPanel(new BorderLayout());
panel.add(pane, BorderLayout.CENTER);
myTable = table;
TableUtil.ensureSelectionExists(myTable);
return panel;
}
}.show();
}
use of com.intellij.openapi.ui.DialogWrapper in project android by JetBrains.
the class AndroidUtils method showStackStace.
public static void showStackStace(@NotNull final Project project, @NotNull Throwable[] throwables) {
final StringBuilder messageBuilder = new StringBuilder();
for (Throwable t : throwables) {
if (messageBuilder.length() > 0) {
messageBuilder.append("\n\n");
}
messageBuilder.append(AndroidCommonUtils.getStackTrace(t));
}
final DialogWrapper wrapper = new DialogWrapper(project, false) {
{
init();
}
@Override
protected JComponent createCenterPanel() {
final JPanel panel = new JPanel(new BorderLayout());
final JTextArea textArea = new JTextArea(messageBuilder.toString());
textArea.setEditable(false);
textArea.setRows(40);
textArea.setColumns(70);
panel.add(ScrollPaneFactory.createScrollPane(textArea));
return panel;
}
};
wrapper.setTitle("Stack Trace");
wrapper.show();
}
use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.
the class GitUntrackedFilesHelper method notifyUntrackedFilesOverwrittenBy.
/**
* Displays notification about {@code untracked files would be overwritten by checkout} error.
* Clicking on the link in the notification opens a simple dialog with the list of these files.
* @param root
* @param relativePaths
* @param operation the name of the Git operation that caused the error: {@code rebase, merge, checkout}.
* @param description the content of the notification or null if the default content is to be used.
*/
public static void notifyUntrackedFilesOverwrittenBy(@NotNull final Project project, @NotNull final VirtualFile root, @NotNull Collection<String> relativePaths, @NotNull final String operation, @Nullable String description) {
final String notificationTitle = StringUtil.capitalize(operation) + " failed";
final String notificationDesc = description == null ? createUntrackedFilesOverwrittenDescription(operation, true) : description;
final Collection<String> absolutePaths = GitUtil.toAbsolute(root, relativePaths);
final List<VirtualFile> untrackedFiles = ContainerUtil.mapNotNull(absolutePaths, new Function<String, VirtualFile>() {
@Override
public VirtualFile fun(String absolutePath) {
return GitUtil.findRefreshFileOrLog(absolutePath);
}
});
VcsNotifier.getInstance(project).notifyError(notificationTitle, notificationDesc, new NotificationListener() {
@Override
public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
final String dialogDesc = createUntrackedFilesOverwrittenDescription(operation, false);
String title = "Untracked Files Preventing " + StringUtil.capitalize(operation);
if (untrackedFiles.isEmpty()) {
GitUtil.showPathsInDialog(project, absolutePaths, title, dialogDesc);
} else {
DialogWrapper dialog;
dialog = new UntrackedFilesDialog(project, untrackedFiles, dialogDesc);
dialog.setTitle(title);
dialog.show();
}
}
}
});
}
Aggregations