Пример #1
0
void c4_HandlerSeq::DetachFromStorage(bool full_)
{
    if (_persist != 0) {
        int limit = full_ ? 0 : NumFields();

        // get rid of all handlers which might do I/O
        for (int c = NumHandlers(); --c >= 0;) {
            c4_Handler &h = NthHandler(c);

            // all nested fields are detached recursively
            if (IsNested(c))
                for (int r = 0; r < NumRows(); ++r)
                    if (h.HasSubview(r)) {
                        SubEntry(c, r).DetachFromStorage(full_);
                    }

            if (c >= limit) {
                if (h.IsPersistent()) {
                    delete  &h;
                    _handlers.RemoveAt(c);
                    ClearCache();
                }
            }
        }

        if (full_) {
            //UnmappedAll();
            _persist = 0;
        }
    }
}
Пример #2
0
void c4_HandlerSeq::Prepare(const t4_byte **ptr_, bool selfDesc_)
{
    if (ptr_ != 0) {
        d4_dbgdef(t4_i32 sias =)c4_Column::PullValue(*ptr_);
        d4_assert(sias == 0); // not yet

        if (selfDesc_) {
            t4_i32 n = c4_Column::PullValue(*ptr_);
            if (n > 0) {
                c4_String s = "[" + c4_String((const char *) * ptr_, n) + "]";
                const char *desc = s;

                c4_Field *f = d4_new c4_Field(desc);
                d4_assert(! *desc);

                Restructure(*f, false);
                *ptr_ += n;
            }
        }

        int rows = (int)c4_Column::PullValue(*ptr_);
        if (rows > 0) {
            SetNumRows(rows);

            for (int i = 0; i < NumFields(); ++i) {
                NthHandler(i).Define(rows, ptr_);
            }
        }
    }
UInt32 FieldContainerTreeModel::getChildCount(const boost::any& parent) const
{
    try
    {
	    ContainerFieldIdPair ThePair = boost::any_cast<ContainerFieldIdPair>(parent);

        //FieldContainer
        if(ThePair._FieldID == 0)
        {
            if(ThePair._Container != NULL)
            {
                UInt32 NumFields(0);
                for(UInt32 i(1) ; i<=ThePair._Container->getNumFields() ; ++i)
                {
                    if(isFieldAllowed(ThePair._Container->getFieldDescription(i)))
                    {
                        ++NumFields;
                    }
                }

                return NumFields;
            }
            else
            {
                return 0;
            }
        }
        //Field
        else
        {
            const FieldType& fcType(ThePair._Container->getFieldDescription(ThePair._FieldID)->getFieldType());
           
            if(isFieldAllowed(ThePair._Container->getFieldDescription(ThePair._FieldID)) &&
               ((fcType.getClass() == FieldType::PtrField      ) ||
               (fcType.getClass() == FieldType::ParentPtrField) ||
               (fcType.getClass() == FieldType::ChildPtrField )))
            {
                if(fcType.getCardinality() == FieldType::MultiField )
                {
                    return ThePair._Container->getField(ThePair._FieldID)->size();
                }
                else
                {
                    return 1;
                }
            }
            else
            {
                return 0;
            }
        }
    }
    catch(const boost::bad_any_cast &ex)
    {
        SWARNING << "Bad any cast" << ex.what() << "." << std::endl;
        return 0;
    }
}
Пример #4
0
void c4_HandlerSeq::DetermineSpaceUsage()
{
    for (int c = 0; c < NumFields(); ++c)
        if (IsNested(c)) {
            c4_Handler &h = NthHandler(c);
            for (int r = 0; r < NumRows(); ++r)
                if (h.HasSubview(r)) {
                    SubEntry(c, r).DetermineSpaceUsage();
                }
        }
}
Пример #5
0
c4_HandlerSeq::c4_HandlerSeq(c4_HandlerSeq &owner_, c4_Handler *handler_):
    _persist(owner_.Persist()), _field(owner_.FindField(handler_)), _parent
    (&owner_), _numRows(0)
{
    for (int i = 0; i < NumFields(); ++i) {
        c4_Field &field = Field(i);
        c4_Property prop(field.Type(), field.Name());

        d4_dbgdef(int n =)AddHandler(f4_CreateFormat(prop,  *this));
        d4_assert(n == i);
    }
}
Пример #6
0
void c4_HandlerSeq::Restructure(c4_Field &field_, bool remove_)
{
    //d4_assert(_field != 0);

    // all nested fields must be set up, before we shuffle them around
    for (int k = 0; k < NumHandlers(); ++k)
        if (IsNested(k)) {
            c4_Handler &h = NthHandler(k);
            for (int n = 0; n < NumRows(); ++n)
                if (h.HasSubview(n)) {
                    SubEntry(k, n);
                }
        }

    for (int i = 0; i < field_.NumSubFields(); ++i) {
        c4_Field &nf = field_.SubField(i);
        c4_Property prop(nf.Type(), nf.Name());

        int n = PropIndex(prop.GetId());
        if (n == i) {
            continue;
        }

        if (n < 0) {
            _handlers.InsertAt(i, f4_CreateFormat(prop,  *this));
            NthHandler(i).Define(NumRows(), 0);
        } else {
            // move the handler to the front
            d4_assert(n > i);
            _handlers.InsertAt(i, _handlers.GetAt(n));
            _handlers.RemoveAt(++n);
        }

        ClearCache(); // we mess with the order of handler, keep clearing it

        d4_assert(PropIndex(prop.GetId()) == i);
    }

    c4_Field *ofld = _field;
    // special case if we're "restructuring a view out of persistence", see below

    _field = remove_ ? 0 : &field_;

    // let handler do additional init once all have been prepared
    //for (int n = 0; n < NumHandlers(); ++n)
    //    NthHandler(n).Define(NumRows(), 0);

    const char *desc = "[]";
    c4_Field temp(desc);

    // all nested fields are restructured recursively
    for (int j = 0; j < NumHandlers(); ++j)
        if (IsNested(j)) {
            c4_Handler &h = NthHandler(j);
            for (int n = 0; n < NumRows(); ++n)
                if (h.HasSubview(n)) {
                    c4_HandlerSeq &seq = SubEntry(j, n);
                    if (j < NumFields()) {
                        seq.Restructure(field_.SubField(j), false);
                    } else if (seq._field != 0) {
                        seq.Restructure(temp, true);
                    }
                }
        }

    if (_parent == this) {
        delete ofld;
    }
    // the root table owns its field structure tree
}
/*-------------------------------------------------------------------------*\
 -  private                                                                 -
\*-------------------------------------------------------------------------*/
void GenericFieldContainerEditor::updateFieldsPanel(FieldContainer* fc)
{
    _FieldsContainer->clearChildren();

    UInt32 NumFields(fc->getType().getNumFieldDescs());
    FieldDescriptionBase* Desc;
    FieldEditorComponentUnrecPtr TheEditor;
    LabelUnrecPtr TheLabel;
    ComponentRecPtr TheToolTip;
    GridBagLayoutConstraintsRefPtr LayoutConstraints;
    PanelRefPtr FieldPanel;
    UInt32 NumRows(0),NumRowsForField(1);

    BorderLayoutRefPtr TheBorderLayout = BorderLayout::create();
    BorderLayoutConstraintsRefPtr WestConstraint = BorderLayoutConstraints::create();
    WestConstraint->setRegion(BorderLayoutConstraints::BORDER_WEST);
    BorderLayoutConstraintsRefPtr CenterConstraint = BorderLayoutConstraints::create();
    CenterConstraint->setRegion(BorderLayoutConstraints::BORDER_CENTER);

    //Backgrounds
    ColorLayerRefPtr HeaderBgLayer = ColorLayer::create();
    HeaderBgLayer->setColor(Color4f(0.7f,0.7f,0.7f,1.0f));

    ColorLayerRefPtr LightBgLayer = ColorLayer::create();
    LightBgLayer->setColor(Color4f(0.9f,0.9f,0.9f,1.0f));
    ColorLayerRefPtr DarkBgLayer = ColorLayer::create();
    DarkBgLayer->setColor(Color4f(0.8f,0.8f,0.8f,1.0f));

    LayoutConstraints = GridBagLayoutConstraints::create();
    LayoutConstraints->setGridX(0);
    LayoutConstraints->setGridY(NumRows);
    LayoutConstraints->setGridHeight(1);
    LayoutConstraints->setGridWidth(2);
    LayoutConstraints->setFill(GridBagLayoutConstraints::FILL_BOTH);

    LabelRecPtr FieldsLabel = Label::create();
    FieldsLabel->setAlignment(Vec2f(0.5f,0.5f));
    FieldsLabel->setText("Fields");
    FieldsLabel->setBackgrounds(HeaderBgLayer);
    FieldsLabel->setConstraints(LayoutConstraints);
    FieldsLabel->setFont(_BoldFont);

    _FieldsContainer->pushToChildren(FieldsLabel);
    ++NumRows;

    if(_GenericNameAttachmentEditor->isTypeEditable(fc->getType()))
    {
        //Create the Label
        TheLabel = Label::create();
        TheLabel->setText("Name");
        TheLabel->setBackgrounds(NULL);
        TheLabel->setConstraints(WestConstraint);
        TheLabel->setPreferredSize(Vec2f(160.0f,22.0f));

        //Attach the Generic Name Editor
        _GenericNameAttachmentEditor->setCommandManager(_CmdManager);
        _GenericNameAttachmentEditor->attachContainer(fc);
        _GenericNameAttachmentEditor->setConstraints(CenterConstraint);

        //Create the Panel
        LayoutConstraints = GridBagLayoutConstraints::create();
        LayoutConstraints->setGridX(0);
        LayoutConstraints->setGridY(NumRows);
        LayoutConstraints->setGridHeight(1);
        LayoutConstraints->setGridWidth(1);
        LayoutConstraints->setFill(GridBagLayoutConstraints::FILL_BOTH);

        FieldPanel = Panel::createEmpty();
        FieldPanel->setInset(Vec4f(1.0f,1.0f,1.0f,1.0f));
        FieldPanel->pushToChildren(TheLabel);
        FieldPanel->pushToChildren(_GenericNameAttachmentEditor);
        FieldPanel->setLayout(TheBorderLayout);
        FieldPanel->setConstraints(LayoutConstraints);
        FieldPanel->setBackgrounds(LightBgLayer);

        _FieldsContainer->pushToChildren(FieldPanel);
        ++NumRows;
    }

    UInt32 UsedFieldCount(0);
    for(UInt32 i(1) ; i<=NumFields ; ++i)
    {
        Desc = fc->getFieldDescription(i);
        if(Desc != NULL &&
           !Desc->isInternal() &&
           Desc->getFieldType().getClass() != FieldType::ParentPtrField &&
           //HACK: Stop the pixel field from being editable on Images
           !(fc->getType().isDerivedFrom(Image::getClassType()) &&
             Desc->getFieldId() == Image::PixelFieldId))
        {
            //Create the Editor
            TheEditor = FieldEditorFactory::the()->createDefaultEditor(fc, Desc->getFieldId(), _CmdManager);
            if(TheEditor != NULL)
            {
                NumRowsForField = TheEditor->getNumRequestedRows();
                pushToEditors(TheEditor);
                TheEditor->setConstraints(CenterConstraint);

                //Create the Label
                TheLabel = Label::create();
                TheLabel->setText(Desc->getCName());
                TheLabel->setBackgrounds(NULL);
                TheLabel->setConstraints(WestConstraint);
                TheLabel->setPreferredSize(Vec2f(160.0f,22.0f));
                TheToolTip = createFieldToolTip(Desc);
                TheLabel->setToolTip(TheToolTip);

                //Create the Panel
                LayoutConstraints = GridBagLayoutConstraints::create();
                LayoutConstraints->setGridX(0);
                LayoutConstraints->setGridY(NumRows);
                LayoutConstraints->setGridHeight(NumRowsForField);
                LayoutConstraints->setGridWidth(1);
                LayoutConstraints->setFill(GridBagLayoutConstraints::FILL_BOTH);


                FieldPanel = Panel::createEmpty();
                FieldPanel->setInset(Vec4f(1.0f,1.0f,1.0f,1.0f));
                FieldPanel->pushToChildren(TheLabel);
                FieldPanel->pushToChildren(TheEditor);
                FieldPanel->setLayout(TheBorderLayout);
                FieldPanel->setConstraints(LayoutConstraints);
                if((UsedFieldCount%2) == 0)
                {
                    FieldPanel->setBackgrounds(DarkBgLayer);
                }
                else
                {
                    FieldPanel->setBackgrounds(LightBgLayer);
                }

                _FieldsContainer->pushToChildren(FieldPanel);
                NumRows += NumRowsForField;
                TheEditor->setPreferredSize(Vec2f(50.0f,22.0f * NumRowsForField));
                ++UsedFieldCount;
            }
        }
    }

    //Set the number of rows for the grid layout
    dynamic_cast<GridBagLayout*>(_FieldsContainer->getLayout())->setRows(NumRows);
    _FieldsContainer->setPreferredSize(Vec2f(400.0f, NumRows*24.0f));
}
boost::any FieldContainerTreeModel::getChild(const boost::any& parent, const UInt32& index) const
{
    try
    {
	    ContainerFieldIdPair ThePair = boost::any_cast<ContainerFieldIdPair>(parent);

        //FieldContainer
        if(ThePair._FieldID == 0)
        {
            UInt32 FieldId(1);
            UInt32 NumFields(0);
            for( ; FieldId<=ThePair._Container->getNumFields() ; ++FieldId)
            {
                if(isFieldAllowed(ThePair._Container->getFieldDescription(FieldId)))
                {
                    ++NumFields;
                    if(NumFields == index+1)
                    {
                        break;
                    }
                }
            }

            ContainerFieldIdPair ChildPair(ThePair._Container,FieldId);
            return boost::any(ChildPair);
        }
        //Field
        else
        {
            const FieldType& fcType(ThePair._Container->getFieldDescription(ThePair._FieldID)->getFieldType());
           
            if((fcType.getClass() == FieldType::PtrField      ) ||
               (fcType.getClass() == FieldType::ParentPtrField) ||
               (fcType.getClass() == FieldType::ChildPtrField ))
            {
                if(fcType.getCardinality() == FieldType::MultiField )
                {
                    if(index < ThePair._Container->getField(ThePair._FieldID)->size())
                    {
                        GetFieldHandlePtr TempHandle(ThePair._Container->getField(ThePair._FieldID));
                        FieldContainerWeakPtr TheContainer = dynamic_cast<GetMFieldHandle<FieldContainerPtrMFieldBase>*>(TempHandle.get())->get(index);

                        return boost::any(ContainerFieldIdPair(TheContainer,0));
                    }
                    else
                    {
                        SWARNING << "Index out of bounds." << std::endl;
                        return boost::any();
                    }
                }
                else
                {
                    if(index == 0)
                    {
                        GetFieldHandlePtr TempHandle(ThePair._Container->getField(ThePair._FieldID));
                        FieldContainerWeakPtr TheContainer = dynamic_cast<GetSFieldHandle<FieldContainerPtrSFieldBase>*>(TempHandle.get())->get();

                        return boost::any(ContainerFieldIdPair(TheContainer,0));
                    }
                    else
                    {
                        SWARNING << "Index out of bounds." << std::endl;
                        return boost::any();
                    }
                }
            }
            else
            {
                SWARNING << "Not Ptr field." << std::endl;
                return boost::any();
            }
        }
    }
    catch(const boost::bad_any_cast &ex)
    {
        SWARNING << "Bad any cast" << ex.what() << "." << std::endl;
        return boost::any();
    }
}