Package net.datacrow.core.objects

Examples of net.datacrow.core.objects.DcField


        if (ae.getActionCommand().equals("addEntry")) {
            addEntry();
        } else if (ae.getActionCommand().equals("moduleSelected")) {
            setFields((DcModule) comboModules.getSelectedItem());
        } else if (ae.getActionCommand().equals("fieldSelected")) {
            DcField field = (DcField) comboFields.getSelectedItem();
            applyField(field);
            setOperators(field);
        } else if (ae.getActionCommand().equals("operatorSelected")) {
            Operator operator = (Operator) comboOperators.getSelectedItem();
            if (c != null && operator != null) {
View Full Code Here


            public void windowOpened(WindowEvent we) {
                try {
                 
                    for (DcFieldDefinition definition : module.getFieldDefinitions().getDefinitions()) {
                        int index = definition.getIndex();
                        DcField field = dco.getField(index);
                        JComponent component = fields.get(field);
                       
                        if (component == null)
                            break;
                       
                        if (    component.isShowing() &&
                            (component instanceof JTextField || component instanceof DcLongTextField) &&
                                field.isEnabled() && component.getParent() != null) {
                            component.requestFocusInWindow();
                            break;
                        }
                    }
                } catch (Exception e) {
View Full Code Here

   
            int[] indices = object.getFieldIndices();
            for (int i = 0; i < indices.length; i++) {
                int index = indices[i];
               
                DcField field = dco.getField(index);
                JComponent component = fields.get(field);
                Object oldValue = ComponentFactory.getValue(component);
                Object newValue = object.getValue(index);
   
                if (newValue instanceof Picture)
View Full Code Here

    @SuppressWarnings("unchecked")
    private boolean isChanged(int fieldIdx) {
        boolean changed = false;
       
        DcField field = dcoOrig.getField(fieldIdx);
        JComponent component = fields.get(field);
        Object o = ComponentFactory.getValue(component);

        if (field.getValueType() == DcRepository.ValueTypes._ICON) {
            byte[] newValue = o == null ? new byte[0] : ((DcImageIcon) o).getBytes();
           
            Object oOld = dcoOrig.getValue(fieldIdx);
            byte[] oldValue;
            if (oOld instanceof String)
                oldValue = Base64.decode(((String) oOld).toCharArray());
            else
                oldValue = (byte[]) oOld;

            oldValue = oldValue == null ? new byte[0] : oldValue;
            if (!Utilities.sameImage(newValue, oldValue)) {
                dcoOrig.setChanged(DcObject._ID, true);
                logger.debug("Field " + field.getLabel() + " is changed. Old: " + oldValue + ". New: " + newValue);
                changed = true;
            }
        } else if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION) {
            List<DcMapping> oldList = dcoOrig.getValue(fieldIdx) instanceof List ? (List<DcMapping>) dcoOrig.getValue(fieldIdx) : null;
            List<DcMapping> newList = (List<DcMapping>) o;
           
            oldList = oldList == null ? new ArrayList<DcMapping>() : oldList;
            newList = newList == null ? new ArrayList<DcMapping>() : newList;
           
            if (oldList.size() == newList.size()) {
                for (DcMapping newMapping : newList) {
                    boolean found = false;
                    for (DcMapping oldMapping : oldList) {
                        if (newMapping.getReferencedID().equals(oldMapping.getReferencedID()))
                            found = true;
                    }
                    changed = !found;
                    if (changed) logger.debug("Field " + field.getLabel() + " is changed. Old: " + oldList + ". New: " + newList);
                }
            } else {
                changed = true;
                logger.debug("Field " + field.getLabel() + " is changed. Old: " + oldList + ". New: " + newList);
            }
        } else if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION ||
                  (!field.isUiOnly() && field.getValueType() != DcRepository.ValueTypes._PICTURE)) {
           
            if (field.getValueType() == DcRepository.ValueTypes._DATE) {
                Date dateOld = (Date) dcoOrig.getValue(fieldIdx);
                Date dateNew = (Date) o;
               
                if (   (dateOld == null && dateNew != null) || (dateNew == null && dateOld != null) ||
                       (dateOld != null && dateNew != null && dateOld.compareTo(dateNew) != 0)) {
                    changed = true;
                    logger.debug("Field " + field.getLabel() + " is changed. Old: " + dateOld + ". New: " + dateNew);
                }

            } else {
                String newValue = Utilities.getComparableString(o);
                String oldValue = Utilities.getComparableString(dcoOrig.getValue(fieldIdx));
                changed = !oldValue.equals(newValue);
                if (changed) logger.debug("Field " + field.getLabel() + " is changed. Old: " + oldValue + ". New: " + newValue);
            }
        } else if (field.getValueType() == DcRepository.ValueTypes._PICTURE) {
            Picture picture = (Picture) dcoOrig.getValue(fieldIdx);
            changed = (picture != null && (picture.isEdited() || picture.isNew() || picture.isDeleted())) ||
                      ((DcPictureField) component).isChanged();
           
            if (changed) logger.debug("Picture " + field.getLabel() + " is changed.");
        }
       
        return changed;
    }
View Full Code Here

    private void initializeComponents() {
        int[] indices = dco.getFieldIndices();
        for (int i = 0; i < indices.length; i ++) {
            int index = indices[i];
            DcField field = dco.getField(index);

            labels.put(field, ComponentFactory.getLabel(dco.getLabel(index)));
            if (index == DcObject._ID) {
                fields.put(field, ComponentFactory.getIdFieldDisabled());
            } else {
                JComponent c = ComponentFactory.getComponent(field.getModule(),
                                                             field.getReferenceIdx(),
                                                             field.getIndex(),
                                                             field.getFieldType(),
                                                             field.getLabel(),
                                                             field.getMaximumLength());
                fields.put(field, c);
            }
        }
    }
View Full Code Here

                positions.put(name, new Integer(0));
           
            int y = positions.get(name).intValue();
           
            int fieldIdx = definition.getIndex();
            DcField field = dco.getField(fieldIdx);
            JLabel label = labels.get(field);
            JComponent component = fields.get(field);
           
          if ((!field.isUiOnly() || field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION) &&
                field.isEnabled() &&
                  field.getValueType() != DcRepository.ValueTypes._PICTURE && // check the field type
                  field.getValueType() != DcRepository.ValueTypes._ICON &&
                 (fieldIdx != dco.getParentReferenceFieldIndex() ||
                  fieldIdx == DcObject._SYS_CONTAINER )) { // not a reference field

                int stretch = GridBagConstraints.HORIZONTAL;
                int factor = 10;

                if (field.getFieldType() == ComponentFactory._LONGTEXTFIELD) {
                    stretch = GridBagConstraints.BOTH;
                    factor = 200;

                    DcLongTextField longText = (DcLongTextField) component;
                    longText.setMargin(new Insets(1, 1, 1, 5));

                    if (field.isReadOnly())
                        ComponentFactory.setUneditable(longText);
                   
                    JScrollPane pane = new JScrollPane(longText);
                   
                    ComponentFactory.setBorder(pane);
                    pane.setPreferredSize(new Dimension(100,100));
                    pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
                    pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
                    component = pane;
                }
               
                if (field.getFieldType() == ComponentFactory._REFERENCESFIELD) {
                    stretch = GridBagConstraints.BOTH;
                    factor = 10;
                }
               
                if (component instanceof DcCheckBox)
                    ((DcCheckBox) component).setText("");

                int space = y == 0 ? 5 : 0;
                panel.add(label,     Layout.getGBC(0, y, 1, 1, 1.0, 1.0
                        ,GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
                         new Insets(space, 2, 2, 5), 0, 0));
                panel.add(component, Layout.getGBC(1, y, 1, 1, factor, factor
                        ,GridBagConstraints.NORTHWEST, stretch,
                         new Insets(space, 2, 2, 2), 0, 0));
               
                positions.put(definition.getTab(moduleIdx), Integer.valueOf(y + 1));
               
                if (field.isReadOnly())
                    ComponentFactory.setUneditable(component);
            }
        }
       
        for (String tab : panels.keySet()) {
View Full Code Here

    protected void addPictureTabs() {
        DcModule module = DcModules.get(moduleIdx);

        for (DcFieldDefinition definition : module.getFieldDefinitions().getDefinitions()) {
            int index = definition.getIndex();
            DcField field = dco.getField(index);
            JComponent component = fields.get(field);

            if (field.isEnabled() &&
               (field.getValueType() == DcRepository.ValueTypes._PICTURE ||
                field.getValueType() == DcRepository.ValueTypes._ICON)) {

                JPanel panel = new JPanel();
                panel.setLayout(Layout.getGBL());

                component.setPreferredSize(component.getMinimumSize());
                panel.add(component, Layout.getGBC(0, 0, 1, 1, 1.0, 1.0
                         ,GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH,
                          new Insets(5, 5, 5, 5), 0, 0));

                if (field.isReadOnly())
                    ComponentFactory.setUneditable(component);
               
                tabbedPane.addTab(field.getLabel(), IconLibrary._icoPicture, panel);
            }
        }
    }
View Full Code Here

        int index = level;
       
        if (fields == null || index >= fields.length) return;
       
        DcDefaultMutableTreeNode child;
        DcField field = dco.getField(fields[index]);
        Object value = dco.getValue(fields[index]);
        index++;
        if (Utilities.isEmpty(value)) {
            child = new DcDefaultMutableTreeNode(new NodeElement(empty, empty, null));
            node.add(child);
            add(dco, index, child);
        } else {
            if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION) {
                @SuppressWarnings("unchecked")
        Collection<DcObject> references = (Collection<DcObject>) dco.getValue(field.getIndex());
                if (references != null && references.size() > 0) {
                    for (DcObject reference : references) {
                        child = new DcDefaultMutableTreeNode(new NodeElement(reference.toString(), reference.toString(), reference.getIcon()));
                        node.insert(child, 0);
                        add(dco, index, child);
                    }
                }
            } else {
                String key = dco.getDisplayString(field.getIndex());
                child = new DcDefaultMutableTreeNode(new NodeElement(key, key, null));
                node.add(child);
                add(dco, index, child);
            }
        }
View Full Code Here

            StringBuffer sql = new StringBuffer("");
           
            List<String> joinOn = new ArrayList<String>();
           
            DcField field;
            DcModule reference;
            DcModule main;
           
            Collection<DcModule> modules = new ArrayList<DcModule>();
           
            if (m.isAbstract()) {
              modules = DcModules.getPersistentModules(m);
            } else {
              modules.add(m);
            }
           
            int moduleCounter = 0;
            int fieldCounter = 0;
           
            StringBuffer columns;
            StringBuffer joins;
           
            for (DcModule module : modules) {
             
              fieldCounter = 0;

              columns = new StringBuffer("select ");
                joins = new StringBuffer("from ");
                joins.append(module.getTableName());
               
              if (moduleCounter > 0)
                sql.append(" UNION ");
             
                columns.append(module.getTableName());
                columns.append(".ID, ");
                columns.append(module.getIndex());
                columns.append(" AS MODULEIDX");     
             
              for (int idx : fields) {
                  field = module.getField(idx);
                  if (field.isUiOnly() &&
                      field.getValueType() != DcRepository.ValueTypes._DCOBJECTCOLLECTION &&
                      field.getValueType() != DcRepository.ValueTypes._DCOBJECTREFERENCE) continue;
                 
                    columns.append(",");
                 
                  joinOn.add(module.getTableName() + fieldCounter + ".ID");
                 
                  if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION ||
                      field.getValueType() == DcRepository.ValueTypes._DCOBJECTREFERENCE) {
 
                      reference = DcModules.get(field.getReferenceIdx());
                      main = field.getValueType() == DcRepository.ValueTypes._DCOBJECTREFERENCE ? module :
                             DcModules.get(DcModules.getMappingModIdx(module.getIndex(), reference.getIndex(), field.getIndex()));
 
                      if (    field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION ||
                              field.getFieldType() == ComponentFactory._REFERENCEFIELD) {
                         
                          columns.append("subselect");
                          columns.append(fieldCounter);
                          columns.append(".ID AS ");
                          columns.append("ID");
                          columns.append(fieldCounter);
                          columns.append(", ");
                         
                          columns.append("subselect");
                          columns.append(fieldCounter);
                          columns.append(".name AS ");
                          columns.append("NAME");
                          columns.append(fieldCounter);
                          columns.append(", ");
                         
                          columns.append("subselect");
                          columns.append(fieldCounter);                           
                          columns.append(".icon AS ");
                          columns.append("ICON");
                          columns.append(fieldCounter);
                             
                          if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION) {
                              joins.append(" left outer join ");
                              joins.append("(select ");
                              joins.append(reference.getTableName());
                              joins.append(".ID as ID,");
                              joins.append(main.getTableName());
                              joins.append(".");
                              joins.append(main.getField(DcMapping._A_PARENT_ID).getDatabaseFieldName());
                              joins.append(" as parentID, ");
                              joins.append(reference.getTableName());
                              joins.append(".");
                              joins.append(reference.getField(reference.getSystemDisplayFieldIdx()).getDatabaseFieldName());
                              joins.append(" as name,");
                             
                              if (reference.getType() == DcModule._TYPE_PROPERTY_MODULE) {
                                  joins.append(reference.getTableName());
                                  joins.append(".");
                                  joins.append(reference.getField(DcProperty._B_ICON).getDatabaseFieldName());
                              } else {
                                  joins.append("NULL");
                              }
                             
                              joins.append(" as icon");
                              joins.append(" from ");
                              joins.append(reference.getTableName());
                              joins.append(" inner join ");
                              joins.append(main.getTableName());
                              joins.append(" on ");
                              joins.append(reference.getTableName());
                              joins.append(".ID = ");
                              joins.append(main.getTableName());
                              joins.append(".");
                              joins.append(main.getField(DcMapping._B_REFERENCED_ID).getDatabaseFieldName());
                              joins.append(") subselect");
                              joins.append(fieldCounter);
                              joins.append(" on ");
                              joins.append(" subselect");
                              joins.append(fieldCounter);
                              joins.append(".parentID = ");
                              joins.append(module.getTableName());
                              joins.append(".ID ");
 
                          } else {
                              joins.append(" left outer join ");
                              joins.append(reference.getTableName());
                              joins.append(" ");
                              joins.append(" subselect");
                              joins.append(fieldCounter);
                              joins.append(" on ");
                              joins.append(module.getTableName());
                              joins.append(".");
                              joins.append(field.getDatabaseFieldName());
                              joins.append("=");
                              joins.append(" subselect");
                              joins.append(fieldCounter);
                              joins.append(".ID");
                          }
                      }
                  } else {
                      columns.append(module.getTableName());
                      columns.append(".");
                      columns.append(field.getDatabaseFieldName());
                      columns.append(",");
                      columns.append(module.getTableName());
                      columns.append(".");
                      columns.append(field.getDatabaseFieldName() + " as df");
                      columns.append(fieldCounter);
                      columns.append(",NULL");
                     
                      joinOn.add(module.getTableName() + ".ID");
                  }
                  fieldCounter++;
              }
             
              sql.append(columns.toString() + " " + joins.toString());
              sql.append(" ");
              moduleCounter++;
            }

            if (m.isAbstract()) {
              sql.insert(0, "select * from (");
              sql.append(") ");
          }

            // index based order by
            int level = 0;
            boolean ordered = false;
            for (int idx : fields) {
              field = DcModules.get(getModule()).getField(idx);
                if (field.isUiOnly() &&
                    field.getIndex() != DcObject._SYS_MODULE &&
                    field.getValueType() != DcRepository.ValueTypes._DCOBJECTCOLLECTION &&
                    field.getValueType() != DcRepository.ValueTypes._DCOBJECTREFERENCE) continue;

                if (!ordered) {
                   sql.append(" order by ");
                   ordered = true;
                } else {
                sql.append(",");
                }
               
              if (field.getIndex() == DcObject._SYS_MODULE) {
                  sql.append("2");
              } else {
                  sql.append(String.valueOf((level * 3) + 4));
                  level++;
              }
View Full Code Here

                String id = null;
                String value = null;
                Object key = null;
                DcImageIcon icon = null;
                String iconBase64 = null;
                DcField field = null;
                int module;

                DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
               
                DefaultMutableTreeNode current;
                DefaultMutableTreeNode parent;
                DefaultMutableTreeNode previous;
                boolean exists = false;
               
                Map<String, Integer> items = DataManager.getKeys(DataFilters.getCurrent(getModule()));
               
                Collection<String> keys = null;
                if (DataFilters.isFilterActive(getModule())) {
                    keys = new ArrayList<String>(items.keySet());
                }
               
                while (rs.next() && !stop) {
                    int level = 0;
                    parent = top;
                   
                    for (int idx = 0; idx < fields.length; idx++) {
                     
                      field = DcModules.get(getModule()).getField(fields[idx]);
                      if (field.isUiOnly() &&
                          field.getIndex() != DcObject._SYS_MODULE &&
                          field.getValueType() != DcRepository.ValueTypes._DCOBJECTCOLLECTION &&
                          field.getFieldType() != ComponentFactory._REFERENCEFIELD)
                        continue;
                     
                       
                        if (stop) break;
                       
                        // for each level the field index is shifted to the end.
                        id = rs.getString(1);
                        module = rs.getInt(2);
                        key = field.getIndex() == DcObject._SYS_MODULE ? DcModules.get(module).getLabel() : rs.getObject((level * 3) + 3);
                        value =  field.getIndex() == DcObject._SYS_MODULE ? DcModules.get(module).getLabel() : rs.getString((level * 3) + 4);
                        iconBase64 = field.getIndex() != DcObject._SYS_MODULE ? rs.getString((level * 3) + 5) : null;
                       
                        icon = field.getIndex() == DcObject._SYS_MODULE ?
                                new DcImageIcon(DcModules.get(module).getIcon16().getImage()) :
                                iconBase64 != null ? DataManager.addIcon(String.valueOf(key), iconBase64) : null;
                       
                        if (keys != null && !keys.contains(id)) continue;
                       
                        previous = parent.getChildCount() == 0 ? null : ((DefaultMutableTreeNode) parent.getChildAt(parent.getChildCount() - 1));
                        exists = previous == null || (((NodeElementprevious.getUserObject()).getKey() == null && key != null) ? false :
                                ((NodeElementprevious.getUserObject()).getKey() == key || // empty key
                                ((NodeElementprevious.getUserObject()).getKey().equals(key);
                       
                        if (!exists) {
                            if (key == null) {
                                ne = new NodeElement(null, empty, null);
                            } else {
                                ne = new NodeElement(key, value, icon);
                            }
                           
                            ne.addItem(id, module);
                            current = new DcDefaultMutableTreeNode(ne);
                            parent.add(current);
                            parent = current;
                          
                        } else { // exists
                            existingNe =(NodeElement) previous.getUserObject();
                            existingNe.addItem(id, module);
                            model.nodeChanged(previous);
                            parent = previous;   
                        }
                       
                        if (field.getIndex() != DcObject._SYS_MODULE)
                            level++;
                    }
                }
               
                rs.close();
View Full Code Here

TOP

Related Classes of net.datacrow.core.objects.DcField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.