use of java.awt.event.ComponentEvent in project cayenne by apache.
the class MainDataNodeEditor method initController.
protected void initController() {
view.getDataSourceDetail().add(defaultSubeditor.getView(), "default");
view.getFactories().setEditable(true);
// init combo box choices
view.getFactories().setModel(new DefaultComboBoxModel<>(STANDARD_DATA_SOURCE_FACTORIES));
view.getSchemaUpdateStrategy().setEditable(true);
view.getSchemaUpdateStrategy().setModel(new DefaultComboBoxModel<>(STANDARD_SCHEMA_UPDATE_STRATEGY));
// init listeners
((ProjectController) getParent()).addDataNodeDisplayListener(e -> refreshView(e.getDataNode()));
getView().addComponentListener(new ComponentAdapter() {
public void componentShown(ComponentEvent e) {
refreshView(node != null ? node : ((ProjectController) getParent()).getCurrentDataNode());
}
});
BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), this);
localDataSourceBinding = builder.bindToComboSelection(view.getLocalDataSources(), "parent.dataNodePreferences.localDataSource", NO_LOCAL_DATA_SOURCE);
// use delegate for the rest of them
builder.setDelegate(nodeChangeProcessor);
bindings = new ObjectBinding[3];
bindings[0] = builder.bindToTextField(view.getDataNodeName(), "nodeName");
bindings[1] = builder.bindToComboSelection(view.getFactories(), "factoryName");
bindings[2] = builder.bindToComboSelection(view.getSchemaUpdateStrategy(), "schemaUpdateStrategy");
// one way bindings
builder.bindToAction(view.getConfigLocalDataSources(), "dataSourceConfigAction()");
}
use of java.awt.event.ComponentEvent in project cayenne by apache.
the class PasswordEncoderEditor method initController.
protected void initController() {
BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), this);
builder.setDelegate(nodeChangeProcessor);
bindings = new ObjectBinding[4];
bindings[0] = builder.bindToComboSelection(view.getPasswordEncoder(), "node.dataSourceDescriptor.passwordEncoderClass");
bindings[1] = builder.bindToTextField(view.getPasswordKey(), "node.dataSourceDescriptor.passwordEncoderKey");
bindings[2] = builder.bindToComboSelection(view.getPasswordLocation(), "node.dataSourceDescriptor.passwordLocation");
bindings[3] = builder.bindToTextField(view.getPasswordSource(), "node.dataSourceDescriptor.passwordSource");
((ProjectController) getParent()).addDataNodeDisplayListener(new DataNodeDisplayListener() {
public void currentDataNodeChanged(DataNodeDisplayEvent e) {
refreshView(e.getDataNode());
}
});
getView().addComponentListener(new ComponentAdapter() {
public void componentShown(ComponentEvent e) {
refreshView(node != null ? node : ((ProjectController) getParent()).getCurrentDataNode());
}
});
builder.bindToAction(view.getPasswordEncoder(), "validatePasswordEncoderAction()");
builder.bindToAction(view.getPasswordLocation(), "passwordLocationChangedAction()");
}
use of java.awt.event.ComponentEvent in project knime-core by knime.
the class AbstractJFileChooserBrowser method openDialogAndGetSelectedFileName.
/**
* {@inheritDoc}
*/
@Override
public String openDialogAndGetSelectedFileName(final FileSelectionMode fileSelectionMode, final DialogType dialogType, final Component parent, final String forcedFileExtensionOnSave, final String selectedFile, final String[] suffixes) {
final JFileChooser fileChooser = new JFileChooser(getFileSystemView());
setFileView(fileChooser);
fileChooser.setAcceptAllFileFilterUsed(true);
List<SimpleFileFilter> filters = createFiltersFromSuffixes(suffixes);
for (SimpleFileFilter filter : filters) {
fileChooser.addChoosableFileFilter(filter);
}
if (filters.size() > 0) {
fileChooser.setFileFilter(filters.get(0));
}
fileChooser.setFileSelectionMode(fileSelectionMode.getJFileChooserCode());
fileChooser.setDialogType(dialogType.getJFileChooserCode());
// AP-2562
// It seems only resized event is happening when showing the dialog
// Grabbing the focus then makes two clicks to single click selection.
fileChooser.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(final ComponentEvent e) {
fileChooser.grabFocus();
}
});
final File selected = createFileFromPath(selectedFile);
if (selected == null) {
fileChooser.setSelectedFile(null);
} else {
if (selected.isDirectory()) {
fileChooser.setSelectedFile(null);
fileChooser.setCurrentDirectory(selected.getAbsoluteFile());
} else {
fileChooser.setSelectedFile(selected.getAbsoluteFile());
}
}
/* This if construct is result of a fix for bug 5841.
* showDialog does not resolve localized folder names correctly under Mac OS,
* so we use the methods showSaveDialog and showOpenDialog if possible.
*/
int r;
if (dialogType == DialogType.SAVE_DIALOG) {
r = fileChooser.showSaveDialog(parent);
} else if (dialogType == DialogType.OPEN_DIALOG) {
r = fileChooser.showOpenDialog(parent);
} else {
r = fileChooser.showDialog(parent, "OK");
}
if (r == JFileChooser.APPROVE_OPTION) {
File file = fileChooser.getSelectedFile();
if (dialogType == DialogType.SAVE_DIALOG) {
String forceFileExtension = StringUtils.defaultString(forcedFileExtensionOnSave);
final String fileName = file.getName();
if (!(StringUtils.endsWithAny(fileName, suffixes) || StringUtils.endsWithIgnoreCase(fileName, forcedFileExtensionOnSave))) {
file = addFileExtension(file, forceFileExtension);
}
}
if (file.exists() && (fileSelectionMode == FileSelectionMode.FILES_ONLY) && file.isDirectory()) {
JOptionPane.showMessageDialog(parent, "Error: Please select a file, not a directory.");
return null;
}
return postprocessSelectedFilePath(file.getAbsolutePath());
}
return null;
}
use of java.awt.event.ComponentEvent in project vcell by virtualcell.
the class DialogUtils method showComponentOptionsTableList.
public static TableListResult showComponentOptionsTableList(final Component requester, final String title, final String[] columnNames, final Object[][] rowDataOrig, final Integer listSelectionModel_SelectMode, final ListSelectionListener listSelectionListener, final String[] options, final String initOption, final Comparator<Object> rowSortComparator, final boolean bModal) throws UserCancelException {
// //Create hidden column with original row index so original row index can
// //be returned for user selections even if rows are sorted
// final int hiddenColumnIndex = rowDataOrig[0].length;
// final Object[][] rowDataHiddenIndex = new Object[rowDataOrig.length][hiddenColumnIndex+1];
// for (int i = 0; i < rowDataHiddenIndex.length; i++) {
// for (int j = 0; j < rowDataOrig[i].length; j++) {
// rowDataHiddenIndex[i][j] = rowDataOrig[i][j];
// }
// rowDataHiddenIndex[i][hiddenColumnIndex] = i;
// }
Producer<TableListResult> prod = () -> {
// Create hidden column with original row index so original row index can
// be returned for user selections even if rows are sorted
int hiddenColumnIndex = rowDataOrig[0].length;
Object[][] rowDataHiddenIndex = rowDataOrig;
if (rowSortComparator != null) {
rowDataHiddenIndex = new Object[rowDataOrig.length][hiddenColumnIndex + 1];
for (int i = 0; i < rowDataHiddenIndex.length; i++) {
for (int j = 0; j < rowDataOrig[i].length; j++) {
rowDataHiddenIndex[i][j] = rowDataOrig[i][j];
}
rowDataHiddenIndex[i][hiddenColumnIndex] = i;
}
}
@SuppressWarnings("serial") VCellSortTableModel<Object[]> tableModel = new VCellSortTableModel<Object[]>(columnNames, rowDataOrig.length) {
@Override
public boolean isSortable(int col) {
if (rowSortComparator != null) {
return true;
}
return false;
}
public Object getValueAt(int row, int column) {
return getValueAt(row)[column];
}
@Override
public Comparator<Object[]> getComparator(final int col, final boolean ascending) {
return new Comparator<Object[]>() {
public int compare(Object[] o1, Object[] o2) {
if (ascending) {
return rowSortComparator.compare(o1[col], o2[col]);
}
return rowSortComparator.compare(o2[col], o1[col]);
}
};
}
};
final JSortTable table = new JSortTable();
// table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
table.setModel(tableModel);
tableModel.setData(Arrays.asList(rowDataHiddenIndex));
if (listSelectionModel_SelectMode != null) {
table.setSelectionMode(listSelectionModel_SelectMode);
} else {
table.setRowSelectionAllowed(false);
table.setColumnSelectionAllowed(false);
}
table.setPreferredScrollableViewportSize(new Dimension(500, 250));
table.disableUneditableForeground();
OKEnabler tableListOKEnabler = null;
if (listSelectionModel_SelectMode != null) {
tableListOKEnabler = new OKEnabler() {
private JOptionPane jop;
public void setJOptionPane(JOptionPane joptionPane) {
jop = joptionPane;
setInternalNotCancelEnabled(joptionPane, false, false);
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
if (table.getSelectedRowCount() != 0) {
setInternalNotCancelEnabled(jop, true, false);
} else {
setInternalNotCancelEnabled(jop, false, false);
}
}
}
});
}
};
}
if (listSelectionListener != null) {
table.getSelectionModel().addListSelectionListener(listSelectionListener);
}
TableListResult tableListResult = new TableListResult();
// HACK to fix horizontal scrollbar not showing for large horizontal tables
// workaround code from: http://bugs.sun.com/view_bug.do?bug_id=4127936
final JScrollPane[] jScrollPaneArr = new JScrollPane[1];
Component[] components = table.getEnclosingScrollPane().getComponents();
for (int i = 0; i < components.length; i++) {
if (components[i] instanceof JScrollPane) {
jScrollPaneArr[0] = (JScrollPane) components[i];
break;
}
}
if (jScrollPaneArr[0] != null) {
jScrollPaneArr[0].addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
if (table.getPreferredSize().width <= jScrollPaneArr[0].getViewport().getExtentSize().width) {
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
} else {
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
}
});
}
if (options == null) {
if (bModal) {
if (showComponentOKCancelDialog(requester, table.getEnclosingScrollPane(), title, tableListOKEnabler) != JOptionPane.OK_OPTION) {
throw UserCancelException.CANCEL_GENERIC;
}
} else {
// display non-modal
JOptionPane jOptionPane = new JOptionPane(table.getEnclosingScrollPane(), JOptionPane.INFORMATION_MESSAGE);
JDialog jDialog = jOptionPane.createDialog(requester, title);
jDialog.setResizable(true);
jDialog.setModal(false);
jDialog.pack();
jDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
jDialog.setVisible(true);
}
tableListResult.selectedTableRows = table.getSelectedRows();
} else {
tableListResult.selectedOption = showOptionsDialog(requester, table.getEnclosingScrollPane(), JOptionPane.QUESTION_MESSAGE, options, initOption, tableListOKEnabler, title);
tableListResult.selectedTableRows = table.getSelectedRows();
}
if (rowSortComparator != null) {
// return the index of the original unsorted object array that corresponds to the user row selections
for (int i = 0; i < tableListResult.selectedTableRows.length; i++) {
tableListResult.selectedTableRows[i] = (Integer) (tableModel.getValueAt(tableListResult.selectedTableRows[i])[hiddenColumnIndex]);
}
}
return tableListResult;
};
return VCSwingFunction.executeAsRuntimeException(prod);
}
use of java.awt.event.ComponentEvent in project vcell by virtualcell.
the class BasicGraphEditor method insertPalette.
/**
*/
public EditorPalette insertPalette(String title) {
final EditorPalette palette = new EditorPalette();
final JScrollPane scrollPane = new JScrollPane(palette);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
libraryPane.add(title, scrollPane);
// Updates the widths of the palettes if the container size changes
libraryPane.addComponentListener(new ComponentAdapter() {
/**
*/
public void componentResized(ComponentEvent e) {
int w = scrollPane.getWidth() - scrollPane.getVerticalScrollBar().getWidth();
palette.setPreferredWidth(w);
}
});
return palette;
}
Aggregations