use of com.ramussoft.database.common.Row in project ramus by Vitaliy-Yakovchuk.
the class OtherElementEditor method setValue.
@Override
public Object setValue(Object value) {
component.getModel().clearSelection();
if (value != null) {
long elementId = (Long) value;
if (elementId > -1l) {
RowSet rowSet = component.getRowSet();
Row row = rowSet.findRow(elementId);
if (row != null) {
component.getModel().setSelectedRow(row, true);
int indexOfRow = component.getTable().indexOfRow(row);
if (indexOfRow >= 0)
component.getTable().scrollRowToVisible(indexOfRow);
} else
return null;
} else
return null;
}
return value;
}
use of com.ramussoft.database.common.Row 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.database.common.Row in project ramus by Vitaliy-Yakovchuk.
the class QualifierPreferencesPanel method setupAttribute.
public void setupAttribute() {
Row row = attributeEditor.getSelectedRow();
if (row == null)
return;
AttributePreferenciesDialog d;
if (dialog == null)
d = new AttributePreferenciesDialog(framework);
else
d = new AttributePreferenciesDialog(framework, dialog);
Attribute attribute = engine.getAttribute((Long) row.getAttribute(attributeId));
d.setAttribute(attribute);
d.getOKButton().setEnabled(rules.canUpdateAttribute(attribute.getId()));
d.setVisible(true);
}
use of com.ramussoft.database.common.Row in project ramus by Vitaliy-Yakovchuk.
the class QualifierView method refreshActions.
@Override
protected void refreshActions() {
super.refreshActions();
TreePath selectionPath = table.getTreeSelectionModel().getSelectionPath();
boolean anySelected = selectionPath != null;
qualifierPreferenciesAction.setEnabled(anySelected);
Row sRow = null;
if (selectionPath != null)
sRow = ((TreeTableNode) selectionPath.getLastPathComponent()).getRow();
if (sRow == null)
convertQualifierToElementsAction.setEnabled(false);
else {
if ((sRow.getChildCount() == 0) || (table.getTreeSelectionModel().getSelectionPaths().length > 1))
convertQualifierToElementsAction.setEnabled(false);
else
convertQualifierToElementsAction.setEnabled(canDeleteLastLeveleOfQualifiers(sRow, qAttribute));
}
openQualifier.setEnabled(anySelected && sRow != null && sRow.getChildCount() == 0);
if (deleteElementAction.isEnabled()) {
TreePath[] paths = table.getTreeSelectionModel().getSelectionPaths();
boolean e = true;
for (TreePath path : paths) {
Row row = ((TreeTableNode) path.getLastPathComponent()).getRow();
if (engine.getElement(row.getElementId()) == null)
row = null;
if (row == null) {
e = false;
break;
}
if (row.getChildCount() > 0) {
e = false;
break;
}
Long attribute = (Long) row.getAttribute(qAttribute);
if ((attribute != null) && (!accessRules.canDeleteQualifier(attribute))) {
e = false;
break;
}
}
deleteElementAction.setEnabled(e);
}
}
use of com.ramussoft.database.common.Row in project ramus by Vitaliy-Yakovchuk.
the class RowTreeTable method getBodyText.
public String getBodyText(String tableName) {
StringBuffer sb = new StringBuffer();
sb.append("<h1>" + tableName + "</h1>\n<hr>\n");
sb.append("<table>\n");
RowTreeTableModel model = (RowTreeTableModel) getTreeTableModel();
sb.append("<tr>");
sb.append("<td><b><i>");
sb.append(GlobalResourcesManager.getString("Code"));
sb.append("</i></b></td>\n");
for (int j = 0; j < getColumnCount(); j++) {
int column = convertColumnIndexToModel(j);
sb.append("<td><b>");
String name = getModel().getColumnName(column);
if (name != null) {
if (name.startsWith("<html><body><center>"))
name = name.substring("<html><body><center>".length(), name.length() - "</center></body></html>".length());
sb.append(name);
}
sb.append("</b></td>\n");
}
sb.append("</tr>\n");
for (int i = 0; i < getRowCount(); i++) {
int row = convertRowIndexToModel(i);
sb.append("<tr>");
sb.append("<td>");
TreeTableNode node = (TreeTableNode) getPathForRow(row).getLastPathComponent();
Row row2 = node.getRow();
if (row2 != null)
sb.append("<i>" + row2.getCode() + "</i>");
sb.append("</td>");
for (int j = 0; j < getColumnCount(); j++) {
boolean rightAlign = false;
int column = convertColumnIndexToModel(j);
TableCellRenderer renderer = getCellRenderer(row, column);
String value;
if (renderer instanceof JLabel) {
if (((JLabel) renderer).getHorizontalAlignment() == SwingConstants.RIGHT)
rightAlign = true;
}
Object object = model.getValueAt(node, column);
if (object == null)
value = null;
else
value = object.toString();
if (rightAlign)
sb.append("<td align=\"right\">");
else
sb.append("<td>");
if (value != null)
sb.append(value);
sb.append("</td>\n");
}
sb.append("</tr>\n");
}
sb.append("</table>\n");
return sb.toString();
}
Aggregations