Skip to content

[컴포넌트 개발] ComputeTable

Jinyoung Jang edited this page Sep 12, 2016 · 2 revisions

ComputeTable

package com.abc.widget;

import org.metaworks.ContextAware;
import org.metaworks.MetaworksContext;
import org.metaworks.annotation.Range;
import org.metaworks.annotation.ServiceMethod;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by jjy on 2016. 9. 1..
 */
public class ComputeTable implements ContextAware, Serializable{

   List<ComputeTableRow> computeTableRowList;

    public List<ComputeTableRow> getComputeTableRowList() {
        return computeTableRowList;
    }

    public void setComputeTableRowList(List<ComputeTableRow> computeTableRowList) {
        this.computeTableRowList = computeTableRowList;
    }


    public ComputeTable(){

        setComputeTableRowList(new ArrayList<ComputeTableRow>());

        getComputeTableRowList().add(new ComputeTableRow());

    }


    MetaworksContext metaworksContext;
        @Override
        public MetaworksContext getMetaworksContext() {
            return metaworksContext;
        }
        @Override
        public void setMetaworksContext(MetaworksContext metaworksContext) {
            this.metaworksContext = metaworksContext;
        }





    @ServiceMethod(callByContent = true)
    public void addRow(){
        setMetaworksContext(new MetaworksContext());
        getMetaworksContext().setWhen(MetaworksContext.WHEN_EDIT);

        getComputeTableRowList().add(new ComputeTableRow());
    }
}

Note

  1. Serializable 이 있어야 액티비티가 XStream 등에 의하여 저장될 때 문제 없이 Serialization 이 벌어진다.
  2. ContextAware 가 있어야 디자인 타임에서 EDIT 모드가 유지된다.

ComputeTableRow

package com.abc.widget;

import org.metaworks.EventContext;
import org.metaworks.annotation.AutowiredFromClient;
import org.metaworks.annotation.Face;
import org.metaworks.annotation.Range;
import org.metaworks.annotation.ServiceMethod;

import java.io.Serializable;

/**
 * Created by jjy on 2016. 9. 1..
 */
@Face(ejsPathForArray = "dwr/metaworks/genericfaces/CleanArrayFace.ejs")
public class ComputeTableRow implements Serializable{

    String column;
        public String getColumn() {
            return column;
        }
        public void setColumn(String column) {
            this.column = column;
        }

    String function;
        @Range(
                options={"sum", "avg", "round"},
                values={"sum", "avg", "round"}


        )
        public String getFunction() {
            return function;
        }
        public void setFunction(String function) {
            this.function = function;
        }

    int n;
        public int getN() {
            return n;
        }
        public void setN(int n) {
            this.n = n;
        }

    String formula;
        public String getFormula() {
            return formula;
        }
        public void setFormula(String formula) {
            this.formula = formula;
        }

    boolean isDeleted;
        public boolean isDeleted() {
            return isDeleted;
        }
        public void setDeleted(boolean isDeleted) {
            this.isDeleted = isDeleted;
        }



    @ServiceMethod(target=ServiceMethod.TARGET_SELF, inContextMenu = true)
    public void remove(){
        setDeleted(true);
    }

    @ServiceMethod(target=ServiceMethod.TARGET_SELF, eventBinding = EventContext.EVENT_CHANGE, bindingFor = "function", callByContent = true, inContextMenu = true)
    public void refresh(){

        setFormula(getFunction() + "(" + getColumn() + ", " + getN() + ")");

    }

    @ServiceMethod(target=ServiceMethod.TARGET_SELF, eventBinding = EventContext.EVENT_CHANGE, bindingFor = "column", callByContent = true)
    public void refresh_(){

       refresh();

    }

}

ComputeTable.ejs

<table>


    <tr>
        <th>Column</th>
        <th>Function</th>
        <th>N</th>
        <th>Formula</th>
    </tr>

    <%=fields.computeTableRowList.here()%>

</table>


<%=methods.addRow.here()%>

ComputeTableRow.ejs

<!--replace-->

<%
 if(!value.deleted){
%>

<tr id="objDiv_<%=objectId%>">

    <td><%=fields.column.here()%></td>
    <td><%=fields.function.here()%></td>
    <td><%=fields.n.here()%></td>
    <td><%=fields.formula.here()%></td>

</tr>

<%
 }
%>