use of com.ramussoft.gui.common.BaseDialog in project ramus by Vitaliy-Yakovchuk.
the class SelectableTableView method showRowSelectDialog.
public static List<Row> showRowSelectDialog(Component component, GUIFramework framework, Engine engine, AccessRules rules, Qualifier qualifier, SelectType selectType, boolean readOnly, boolean selectAll) {
final SelectableTableView view = new SelectableTableView(framework, engine, rules, qualifier, readOnly) {
};
JComponent createComponent = view.createComponent();
view.setSelectType(selectType);
Component root = SwingUtilities.getRoot(component);
BaseDialog dialog;
if (root instanceof JFrame)
dialog = new BaseDialog((JFrame) root) {
/**
*/
private static final long serialVersionUID = -900626699911390352L;
@Override
protected void onOk() {
if (view.getSelectedRows().size() == 0) {
JOptionPane.showMessageDialog(this, GlobalResourcesManager.getString("SelectElementDialog.NoSelection"));
} else
super.onOk();
}
};
else if (root instanceof JDialog)
dialog = new BaseDialog((JDialog) root) {
/**
*/
private static final long serialVersionUID = -900626699911390352L;
@Override
protected void onOk() {
if (view.getSelectedRows().size() == 0) {
JOptionPane.showMessageDialog(this, GlobalResourcesManager.getString("SelectElementDialog.NoSelection"));
} else
super.onOk();
}
};
dialog = new BaseDialog(framework.getMainFrame()) {
/**
*/
private static final long serialVersionUID = -900626699911390352L;
@Override
protected void onOk() {
if (view.getSelectedRows().size() == 0) {
JOptionPane.showMessageDialog(this, GlobalResourcesManager.getString("SelectElementDialog.NoSelection"));
} else
super.onOk();
}
};
JPanel panel = new JPanel(new BorderLayout());
if (!readOnly) {
JToolBar bar = view.createToolBar();
bar.setFloatable(false);
panel.add(bar, BorderLayout.NORTH);
}
if (selectAll)
view.getComponent().getModel().checkAll();
panel.add(createComponent, BorderLayout.CENTER);
dialog.setMainPane(panel);
dialog.setLocationRelativeTo(null);
dialog.setTitle(GlobalResourcesManager.getString("SelectElementDialog.Title"));
Options.loadOptions(dialog);
dialog.setVisible(true);
Options.saveOptions(dialog);
if (dialog.isOkPressed()) {
List<Row> res = view.getSelectedRows();
view.close();
return res;
}
view.close();
return null;
}
use of com.ramussoft.gui.common.BaseDialog in project ramus by Vitaliy-Yakovchuk.
the class TableCellEditorFactory method createModelEditor.
private TableCellEditor createModelEditor() {
Qualifier qualifier = getModelTree(engine);
Attribute nameAttribute = StandardAttributesPlugin.getAttributeNameAttribute(engine);
RowSet rowSet = new RowSet(engine, qualifier, new Attribute[] { nameAttribute }, null, true);
OtherElementTableCellEditor editor = new OtherElementTableCellEditor(rowSet, nameAttribute, framework, null) {
/**
*/
private static final long serialVersionUID = -5820017882593141555L;
private OtherElementListModel model;
private void updateValue() {
if (list.getSelectedIndex() == 0)
value = null;
else if (list.getSelectedIndex() == 1)
value = "[ALL MODELS]";
else {
if (model.checked.size() == 0) {
value = model.wrappers[list.getSelectedIndex() - 2].row.getName();
} else {
StringBuffer sb = null;
for (PopupRowWrapper w : model.checked.keySet()) {
if (sb == null)
sb = new StringBuffer(w.row.getName());
else {
sb.append(com.ramussoft.report.editor.xml.Attribute.QUALIFIER_DELIMETER);
sb.append(w.row.getName());
}
}
value = sb.toString();
}
}
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int rowIndex, int columnIndex) {
try {
this.table = table;
if (value instanceof String) {
Row r = rowSet.findRow((String) value);
if (r != null) {
return super.getTableCellEditorComponent(table, value, isSelected, rowIndex, columnIndex);
} else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
codeField.selectAll();
codeField.requestFocus();
}
});
return component;
}
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
codeField.selectAll();
codeField.requestFocus();
}
});
return super.getTableCellEditorComponent(table, value, isSelected, rowIndex, columnIndex);
} finally {
this.value = value;
}
}
protected JPopupMenu getMenu(Attribute attribute) {
if (menu == null) {
menu = new JPopupMenu(attribute.getName());
menu.setMaximumSize(new Dimension(600, 500));
JScrollPane pane = new JScrollPane();
List<Row> allRows = rowSet.getAllRows();
wrappers = new PopupRowWrapper[allRows.size()];
for (int i = 0; i < wrappers.length; i++) {
wrappers[i] = new PopupRowWrapper(allRows.get(i), attribute);
}
model = new OtherElementListModel(wrappers);
list = new JList(model) {
/**
*/
private static final long serialVersionUID = 3924839890645563320L;
CheckCellRenderer cellRenderer;
public ListCellRenderer getCellRenderer() {
if (cellRenderer == null)
cellRenderer = new CheckCellRenderer(model, super.getCellRenderer());
return cellRenderer;
}
};
Dimension size = list.getPreferredSize();
if (size.width > 600)
list.setPreferredSize(new Dimension(600, size.height));
if (value == null)
list.setSelectedIndex(0);
else {
List<String> slist = new ArrayList<String>();
String val = ((String) value);
StringTokenizer st = new StringTokenizer(val, com.ramussoft.report.editor.xml.Attribute.QUALIFIER_DELIMETER);
slist.add(val);
while (st.hasMoreTokens()) slist.add(st.nextToken());
if ("[ALL MODELS]".equals(val))
list.setSelectedIndex(1);
else {
List<Integer> seleted = new ArrayList<Integer>();
for (int i = 0; i < wrappers.length; i++) {
if (slist.contains(wrappers[i].row.getName())) {
model.select(wrappers[i]);
seleted.add(i + 2);
}
}
int[] is = new int[seleted.size()];
for (int i = 0; i < is.length; i++) is[i] = seleted.get(i);
if (is.length > 0)
list.setSelectedIndices(is);
}
}
list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
list.ensureIndexIsVisible(list.getSelectedIndex());
}
});
list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
private boolean rec = false;
@Override
public void valueChanged(ListSelectionEvent e) {
if (rec)
return;
rec = true;
int index = list.getSelectedIndex();
PopupRowWrapper wrapper = null;
if (index < 0)
return;
updateValue();
if (index == 0)
value = null;
else if (index > 1) {
wrapper = wrappers[index - 2];
}
if (updateFields) {
codeField.setBackground(fieldDefaultBackground);
valueField.setBackground(fieldDefaultBackground);
if (wrapper == null) {
codeField.setText("");
valueField.setText("");
} else {
codeField.setText(wrapper.code);
codeField.setCaretPosition(0);
valueField.setText(wrapper.value);
valueField.setCaretPosition(0);
}
}
rec = false;
}
});
list.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getX() <= 20 && e.getClickCount() < 2) {
int index = list.getSelectedIndex();
if (index > 1) {
index -= 2;
model.select(wrappers[index]);
updateValue();
list.repaint();
return;
}
}
updateValue();
stopCellEditing();
}
});
InputMap inputMap = list.getInputMap();
KeyStroke[] allKeys = inputMap.allKeys();
for (Object actionName : actionsToReplace) {
for (KeyStroke stroke : allKeys) {
Object value = inputMap.get(stroke);
if (actionName.equals(value)) {
codeField.getInputMap().put(stroke, actionName);
valueField.getInputMap().put(stroke, actionName);
final Action source = list.getActionMap().get(actionName);
if (source != null) {
Action action = new AbstractAction() {
/**
*/
private static final long serialVersionUID = 4806926801192964440L;
@Override
public void actionPerformed(ActionEvent e) {
if (list != null) {
updateFields = true;
e.setSource(list);
source.actionPerformed(e);
updateFields = false;
}
}
};
valueField.getActionMap().put(actionName, action);
codeField.getActionMap().put(actionName, action);
}
}
}
}
pane.setViewportView(list);
menu.add(pane);
menu.pack();
}
return menu;
}
@Override
protected void edit() {
if (menu != null) {
menu.setVisible(false);
menu = null;
}
final SelectableTableView view = new SelectableTableView(framework, engine, framework.getAccessRules(), rowSet.getQualifier()) {
@Override
public String getPropertiesPrefix() {
return "xml_edit";
}
};
JComponent rc = view.createComponent();
final RowTreeTableComponent component = view.getComponent();
component.getTable().setComponentPopupMenu(null);
component.getTable().setTableHeader(null);
List<String> slist = new ArrayList<String>();
String val = ((String) value);
if (val != null) {
StringTokenizer st = new StringTokenizer(val, com.ramussoft.report.editor.xml.Attribute.QUALIFIER_DELIMETER);
slist.add(val);
while (st.hasMoreTokens()) slist.add(st.nextToken());
for (Row row : component.getRowSet().getAllRows()) if (slist.contains(row.getName()))
component.getModel().setSelectedRow(row, true);
}
view.setSelectType(SelectType.CHECK);
BaseDialog dialog = new BaseDialog(framework.getMainFrame()) {
/**
*/
private static final long serialVersionUID = -4426170644933177805L;
@Override
protected void onOk() {
List<Row> rows = view.getSelectedRows();
if (rows.size() == 0)
value = null;
else {
StringBuffer sb = null;
for (Row w : rows) {
if (sb == null)
sb = new StringBuffer(w.getName());
else {
sb.append(com.ramussoft.report.editor.xml.Attribute.QUALIFIER_DELIMETER);
sb.append(w.getName());
}
}
value = sb.toString();
}
stopCellEditing();
super.onOk();
}
};
dialog.setMainPane(rc);
dialog.setTitle(ReportResourceManager.getString("ReportAttribute.model"));
dialog.setLocationRelativeTo(null);
Options.loadOptions("IDEF0_models", dialog);
dialog.setModal(true);
dialog.setVisible(true);
Options.saveOptions("IDEF0_models", dialog);
try {
view.close();
} catch (Exception e) {
e.printStackTrace();
}
}
};
return editor;
}
use of com.ramussoft.gui.common.BaseDialog in project ramus by Vitaliy-Yakovchuk.
the class Importer method importFromFile.
@SuppressWarnings("unchecked")
public void importFromFile(File file) throws IOException {
FileInputStream fileInputStream = new FileInputStream(file);
final Workbook workbook = new HSSFWorkbook(fileInputStream);
fileInputStream.close();
int sheetCount = workbook.getNumberOfSheets();
if (sheetCount == 0) {
JOptionPane.showMessageDialog(framework.getMainFrame(), plugin.getString("NoSheetsAreFound"));
}
boxes = new ArrayList[sheetCount];
for (int i = 0; i < sheetCount; i++) boxes[i] = new ArrayList<JComboBox>();
final JTabbedPane pane = new JTabbedPane();
for (int i = 0; i < sheetCount; i++) {
sheetNumber = i;
Sheet sheet = workbook.getSheetAt(i);
pane.addTab(workbook.getSheetName(i), createSheetSelect(sheet));
}
BaseDialog dialog = new BaseDialog(framework.getMainFrame(), true) {
/**
*/
private static final long serialVersionUID = -5962006392465638821L;
@Override
protected void onOk() {
rowSet.startUserTransaction();
try {
int index = pane.getSelectedIndex();
ArrayList<JComboBox> boxes = Importer.this.boxes[index];
Sheet sheet = workbook.getSheetAt(index);
ArrayList<ImportRule> rules = new ArrayList<ImportRule>();
int attr = 0;
for (JComboBox box : boxes) {
ImportRule source = importRules.get(attr);
int column = box.getSelectedIndex() - 2;
if (column >= -1) {
ImportRule rule = new ImportRule(source.getAttribute(), source.getTableAttribute(), column);
rules.add(rule);
}
attr++;
}
if (applyToAll.isSelected()) {
for (index = 0; index < workbook.getNumberOfSheets(); index++) {
try {
sheet = workbook.getSheetAt(index);
ComplexImport import1 = new ComplexImport(rowSet, uniqueElement.isSelected());
import1.importDromSheet(sheet, workbook.getSheetName(index), startFrom, rules.toArray(new ImportRule[rules.size()]));
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
ComplexImport import1 = new ComplexImport(rowSet, uniqueElement.isSelected());
import1.importDromSheet(sheet, workbook.getSheetName(index), startFrom, rules.toArray(new ImportRule[rules.size()]));
}
} finally {
rowSet.commitUserTransaction();
}
super.onOk();
}
};
dialog.setTitle(plugin.getString("Action.ImportFromExcel"));
JPanel panel = new JPanel(new BorderLayout());
panel.add(pane, BorderLayout.CENTER);
applyToAll = new JCheckBox(plugin.getString("ApplyToAllSheets"));
uniqueElement = new JCheckBox(plugin.getString("UniqueElements"));
uniqueElement.setSelected(true);
JPanel panel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
panel2.add(applyToAll);
panel2.add(uniqueElement);
panel.add(panel2, BorderLayout.SOUTH);
dialog.setMainPane(panel);
dialog.pack();
dialog.setMaximumSize(dialog.getSize());
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
}
Aggregations