use of com.ramussoft.gui.qualifier.table.SelectableTableView in project ramus by Vitaliy-Yakovchuk.
the class QueryView method setQueryForReport.
public void setQueryForReport(Element element) {
Qualifier qualifier = reportQuery.getHTMLReportQuery(element);
if (qualifier == null) {
this.removeAll();
if (selectableTableView != null) {
selectableTableView.close();
selectableTableView = null;
}
this.add(new JLabel(ReportResourceManager.getString("QueryView.emptyQueryText")), BorderLayout.CENTER);
} else {
if ((selectableTableView == null) || (!selectableTableView.getQualifier().equals(qualifier))) {
this.removeAll();
if (selectableTableView != null)
selectableTableView.close();
selectableTableView = new SelectableTableView(framework, qualifier);
JComponent createComponent = selectableTableView.createComponent();
selectableTableView.getComponent().getModel().checkAll();
this.add(createComponent, BorderLayout.CENTER);
selectableTableView.setSelectType(SelectType.CHECK);
}
}
}
use of com.ramussoft.gui.qualifier.table.SelectableTableView in project ramus by Vitaliy-Yakovchuk.
the class ChartAttributeEditor method getComponent.
@Override
public JComponent getComponent() {
view = new SelectableTableView(framework, ChartPlugin.getCharts(framework.getEngine())) {
@Override
protected Attribute[] getAttributes() {
return new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine) };
}
};
JComponent component = view.createComponent();
view.setSelectType(SelectType.RADIO);
if (link != null) {
List<Long> rows = new ArrayList<Long>(1);
rows.add(link);
view.selectRows(rows);
}
return component;
}
use of com.ramussoft.gui.qualifier.table.SelectableTableView in project ramus by Vitaliy-Yakovchuk.
the class QualifierPlugin method getProjectPreferences.
@Override
public Preferences[] getProjectPreferences() {
return new Preferences[] { new AbstractPreferences() {
class Button extends JRadioButton {
/**
*/
private static final long serialVersionUID = 1L;
private Language language;
public Button(Language language) {
this.language = language;
}
public Language getLanguage() {
return language;
}
}
private JPanel component;
private Button[] buttons;
private JCheckBox box;
{
Properties ps = engine.getProperties(TextAttributePlugin.USER_GUI_SPELL_PROPERTIES);
Language language = getCurrentLanguage(ps);
Language[] languages = SpellFactory.getLanguages();
box = new JCheckBox(GlobalResourcesManager.getString("Editor.SpellCheck"));
box.setSelected(Options.getBoolean(TextAttributePlugin.SPELL_CHECK, true, ps));
JPanel languagesPanel = new JPanel();
languagesPanel.setLayout(new BoxLayout(languagesPanel, BoxLayout.Y_AXIS));
buttons = new Button[languages.length];
ButtonGroup group = new ButtonGroup();
for (int i = 0; i < languages.length; i++) {
Button button = new Button(languages[i]);
button.setText(languages[i].getLocalizedName());
languagesPanel.add(button);
buttons[i] = button;
if (languages[i].equals(language))
button.setSelected(true);
group.add(button);
}
JScrollPane pane = new JScrollPane();
pane.setViewportView(languagesPanel);
component = new JPanel(new BorderLayout());
component.add(pane, BorderLayout.CENTER);
component.add(box, BorderLayout.NORTH);
}
@Override
public JComponent createComponent() {
return component;
}
@Override
public String getTitle() {
return GlobalResourcesManager.getString("Preferences.SpellChecking");
}
@Override
public boolean save(JDialog dialog) {
Properties ps = engine.getProperties(TextAttributePlugin.USER_GUI_SPELL_PROPERTIES);
Options.setBoolean(TextAttributePlugin.SPELL_CHECK, box.isSelected(), ps);
String l = "";
for (Button button : buttons) if (button.isSelected()) {
l = button.getLanguage().getName();
break;
}
Options.setString(TextAttributePlugin.LANGUAGE, l, ps);
engine.setProperties(TextAttributePlugin.USER_GUI_SPELL_PROPERTIES, ps);
return true;
}
private Language getCurrentLanguage(Properties ps) {
String langName = Options.getString(TextAttributePlugin.LANGUAGE, "", ps);
Language language;
if ((langName == null) || (langName.equals("")))
language = SpellFactory.getDefaultLanguage();
else
language = SpellFactory.findLanguage(langName);
return language;
}
}, new AbstractPreferences() {
SelectableTableView tableView;
JComboBox attributeForName = new JComboBox();
private JPanel panel;
{
tableView = new SelectableTableView(framework, engine, accessor, StandardAttributesPlugin.getAttributesQualifier(engine)) {
@Override
protected Attribute[] getAttributes() {
return new Attribute[] { StandardAttributesPlugin.getAttributeNameAttribute(engine), StandardAttributesPlugin.getAttributeTypeNameAttribute(engine) };
}
};
double[][] size = { { 5, TableLayout.MINIMUM, 5, TableLayout.FILL, 5 }, { 5, TableLayout.MINIMUM, 5 } };
JPanel attrForName = new JPanel(new TableLayout(size));
attrForName.add(new JLabel(GlobalResourcesManager.getString("Qualifier.AttributeForName")), "1, 1");
attrForName.add(attributeForName, "3, 1");
panel = new JPanel(new BorderLayout());
panel.add(tableView.createComponent(), BorderLayout.CENTER);
panel.add(attrForName, BorderLayout.SOUTH);
Properties ps = engine.getProperties(AutochangePlugin.AUTO_ADD_ATTRIBUTES);
String ids = ps.getProperty(AutochangePlugin.AUTO_ADD_ATTRIBUTE_IDS);
if (ids == null)
ids = "";
String aForName = ps.getProperty(AutochangePlugin.ATTRIBUTE_FOR_NAME);
StringTokenizer st = new StringTokenizer(ids, " ,");
List<Row> rows = tableView.getComponent().getRowSet().getAllRows();
attributeForName.addItem(null);
while (st.hasMoreElements()) {
String s = st.nextToken();
Long long1 = new Long(s);
Row row = findRow(long1, rows);
if (row != null) {
tableView.setSelectedRow(row, true);
attributeForName.addItem(row);
if (s.equals(aForName))
attributeForName.setSelectedItem(row);
}
}
attributeForName.addPopupMenuListener(new PopupMenuListener() {
@Override
public void popupMenuCanceled(PopupMenuEvent e) {
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
}
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
attributeForName.removeAllItems();
List<Row> list = tableView.getSelectedRows();
for (Row p : list) {
Attribute a = StandardAttributesPlugin.getAttribute(engine, p.getElement());
if (StandardAttributesPlugin.isNameType(a.getAttributeType()))
attributeForName.addItem(p);
}
JComboBox box = (JComboBox) e.getSource();
Object comp = box.getUI().getAccessibleChild(box, 0);
if (!(comp instanceof JPopupMenu))
return;
JComponent scrollPane = (JComponent) ((JPopupMenu) comp).getComponent(0);
Dimension size = new Dimension();
size.width = box.getPreferredSize().width;
size.height = scrollPane.getPreferredSize().height;
scrollPane.setPreferredSize(size);
}
});
}
@Override
public JComponent createComponent() {
return panel;
}
private Row findRow(Long long1, List<Row> rows) {
Attribute attr = engine.getAttribute(long1.longValue());
if (attr != null) {
for (Row row : rows) {
Long long2 = StandardAttributesPlugin.getAttributeId(engine, row.getElement());
if (long2 != null) {
if (attr.getId() == long2.longValue())
return row;
}
}
}
return null;
}
@Override
public String getTitle() {
return GlobalResourcesManager.getString("Preferences.AutoaddAttributes");
}
@Override
public boolean save(JDialog dialog) {
List<Row> list = tableView.getSelectedRows();
StringBuffer sb = new StringBuffer();
for (Row row : list) {
Long id = StandardAttributesPlugin.getAttributeId(engine, row.getElement());
if (id != null)
sb.append(id + " ");
}
Properties properties = engine.getProperties(AutochangePlugin.AUTO_ADD_ATTRIBUTES);
properties.setProperty(AutochangePlugin.AUTO_ADD_ATTRIBUTE_IDS, sb.toString());
Row row = (Row) attributeForName.getSelectedItem();
if (row != null)
properties.setProperty(AutochangePlugin.ATTRIBUTE_FOR_NAME, Long.toString(StandardAttributesPlugin.getAttributeId(engine, row.getElement())));
engine.setProperties(AutochangePlugin.AUTO_ADD_ATTRIBUTES, properties);
return true;
}
@Override
public void close() {
tableView.close();
}
} };
}
use of com.ramussoft.gui.qualifier.table.SelectableTableView 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;
}
Aggregations