use of org.openide.DialogDescriptor in project gephi by gephi.
the class DataLaboratoryHelper method executeManipulator.
/**
* Prepares the dialog UI of a manipulator if it has one and executes the manipulator in a separate
* Thread when the dialog is accepted or directly if there is no UI.
* @param m Manipulator to execute
*/
public void executeManipulator(final Manipulator m) {
if (m.canExecute()) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
final ManipulatorUI ui = m.getUI();
// Show a dialog for the manipulator UI if it provides one. If not, execute the manipulator directly:
if (ui != null) {
final JButton okButton = new JButton(NbBundle.getMessage(DataLaboratoryHelper.class, "DataLaboratoryHelper.ui.okButton.text"));
DialogControls dialogControls = new DialogControlsImpl(okButton);
ui.setup(m, dialogControls);
JPanel settingsPanel = ui.getSettingsPanel();
DialogDescriptor dd = new DialogDescriptor(settingsPanel, NbBundle.getMessage(DataLaboratoryHelper.class, "SettingsPanel.title", ui.getDisplayName()), ui.isModal(), new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(okButton)) {
ui.unSetup();
executeManipulatorInOtherThread(m);
} else {
ui.unSetup();
}
}
});
dd.setOptions(new Object[] { okButton, DialogDescriptor.CANCEL_OPTION });
// All options close
dd.setClosingOptions(null);
Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
ui.unSetup();
}
});
dialog.setVisible(true);
} else {
executeManipulatorInOtherThread(m);
}
}
});
}
}
use of org.openide.DialogDescriptor in project gephi by gephi.
the class DataLaboratoryHelper method showAttributeRowsMergeStrategyUIDialog.
/**
* This method shows the UI of an AttributeRowsMergeStrategy if it is provided and the AttributeRowsMergeStrategy can be executed.
* These UI only configures (calls unSetup) the AttributeRowsMergeStrategy if the dialog is accepted,
* and it does not execute the AttributeRowsMergeStrategy.
* @param m AttributeRowsMergeStrategy
* @return True if the AttributeRowsMergeStrategy UI is provided
*/
public boolean showAttributeRowsMergeStrategyUIDialog(final AttributeRowsMergeStrategy m) {
final ManipulatorUI ui = m.getUI();
// Show a dialog for the manipulator UI if it provides one. If not, execute the manipulator directly:
if (ui != null && m.canExecute()) {
final JButton okButton = new JButton(NbBundle.getMessage(DataLaboratoryHelper.class, "DataLaboratoryHelper.ui.okButton.text"));
DialogControls dialogControls = new DialogControlsImpl(okButton);
ui.setup(m, dialogControls);
JPanel settingsPanel = ui.getSettingsPanel();
DialogDescriptor dd = new DialogDescriptor(settingsPanel, NbBundle.getMessage(DataLaboratoryHelper.class, "SettingsPanel.title", ui.getDisplayName()), ui.isModal(), new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(okButton)) {
ui.unSetup();
}
}
});
dd.setOptions(new Object[] { okButton, DialogDescriptor.CANCEL_OPTION });
// All options close
dd.setClosingOptions(null);
Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
dialog.setVisible(true);
return true;
}
return false;
}
use of org.openide.DialogDescriptor in project gephi by gephi.
the class DataTableTopComponent method configurationButtonActionPerformed.
// GEN-LAST:event_nodesButtonActionPerformed
private void configurationButtonActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_configurationButtonActionPerformed
DialogDescriptor dd = new DialogDescriptor(new ConfigurationPanel(this, graphModel), NbBundle.getMessage(DataTableTopComponent.class, "ConfigurationPanel.title"));
dd.setOptions(new Object[] { DialogDescriptor.OK_OPTION });
DialogDisplayer.getDefault().notify(dd);
// Save preferences:
NbPreferences.forModule(DataTableTopComponent.class).putBoolean(DATA_LABORATORY_ONLY_VISIBLE, visibleOnly);
NbPreferences.forModule(DataTableTopComponent.class).putBoolean(DATA_LABORATORY_SPARKLINES, useSparklines);
NbPreferences.forModule(DataTableTopComponent.class).putBoolean(DATA_LABORATORY_TIME_INTERVAL_GRAPHICS, timeIntervalGraphics);
NbPreferences.forModule(DataTableTopComponent.class).putBoolean(DATA_LABORATORY_EDGES_NODES_LABELS, showEdgesNodesLabels);
}
use of org.openide.DialogDescriptor in project gephi by gephi.
the class DesktopImportControllerUI method importWizard.
@Override
public void importWizard(final WizardImporter importer) {
try {
if (importer == null) {
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.error_no_matching_db_importer"), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
return;
}
String containerSource = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.wizardSource", "");
ImporterUI ui = controller.getUI(importer);
if (ui != null) {
String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.wizard.ui.dialog.title", ui.getDisplayName());
JPanel panel = ui.getPanel();
ui.setup(new WizardImporter[] { importer });
final DialogDescriptor dd = new DialogDescriptor(panel, title);
if (panel instanceof ValidationPanel) {
ValidationPanel vp = (ValidationPanel) panel;
vp.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
}
});
}
Object result = DialogDisplayer.getDefault().notify(dd);
if (result.equals(NotifyDescriptor.CANCEL_OPTION) || result.equals(NotifyDescriptor.CLOSED_OPTION)) {
ui.unsetup(false);
return;
}
ui.unsetup(true);
containerSource = ui.getDisplayName();
}
ImporterWizardUI wizardUI = controller.getWizardUI(importer);
if (wizardUI != null) {
containerSource = wizardUI.getCategory() + ":" + wizardUI.getDisplayName();
}
LongTask task = null;
if (importer instanceof LongTask) {
task = (LongTask) importer;
}
// Execute task
final String source = containerSource;
String taskName = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.taskName", containerSource);
executor.execute(task, new Runnable() {
@Override
public void run() {
try {
Container container = controller.importWizard(importer);
if (container != null) {
container.setSource(source);
finishImport(container);
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
}, taskName, errorHandler);
} catch (Exception ex) {
Logger.getLogger("").log(Level.WARNING, "", ex);
}
}
use of org.openide.DialogDescriptor in project gephi by gephi.
the class DesktopImportControllerUI method importFiles.
private void importFiles(final Reader[] readers, final FileImporter[] importers, FileObject[] fileObjects) {
try {
File[] files = new File[readers.length];
Map<ImporterUI, List<FileImporter>> importerUIs = new HashMap<>();
for (int i = 0; i < importers.length; i++) {
FileImporter importer = importers[i];
ImporterUI ui = controller.getUI(importer);
if (ui != null) {
List<FileImporter> l = importerUIs.get(ui);
if (l == null) {
l = new ArrayList<>();
importerUIs.put(ui, l);
}
l.add(importer);
}
if (importer instanceof FileImporter.FileAware) {
try (Reader reader = readers[i]) {
File file = null;
if (fileObjects != null) {
file = FileUtil.toFile(fileObjects[i]);
}
if (file == null) {
// There is no source file but the importer needs it, create temporary copy:
String fileName = "tmp_file" + 1;
String charset = "UTF-8";
if (fileObjects != null && fileObjects[i] != null) {
// Netbeans FileUtil.toFile bug returning null?? Try to recover:
fileName = fileObjects[i].getNameExt();
CharsetToolkit charsetToolkit = new CharsetToolkit(fileObjects[i].getInputStream());
charset = charsetToolkit.getCharset().name();
}
file = TempDirUtils.createTempDir().createFile(fileName);
try (FileOutputStream fos = new FileOutputStream(file)) {
FileUtil.copy(new ReaderInputStream(reader, charset), fos);
}
}
files[i] = file;
((FileImporter.FileAware) importer).setFile(file);
}
}
}
for (Map.Entry<ImporterUI, List<FileImporter>> entry : importerUIs.entrySet()) {
ImporterUI ui = entry.getKey();
String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.file.ui.dialog.title", ui.getDisplayName());
JPanel panel = ui.getPanel();
FileImporter[] fi = (FileImporter[]) entry.getValue().toArray((FileImporter[]) Array.newInstance(entry.getValue().get(0).getClass(), 0));
ui.setup(fi);
if (panel != null) {
final DialogDescriptor dd = new DialogDescriptor(panel, title);
if (panel instanceof ValidationPanel) {
ValidationPanel vp = (ValidationPanel) panel;
vp.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
}
});
}
Object result = DialogDisplayer.getDefault().notify(dd);
if (!result.equals(NotifyDescriptor.OK_OPTION)) {
ui.unsetup(false);
return;
}
}
if (ui instanceof ImporterUI.WithWizard) {
boolean finishedOk = showWizard(ui, ((ImporterUI.WithWizard) ui).getWizardDescriptor());
if (!finishedOk) {
ui.unsetup(false);
return;
}
}
ui.unsetup(true);
}
final List<Container> results = new ArrayList<>();
for (int i = 0; i < importers.length; i++) {
doImport(results, readers[i], files[i], importers[i]);
}
executor.execute(null, new Runnable() {
@Override
public void run() {
if (!results.isEmpty()) {
finishImport(results.toArray(new Container[0]));
}
}
});
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
}
Aggregations