Example usage for com.google.gwt.cell.client CompositeCell CompositeCell

List of usage examples for com.google.gwt.cell.client CompositeCell CompositeCell

Introduction

In this page you can find the example usage for com.google.gwt.cell.client CompositeCell CompositeCell.

Prototype

public CompositeCell(List<HasCell<C, ?>> hasCells) 

Source Link

Document

Construct a new CompositeCell .

Usage

From source file:accelerator.client.ui.TaskDialogBox.java

License:Open Source License

/**
 * /*w  ww  .  j  a  va  2 s. c  o m*/
 */
public TaskDialogBox() {
    setWidget(uiBinder.createAndBindUi(this));

    projectListBox.addItem("(??)", "");

    List<HasCell<Tag, ?>> hasCells = CollectionUtil.createArrayList();
    hasCells.add(new HasCell<Tag, Boolean>() {
        private final CheckboxCell cell = new CheckboxCell();

        public Cell<Boolean> getCell() {
            return cell;
        }

        public FieldUpdater<Tag, Boolean> getFieldUpdater() {
            return null;
        }

        public Boolean getValue(Tag object) {
            return selectionModel.isSelected(object);
        }
    });
    hasCells.add(new HasCell<Tag, Tag>() {
        private final TagCell cell = new TagCell();

        public Cell<Tag> getCell() {
            return cell;
        }

        public FieldUpdater<Tag, Tag> getFieldUpdater() {
            return null;
        }

        public Tag getValue(Tag object) {
            return object;
        }

    });
    CompositeCell<Tag> tagCell = new CompositeCell<Tag>(hasCells);

    tagCellList = new CellList<Tag>(tagCell);
    tagCellList.setSelectionModel(selectionModel, selectionManager);
    scrollPanel.add(tagCellList);

    nameErrorLabel.setVisible(false);
    setText("??");
    setHandler(null);

    // DateBox ??
    dueDateBox.setFormat(new DateBox.DefaultFormat(DateTimeFormat.getFormat("yyyy/MM/dd")));
}

From source file:com.akanoo.client.views.SharingPopupView.java

License:Apache License

private void setupCellList(CellList.Resources cellListResources) {
    selectionModel = new MultiSelectionModel<UserInfo>(UserInfo.keyprovider);

    // Construct a composite cell for contacts that includes a checkbox.
    List<HasCell<UserInfo, ?>> hasCells = new ArrayList<HasCell<UserInfo, ?>>();
    hasCells.add(new HasCell<UserInfo, Boolean>() {

        private CheckboxCell cell = new CheckboxCell(true, false);

        public Cell<Boolean> getCell() {
            return cell;
        }//from w  ww.ja v  a  2s  . com

        public FieldUpdater<UserInfo, Boolean> getFieldUpdater() {
            return null;
        }

        public Boolean getValue(UserInfo object) {
            return selectionModel.isSelected(object);
        }
    });
    hasCells.add(new HasCell<UserInfo, UserInfo>() {

        private UserCell cell = new UserCell();

        public Cell<UserInfo> getCell() {
            return cell;
        }

        public FieldUpdater<UserInfo, UserInfo> getFieldUpdater() {
            return null;
        }

        public UserInfo getValue(UserInfo object) {
            return object;
        }
    });
    CompositeCell<UserInfo> friendCell = new CompositeCell<UserInfo>(hasCells) {
        @Override
        public void render(Context context, UserInfo value, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant("<table><tbody><tr>");
            super.render(context, value, sb);
            sb.appendHtmlConstant("</tr></tbody></table>");
        }

        @Override
        protected Element getContainerElement(Element parent) {
            // Return the first TR element in the table.
            return parent.getFirstChildElement().getFirstChildElement().getFirstChildElement();
        }

        @Override
        protected <X> void render(Context context, UserInfo value, SafeHtmlBuilder sb,
                HasCell<UserInfo, X> hasCell) {
            Cell<X> cell = hasCell.getCell();
            sb.appendHtmlConstant("<td>");
            cell.render(context, hasCell.getValue(value), sb);
            sb.appendHtmlConstant("</td>");
        }
    };

    shares = new CellList<UserInfo>(friendCell, cellListResources, UserInfo.keyprovider);
    shares.setSelectionModel(selectionModel, DefaultSelectionEventManager.<UserInfo>createCheckboxManager());

    dataProvider = new ListDataProvider<UserInfo>(UserInfo.keyprovider);
    dataProvider.addDataDisplay(shares);

    selectionModel.addSelectionChangeHandler(this);
}

From source file:com.ephesoft.gxt.core.client.ui.widget.TableExtractionAPICompositeCell.java

License:Open Source License

public CompositeCell<T> createCompositeCell() {

    final ListStore<String> andOrOpearators = new ListStore<String>(new ModelKeyProvider<String>() {

        @Override/*from   w w w .  j  av a2s.com*/
        public String getKey(String item) {

            if (StringUtil.isNullOrEmpty(item)) {
                item = CoreCommonConstant.OR_OPERATOR;
            }
            return item;
        }
    });
    andOrOpearators.add(CoreCommonConstant.OR_OPERATOR);
    andOrOpearators.add(CoreCommonConstant.AND_OPERATOR);

    final HasCell<T, String> coordHeaderCombo = new HasCell<T, String>() {

        public ComboBoxCell<String> getCell() {
            ComboBoxCell<String> coordHeaderComboCell = new ComboBoxCell<String>(andOrOpearators,
                    new LabelProvider<String>() {

                        @Override
                        public String getLabel(String item) {
                            if (StringUtil.isNullOrEmpty(item)) {
                                item = CoreCommonConstant.OR_OPERATOR;
                            }
                            return item;
                        }
                    });
            coordHeaderComboCell.setTriggerAction(TriggerAction.ALL);
            coordHeaderComboCell.setForceSelection(true);
            coordHeaderComboCell.setWidth(60);
            return coordHeaderComboCell;
        }

        public FieldUpdater<T, String> getFieldUpdater() {
            return new FieldUpdater<T, String>() {

                @Override
                public void update(int index, T object, String value) {
                    // TODO Auto-generated method stub
                    if (object != null && value != null) {
                        object.setCoordinateHeaderComb(value);
                        ;
                    }
                }
            };
        }

        public String getValue(T object) {
            if (object != null && !StringUtil.isNullOrEmpty(object.getCoordinateHeaderComb())) {
                return object.getCoordinateHeaderComb();
            }
            return CoreCommonConstant.OR_OPERATOR;
        }
    };

    final HasCell<T, Boolean> colCoordCell = new HasCell<T, Boolean>() {

        public CheckBoxCell getCell() {
            return new CheckBoxCell();
        }

        public FieldUpdater<T, Boolean> getFieldUpdater() {
            return new FieldUpdater<T, Boolean>() {

                @Override
                public void update(int index, T object, Boolean value) {
                    // TODO Auto-generated method stub
                    if (object != null && value != null) {
                        object.setColumnCoordinates(value);
                    }
                }
            };
        }

        public Boolean getValue(T object) {
            boolean chkValue = false;
            if (object != null) {
                chkValue = object.isColumnCoordinates();
            }
            return chkValue;
        }
    };

    HasCell<T, String> colCoordLabel = new HasCell<T, String>() {

        public Cell<String> getCell() {
            return new TextCell();
        }

        public FieldUpdater<T, String> getFieldUpdater() {
            return null;
        }

        public String getValue(T object) {
            return LocaleDictionary.getConstantValue(CoreCommonConstants.LABEL_COLUMN_COORDINATES);
        }
    };

    final HasCell<T, Boolean> colHeaderCell = new HasCell<T, Boolean>() {

        public CheckBoxCell getCell() {
            return new CheckBoxCell();
        }

        public FieldUpdater<T, Boolean> getFieldUpdater() {
            return new FieldUpdater<T, Boolean>() {

                @Override
                public void update(int index, T object, Boolean value) {
                    // TODO Auto-generated method stub
                    if (object != null && value != null) {
                        object.setColumnHeader(value);
                    }
                }
            };
        }

        public Boolean getValue(T object) {
            if (object != null) {
                return object.isColumnHeader();
            }
            return false;
        }
    };

    HasCell<T, String> colHeaderLabel = new HasCell<T, String>() {

        public Cell<String> getCell() {
            return new TextCell();
        }

        public FieldUpdater<T, String> getFieldUpdater() {
            return null;
        }

        public String getValue(T object) {
            return LocaleDictionary.getConstantValue(CoreCommonConstants.LABEL_COLUMN_HEADER);
        }
    };

    final HasCell<T, String> headerRegexCombo = new HasCell<T, String>() {

        public ComboBoxCell<String> getCell() {
            ComboBoxCell<String> headerRegexComboCell = new ComboBoxCell<String>(andOrOpearators,
                    new LabelProvider<String>() {

                        @Override
                        public String getLabel(String item) {
                            if (StringUtil.isNullOrEmpty(item)) {
                                item = CoreCommonConstant.OR_OPERATOR;
                            }
                            return item;
                        }
                    });
            headerRegexComboCell.setTriggerAction(TriggerAction.ALL);
            headerRegexComboCell.setForceSelection(true);
            headerRegexComboCell.setWidth(60);
            return headerRegexComboCell;
        }

        public FieldUpdater<T, String> getFieldUpdater() {
            return new FieldUpdater<T, String>() {

                @Override
                public void update(int index, T object, String value) {
                    // TODO Auto-generated method stub
                    if (object != null && value != null) {
                        object.setHeaderRegexComb(value);
                    }
                }
            };
        }

        public String getValue(T object) {
            if (object != null && !StringUtil.isNullOrEmpty(object.getHeaderRegexComb())) {
                return object.getHeaderRegexComb();
            }
            return CoreCommonConstant.OR_OPERATOR;
        }
    };

    HasCell<T, Boolean> regexExtCell = new HasCell<T, Boolean>() {

        public CheckBoxCell getCell() {
            CheckBoxCell checkBox = new CheckBoxCell();
            return checkBox;
        }

        public FieldUpdater<T, Boolean> getFieldUpdater() {
            return new FieldUpdater<T, Boolean>() {

                @Override
                public void update(int index, TableExtractionAPIModel object, Boolean value) {
                    // TODO Auto-generated method stub
                    if (object != null && value != null) {
                        object.setRegexExtraction(value);
                    }
                }
            };
        }

        public Boolean getValue(T object) {
            if (object != null) {
                return object.isRegexExtraction();
            }
            return false;
        }
    };

    HasCell<T, String> regexExtLabel = new HasCell<T, String>() {

        public Cell<String> getCell() {
            return new TextCell();
        }

        public FieldUpdater<T, String> getFieldUpdater() {
            return null;
        }

        public String getValue(T object) {
            return LocaleDictionary.getConstantValue(CoreCommonConstants.LABEL_REGEX_EXTRACTION);
        }
    };

    List<HasCell<T, ?>> cells = new ArrayList<HasCell<T, ?>>();
    cells.add(colCoordCell);
    cells.add(colCoordLabel);
    cells.add(coordHeaderCombo);
    cells.add(colHeaderCell);
    cells.add(colHeaderLabel);
    cells.add(headerRegexCombo);
    cells.add(regexExtCell);
    cells.add(regexExtLabel);
    CompositeCell<T> compositeCell = new CompositeCell<T>(cells);
    return compositeCell;
}

From source file:com.goodow.wave.client.wavepanel.blip.TreeTestViewModel.java

License:Apache License

TreeTestViewModel() {
    List<String> title = titles.getList();
    title.add("a");
    title.add("b");
    title.add("c");
    title.add("d");

    List<HasCell<Integer, ?>> hasCell = new ArrayList<HasCell<Integer, ?>>();
    hasCell.add(new HasCell<Integer, Integer>() {

        private AbstractCell<Integer> cell = new AbstractCell<Integer>() {

            @Override//from w w  w.j ava2  s .c  om
            public void render(final com.google.gwt.cell.client.Cell.Context context, final Integer value,
                    final SafeHtmlBuilder sb) {
                sb.append(SafeHtmlUtils.fromTrustedString("<div style='float:left;'>"));
                sb.append(value.intValue());
                sb.append(SafeHtmlUtils.fromTrustedString("</div>"));
            }
        };

        @Override
        public Cell<Integer> getCell() {
            return cell;
        }

        @Override
        public FieldUpdater<Integer, Integer> getFieldUpdater() {
            return null;
        }

        @Override
        public Integer getValue(final Integer object) {
            return object;
        }
    });

    hasCell.add(new HasCell<Integer, Integer>() {

        private TrangleButtonCell<Integer> tbc = new TrangleButtonCell<Integer>();

        @Override
        public Cell<Integer> getCell() {
            return tbc;
        }

        @Override
        public FieldUpdater<Integer, Integer> getFieldUpdater() {
            return null;
        }

        @Override
        public Integer getValue(final Integer object) {
            return object;
        }
    });

    composite = new CompositeCell<Integer>(hasCell) {

        @Override
        public void render(final Context context, final Integer value, final SafeHtmlBuilder sb) {
            sb.append(SafeHtmlUtils.fromTrustedString("<div>"));
            super.render(context, value, sb);
            sb.append(SafeHtmlUtils.fromTrustedString("</div>"));
        }

        @Override
        protected Element getContainerElement(final Element parent) {
            return parent.getFirstChildElement();
        }

        @Override
        protected <X> void render(final Context context, final Integer value, final SafeHtmlBuilder sb,
                final HasCell<Integer, X> hasCell) {
            Cell<X> cell = hasCell.getCell();
            // sb.append(SafeHtmlUtils.fromTrustedString("<div>"));
            cell.render(context, hasCell.getValue(value), sb);
            // sb.append(SafeHtmlUtils.fromTrustedString("</div>"));
        }
    };

}

From source file:com.google.gwt.sample.showcase.client.content.cell.ContactTreeViewModel.java

License:Apache License

public ContactTreeViewModel(final SelectionModel<ContactInfo> selectionModel) {
    this.selectionModel = selectionModel;
    if (images == null) {
        images = GWT.create(Images.class);
    }//from  w w w.  ja  v a2  s  . co  m

    // Create a data provider that provides categories.
    categoryDataProvider = new ListDataProvider<Category>();
    List<Category> categoryList = categoryDataProvider.getList();
    for (Category category : ContactDatabase.get().queryCategories()) {
        categoryList.add(category);
    }

    // Construct a composite cell for contacts that includes a checkbox.
    List<HasCell<ContactInfo, ?>> hasCells = new ArrayList<HasCell<ContactInfo, ?>>();
    hasCells.add(new HasCell<ContactInfo, Boolean>() {

        private CheckboxCell cell = new CheckboxCell(true, false);

        public Cell<Boolean> getCell() {
            return cell;
        }

        public FieldUpdater<ContactInfo, Boolean> getFieldUpdater() {
            return null;
        }

        public Boolean getValue(ContactInfo object) {
            return selectionModel.isSelected(object);
        }
    });
    hasCells.add(new HasCell<ContactInfo, ContactInfo>() {

        private ContactCell cell = new ContactCell(images.contact());

        public Cell<ContactInfo> getCell() {
            return cell;
        }

        public FieldUpdater<ContactInfo, ContactInfo> getFieldUpdater() {
            return null;
        }

        public ContactInfo getValue(ContactInfo object) {
            return object;
        }
    });
    contactCell = new CompositeCell<ContactInfo>(hasCells) {
        @Override
        public void render(Context context, ContactInfo value, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant("<table><tbody><tr>");
            super.render(context, value, sb);
            sb.appendHtmlConstant("</tr></tbody></table>");
        }

        @Override
        protected Element getContainerElement(Element parent) {
            // Return the first TR element in the table.
            return parent.getFirstChildElement().getFirstChildElement().getFirstChildElement();
        }

        @Override
        protected <X> void render(Context context, ContactInfo value, SafeHtmlBuilder sb,
                HasCell<ContactInfo, X> hasCell) {
            Cell<X> cell = hasCell.getCell();
            sb.appendHtmlConstant("<td>");
            cell.render(context, hasCell.getValue(value), sb);
            sb.appendHtmlConstant("</td>");
        }
    };
}

From source file:com.gwtmodel.table.view.table.edit.PresentationEditCellFactory.java

License:Apache License

@SuppressWarnings({ "rawtypes", "unchecked" })
private Column constructControlColumn() {
    // return new ImageColumn();

    List<HasCell> ce = new ArrayList<HasCell>();
    // TODO: blocked now, re-think the usage
    // ce.add(new
    // HasCellImage(ImageNameFactory.getImageName(ImageNameFactory.ImageType.CHANGEROW),
    // PersistTypeEnum.MODIF));
    ce.add(new HasCellImage(PersistTypeEnum.REMOVE));
    ce.add(new HasCellImage(PersistTypeEnum.ADD));
    CompositeCell<MutableInteger> cCell = new CompositeCell(ce);
    Column<MutableInteger, MutableInteger> imageColumn = new Column<MutableInteger, MutableInteger>(cCell) {
        @Override//from  w  w  w  .ja v a 2 s  .  com
        public MutableInteger getValue(MutableInteger object) {
            return object;
        }
    };
    return imageColumn;

}

From source file:com.retech.reader.web.client.labs.Labs.java

License:Apache License

@Inject
Labs(final CellList.Resources resource, final PlaceController placeController, final Provider<BasePlace> base) {
    this.setWaveContent(binder.createAndBindUi(this));

    setColor.setChangeElm(simplePanel.getElement());

    minimize.setIconElement(//w  w w  .  j  a v  a2 s.c o m
            AbstractImagePrototype.create(WaveTitleResources.image().waveTitleMinimize()).createElement());

    // add Data
    List<LabsIconDecorator> list = listDataProvider.getList();
    LabsIconDecorator touch = new LabsIconDecorator(bunder.laboratory(), "", WaveTest.class);
    list.add(touch);

    LabsIconDecorator flip = new LabsIconDecorator(bunder.laboratory(), "3D", BookFlip.class);
    list.add(flip);

    LabsIconDecorator contact = new LabsIconDecorator(bunder.laboratory(), "??",
            ContactPanel.class);
    list.add(contact);

    LabsIconDecorator treeTest = new LabsIconDecorator(bunder.laboratory(), "TreeTest", TreeTest.class);
    list.add(treeTest);

    LabsIconDecorator search = new LabsIconDecorator(bunder.laboratory(), "?", SearchPanel.class);
    list.add(search);

    LabsIconDecorator blipTest = new LabsIconDecorator(bunder.laboratory(), "BlipTest", BlipTest.class);
    list.add(blipTest);

    LabsIconDecorator blipTree = new LabsIconDecorator(bunder.laboratory(), "NestedBlipTest",
            NestedBlipTest.class);
    list.add(blipTree);

    LabsIconDecorator settingsView = new LabsIconDecorator(bunder.laboratory(), "", SettingsView.class);
    list.add(settingsView);

    LabsIconDecorator contactPanel = new LabsIconDecorator(bunder.laboratory(), "", ContactPanel.class);
    list.add(contactPanel);

    server.add(
            new Anchor("Android", "https://build.phonegap.com/apps/95095/download/android", "_blank"));
    server.add(
            new Anchor("iOS", "https://build.phonegap.com/apps/95095/download/ios", "_blank"));
    server.add(new Anchor("Google Play?",
            "https://play.google.com/store/apps/details?id=com.goodow.web.mobile", "_blank"));
    server.add(new Anchor("SCM - Subversion", SERVER_URL + "/svn/retech", "_blank"));
    server.add(new Anchor("Files", SERVER_URL + "/files", "_blank"));
    server.add(new Anchor("Document", SERVER_URL + "/svn/retech/document", "_blank"));
    server.add(new Anchor("CI - Hudson", SERVER_URL + ":8080", "_blank"));
    server.add(new Anchor("Repository - Nexus", SERVER_URL + ":8081/nexus", "_blank"));

    // add cell
    List<HasCell<LabsIconDecorator, ?>> hasCells = new ArrayList<HasCell<LabsIconDecorator, ?>>();
    hasCells.add(new HasCell<LabsIconDecorator, LabsIconDecorator>() {

        LabsIconDecoratorCell cell = new LabsIconDecoratorCell(
                new LabsIconDecoratorCell.Delegate<LabsIconDecorator>() {

                    @Override
                    public void execute(final LabsIconDecorator object) {
                        placeController.goTo(base.get().setPath(object.getClassName().getName()));
                    }
                });

        @Override
        public Cell<LabsIconDecorator> getCell() {
            return cell;
        }

        @Override
        public FieldUpdater<LabsIconDecorator, LabsIconDecorator> getFieldUpdater() {
            return null;
        }

        @Override
        public LabsIconDecorator getValue(final LabsIconDecorator object) {
            return object;
        }
    });

    hasCells.add(new HasCell<LabsIconDecorator, LabsIconDecorator>() {

        private TrangleButtonCell<LabsIconDecorator> tbc = new TrangleButtonCell<LabsIconDecorator>();

        @Override
        public Cell<LabsIconDecorator> getCell() {
            return tbc;
        }

        @Override
        public FieldUpdater<LabsIconDecorator, LabsIconDecorator> getFieldUpdater() {
            return null;
        }

        @Override
        public LabsIconDecorator getValue(final LabsIconDecorator object) {
            return object;
        }
    });

    compositeCell = new CompositeCell<LabsIconDecorator>(hasCells) {

        @Override
        public void render(final com.google.gwt.cell.client.Cell.Context context, final LabsIconDecorator value,
                final SafeHtmlBuilder sb) {
            super.render(context, value, sb);
        }

        @Override
        protected Element getContainerElement(final Element parent) {
            return parent;
        }

        @Override
        protected <X> void render(final com.google.gwt.cell.client.Cell.Context context,
                final LabsIconDecorator value, final SafeHtmlBuilder sb,
                final HasCell<LabsIconDecorator, X> hasCell) {
            Cell<X> cell = hasCell.getCell();
            cell.render(context, hasCell.getValue(value), sb);
        }
    };

    // add cellList
    cellList = new CellList<LabsIconDecorator>(compositeCell, resource);

    // add cellPreviewHanler
    cellList.addCellPreviewHandler(new CellPreviewEvent.Handler<LabsIconDecorator>() {

        @Override
        public void onCellPreview(final CellPreviewEvent<LabsIconDecorator> event) {
            NativeEvent nativeEvent = event.getNativeEvent();
            boolean isClick = nativeEvent.getType().equals(BrowserEvents.CLICK);
            if (isClick) {
                Element clickelm = cellList.getRowElement(event.getIndex());
                Element eventTarget = Element.as(nativeEvent.getEventTarget());
                if (clickelm.getFirstChildElement() == eventTarget) {
                    if (Labs.this.lastElm == null) {
                        Labs.this.lastElm = clickelm;
                    }
                    if (Labs.this.lastElm != clickelm) {
                        Labs.this.lastElm.removeClassName(LabsResources.css().cellListSelectionItem());
                        clickelm.addClassName(LabsResources.css().cellListSelectionItem());
                        Labs.this.lastElm = clickelm;
                    } else if (Labs.this.lastElm == clickelm) {
                        clickelm.addClassName(LabsResources.css().cellListSelectionItem());
                    }
                }
            }
        }
    });
    simplePanel.add(cellList);
}

From source file:com.webgocommerce.client.view.tree.TreeMenuModel.java

private void initComponents() {
    List<HasCell<MenuBar, ?>> hasCells = new ArrayList<HasCell<MenuBar, ?>>();
    hasCells.add(new HasCell<MenuBar, Boolean>() {

        private CheckboxCell cell = new CheckboxCell(true, true);

        @Override/*from   w  w w  .j  a v  a  2s. c  o  m*/
        public Cell<Boolean> getCell() {
            return cell;
        }

        @Override
        public FieldUpdater<MenuBar, Boolean> getFieldUpdater() {
            return new FieldUpdater<MenuBar, Boolean>() {
                public void update(int index, MenuBar object, Boolean value) {
                    selectionModel.setSelected(object, value);
                    object.setOperacion("A");
                    object.setEstado(value == true ? "A" : "D");
                    if (object.getPadre() != null
                            && !object.getPadre().getVariable().equalsIgnoreCase("root")) {
                        if (value) {
                            //selectionModel.setSelected(object.getPadre(), value);
                            //object.getPadre().setOperacion("A");
                            SelectedFather(object);
                        }
                    }
                    isSelectedChild(object, value);
                }
            };
        }

        @Override
        public Boolean getValue(MenuBar object) {
            if (object.getEstado().equalsIgnoreCase("A") && object.getOperacion().equalsIgnoreCase("N")) {
                selectionModel.setSelected(object, true);
                return true;
            }
            return selectionModel.isSelected(object);
        }

        public void SelectedFather(MenuBar menuBar) {
            if (!selectionModel.isSelected(menuBar.getPadre())) {
                selectionModel.setSelected(menuBar.getPadre(), true);
                menuBar.getPadre().setOperacion("A");
                menuBar.getPadre().setEstado("A");
                if (menuBar.getPadre() != null) {
                    SelectedFather(menuBar.getPadre());
                }
            }
        }

        public void isSelectedChild(MenuBar menuBar, Boolean val) {
            Iterator<MenuBar> iterador = menuBar.getHijos().iterator();
            while (iterador.hasNext()) {
                MenuBar bean = iterador.next();
                selectionModel.setSelected(bean, val);
                bean.setOperacion("A");
                bean.setEstado(val == true ? "A" : "D");
                isSelectedChild(bean, val);
            }
        }

    });

    menuBarCell = new CompositeCell<MenuBar>(hasCells) {

        /*@Override
         public void onBrowserEvent(Cell.Context context, Element parent, MenuBar value,
         NativeEvent event, ValueUpdater<MenuBar> valueUpdater) {
         if ("keyup".equals(event.getType())
         && event.getKeyCode() == KeyCodes.KEY_ENTER) {
         selectionModel.setSelected(value, !selectionModel.isSelected(value));
         }
         }*/
        @Override
        public void render(Cell.Context context, MenuBar value, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant("<table><tbody><tr>");
            super.render(context, value, sb);
            sb.appendHtmlConstant("</tr></tbody></table>");
        }

        @Override
        protected Element getContainerElement(Element parent) {
            return parent.getFirstChildElement().getFirstChildElement().getFirstChildElement();
        }

        @Override
        protected <X> void render(Cell.Context context, MenuBar value, SafeHtmlBuilder sb,
                HasCell<MenuBar, X> hasCell) {
            Cell<X> cell = hasCell.getCell();
            sb.appendHtmlConstant("<td>");
            cell.render(context, hasCell.getValue(value), sb);
            sb.appendHtmlConstant(" " + value.getOrden());
            sb.appendHtmlConstant(" " + value.getDescripcion());
            sb.appendHtmlConstant("</td>");
        }
    };

    /*hasCells.add(new HasCell<MenuBar, MenuBar>() {
            
     private MenuBarCell cell = new MenuBarCell();
            
     public Cell<MenuBar> getCell() {
     return cell;
     }
            
     public FieldUpdater<MenuBar, MenuBar> getFieldUpdater() {
     return null;
     }
            
     public MenuBar getValue(MenuBar object) {
     return object;
     }
     });*/
}

From source file:n3phele.client.view.CommandDetailView.java

License:Open Source License

private CompositeCell<FileSpecification> createRepoRefCompositeCell(final boolean isInput) {
    final RepoIconTextCell repo = new RepoIconTextCell(N3phele.n3pheleResource.repositorySmallIcon(),
            new TextCell(RepoTextCellRenderer.getInstance()));
    final TextCell path = new TextCell(FilenamePathRenderer.getInstance());
    final ValidInputIndicatorCell valid = new ValidInputIndicatorCell(N3phele.n3pheleResource.inputErrorIcon());
    final BrowseActionCell browse = new BrowseActionCell(new Delegate<FileSpecification>() {

        @Override//from   w  w w  .j  a va  2  s . com
        public void execute(final FileSpecification fileSpecification) {
            final PopupPanel popup = new PopupPanel(true);
            FileNodeBrowser.BrowserPresenter presenter;
            FileNodeBrowser view = new FileNodeBrowser(presenter = new FileNodeBrowser.BrowserPresenter() {
                FileNodeBrowser view;

                @Override
                public void setView(FileNodeBrowser view) {
                    this.view = view;
                }

                /* (non-Javadoc)
                 * @see n3phele.client.widgets.FileNodeBrowser.BrowserPresenter#select(n3phele.client.model.FileNode)
                 */
                @Override
                public void selectFolder(FileNode value) {
                    if (!value.getMime().equals("application/vnd.com.n3phele.Repository+json")) {
                        String path = value.getPath() == null ? value.getName() + "/"
                                : (value.getPath() + value.getName() + "/");
                        if (path.startsWith("/"))
                            GWT.log("FileNode " + value + " produces query with leading /");
                        CommandDetailView.this.presenter.fetchFiles(view, value.getRepository(), path);
                    } else {
                        CommandDetailView.this.presenter.fetchFiles(view, value.getRepository(), null);
                    }

                }

                /* (non-Javadoc)
                 * @see n3phele.client.widgets.FileNodeBrowser.BrowserPresenter#select(n3phele.client.model.FileNode)
                 */
                @Override
                public void selectFolder(Repository repo) {
                    if (repo != null) {
                        CommandDetailView.this.presenter.fetchFiles(view, repo.getUri(), null);
                    } else {
                        view.show(new ArrayList<FileNode>(0), new ArrayList<FileNode>(0));
                    }

                }

                /* (non-Javadoc)
                 * @see n3phele.client.widgets.FileNodeBrowser.BrowserPresenter#hide()
                 */
                @Override
                public void hide() {
                    popup.hide();
                }

                /* (non-Javadoc)
                 * @see n3phele.client.widgets.FileNodeBrowser.BrowserPresenter#save(java.lang.String)
                 */
                @Override
                public void save(String repoURI, String filename) {
                    fileSpecification.setFilename(filename);
                    fileSpecification.setRepository(repoURI);
                    if (isInput)
                        inputTable.redraw();
                    else
                        outputTable.redraw();
                    updateRunButton(true);
                    CommandDetailView.this.lastRepo = repoURI;
                    CommandDetailView.this.lastPath = getPath(filename);
                    popup.hide();
                }

                /* (non-Javadoc)
                 * @see n3phele.client.widgets.FileNodeBrowser.BrowserPresenter#validate(java.lang.String)
                 */
                @Override
                public boolean validate(String repoURI, String filename) {
                    if (!isInput) {
                        return repoURI == null
                                || (repoURI != null && filename != null && filename.trim().length() != 0);
                    }

                    CommandDetailView.this.presenter.checkExists(view, repoURI, filename);
                    return false;
                }

                @Override
                public void addPlaceholder(FileNode folder) {
                    if (CommandDetailView.this.presenter != null) {
                        CommandDetailView.this.presenter.addPlaceholder(view, folder);
                    }
                }

            }, isInput);
            presenter.setView(view);
            view.setRepos(CommandDetailView.this.repos, !isInput || fileSpecification.isOptional());
            if ((CommandDetailView.this.repos != null && CommandDetailView.this.repos.size() > 0)
                    && (isInput || !isNullOrBlank(fileSpecification.getRepository()))) {
                if (isNullOrBlank(fileSpecification.getRepository())) {
                    if (CommandDetailView.this.lastRepo != null) {
                        CommandDetailView.this.presenter.fetchFiles(view, CommandDetailView.this.lastRepo,
                                CommandDetailView.this.lastPath);
                    } else {
                        CommandDetailView.this.presenter.fetchFiles(view,
                                CommandDetailView.this.repos.get(0).getUri(),
                                getPath(fileSpecification.getFilename()));
                    }
                } else {
                    CommandDetailView.this.presenter.fetchFiles(view, fileSpecification.getRepository(),
                            getPath(fileSpecification.getFilename()));
                }
            } else {
                if (CommandDetailView.this.lastRepo != null) {
                    CommandDetailView.this.presenter.fetchFiles(view, CommandDetailView.this.lastRepo,
                            CommandDetailView.this.lastPath);
                } else {
                    view.show(new ArrayList<FileNode>(0), new ArrayList<FileNode>(0));
                }

            }
            view.setFilename(
                    isNullOrBlank(fileSpecification.getFilename()) ? getFilename(fileSpecification.getName())
                            : getFilename(fileSpecification.getFilename()),
                    !isInput && fileSpecification.getName().endsWith(".zip"),
                    !isInput || fileSpecification.isOptional());
            popup.add(view);
            popup.center();

        }
    }, isInput ? "browse repository to select input file"
            : "browse repository to select output file location and name",
            isInput ? "select file" : "save as..");

    HasCell<FileSpecification, String> repoHasCell = new HasCell<FileSpecification, String>() {

        @Override
        public Cell<String> getCell() {
            return repo;
        }

        @Override
        public FieldUpdater<FileSpecification, String> getFieldUpdater() {
            return new FieldUpdater<FileSpecification, String>() {

                @Override
                public void update(int index, FileSpecification object, String value) {
                }
            };
        }

        @Override
        public String getValue(FileSpecification object) {
            Repository r = CommandDetailView.this.uriToRepoMap.get(object.getRepository());
            if (r != null && r.getName() != null)
                return r.getName();
            else
                return "";
        }
    };

    HasCell<FileSpecification, String> pathHasCell = new HasCell<FileSpecification, String>() {

        @Override
        public Cell<String> getCell() {
            return path;
        }

        @Override
        public FieldUpdater<FileSpecification, String> getFieldUpdater() {
            return new FieldUpdater<FileSpecification, String>() {
                @Override
                public void update(int index, FileSpecification object, String value) {
                }
            };
        }

        @Override
        public String getValue(FileSpecification object) {
            return object.getFilename();
        }

    };
    HasCell<FileSpecification, String> validHasCell = new HasCell<FileSpecification, String>() {

        @Override
        public Cell<String> getCell() {
            return valid;
        }

        @Override
        public FieldUpdater<FileSpecification, String> getFieldUpdater() {
            return new FieldUpdater<FileSpecification, String>() {
                @Override
                public void update(int index, FileSpecification object, String value) {
                }
            };
        }

        @Override
        public String getValue(FileSpecification object) {
            String text;
            if (isInput && !object.isOptional()) {
                text = "Repository name and file required";
            } else {
                text = "Repository name and file required";
            }
            boolean gotRepo = false;
            boolean gotPath = false;
            if (object != null) {
                gotRepo = !isNullOrBlank(object.getRepository());
                gotPath = !isNullOrBlank(object.getFilename());
            }
            boolean visible;
            if (gotRepo || gotPath) {
                visible = !(gotRepo && gotPath);
            } else {
                visible = isInput && !object.isOptional();
            }
            return (visible ? "+" : "-") + text;
        }

    };

    HasCell<FileSpecification, FileSpecification> browseHasCell = new HasCell<FileSpecification, FileSpecification>() {

        @Override
        public Cell<FileSpecification> getCell() {
            return browse;
        }

        @Override
        public FieldUpdater<FileSpecification, FileSpecification> getFieldUpdater() {
            return new FieldUpdater<FileSpecification, FileSpecification>() {
                @Override
                public void update(int index, FileSpecification object, FileSpecification value) {
                }
            };
        }

        @Override
        public FileSpecification getValue(FileSpecification object) {
            return object;
        }

    };

    List<HasCell<FileSpecification, ?>> arg = new ArrayList<HasCell<FileSpecification, ?>>(4);
    arg.add(validHasCell);
    arg.add(repoHasCell);

    arg.add(pathHasCell);
    arg.add(browseHasCell);

    return new CompositeCell<FileSpecification>(arg /*, isInput, /*repoRoot, options*/);
}

From source file:n3phele.client.view.CommandListGridView.java

License:Open Source License

public CommandListGridView() {
    super(new MenuItem(N3phele.n3pheleResource.commandIcon(), "Commands", null));
    String html = "<img style='border:none; vertical-align:bottom; margin:-2px; padding-right:2px;' width=20 height=20 src='"
            + N3phele.n3pheleResource.commandIcon().getURL() + "'/>create a new command";
    Button addDataSet = new Button(html, new ClickHandler() {

        @Override/*from   w w w .ja v a 2  s  .  c  om*/
        public void onClick(ClickEvent event) {
            createUploadPopup();
        }
    });
    addDataSet.setStyleName(N3phele.n3pheleResource.css().newCommandButton());
    this.strip.add(addDataSet);
    HorizontalPanel heading = new HorizontalPanel();
    heading.setWidth("500px");
    heading.setStyleName(N3phele.n3pheleResource.css().sectionPanelHeader());
    add(heading);
    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    simplePager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
    heading.add(simplePager);

    textBox = new TextBox();
    textBox.setTitle("search for a command");
    heading.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    heading.add(textBox);
    heading.setCellHorizontalAlignment(textBox, HorizontalPanel.ALIGN_RIGHT);
    textBox.addKeyPressHandler(new KeyPressHandler() {
        public void onKeyPress(KeyPressEvent event) {
            if (KeyCodes.KEY_ENTER == event.getNativeEvent().getKeyCode()) {
                commandActivity.fetch(0, searchText = textBox.getText(), !allVersions.getValue());
            }
        }
    });

    Image searchIcon = new Image(N3phele.n3pheleResource.searchIcon().getURL());
    searchIcon.setPixelSize(20, 20);
    PushButton search = new PushButton(searchIcon);
    search.setTitle("search for a command");
    search.setStyleName(N3phele.n3pheleResource.css().commandSearchButton());
    heading.add(search);
    search.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            commandActivity.fetch(0, searchText = textBox.getText(), !allVersions.getValue());

        }
    });

    heading.setCellHorizontalAlignment(simplePager, HorizontalPanel.ALIGN_CENTER);
    DisclosurePanel more = new DisclosurePanel("advanced");
    more.setStyleName(N3phele.n3pheleResource.css().sectionPanelHeader());
    heading.add(more);
    heading.setCellHorizontalAlignment(more, HorizontalPanel.ALIGN_LEFT);
    HorizontalPanel disclosed = new HorizontalPanel();
    more.add(disclosed);
    disclosed.add(new InlineLabel("Search all versions"));

    allVersions = new SimpleCheckBox();
    allVersions.setName("allVersions");
    allVersions.setFormValue("Search all versions");
    disclosed.add(allVersions);

    grid = new CellTable<List<Command>>();
    grid.setWidth("100%", true);
    HasCell<Command, ?> nameHasCell = new HasCell<Command, Command>() {

        @Override
        public Cell<Command> getCell() {
            return new CommandTextCell(CommandNameRenderer.getInstance());
        }

        @Override
        public FieldUpdater<Command, Command> getFieldUpdater() {
            return new FieldUpdater<Command, Command>() {

                @Override
                public void update(int index, Command object, Command value) {
                    //                  if(value != null) {
                    //                     GWT.log("got-139 "+index+" "+value.getName());
                    //                     commandActivity.goTo(new CommandPlace(value.getUri()));
                    //                  }

                }
            };
        }

        @Override
        public Command getValue(Command object) {
            return object;
        }

    };
    HasCell<Command, ?> versionHasCell = new HasCell<Command, Command>() {

        @Override
        public Cell<Command> getCell() {
            return new CommandTextCell(CommandVersionRenderer.getInstance());
        }

        @Override
        public FieldUpdater<Command, Command> getFieldUpdater() {
            return new FieldUpdater<Command, Command>() {

                @Override
                public void update(int index, Command object, Command value) {
                    //                  if(value != null) {
                    //                     GWT.log("got-166 "+index+" "+value.getName());
                    //                     commandActivity.goTo(new CommandPlace(value.getUri()));
                    //                  }

                }
            };
        }

        @Override
        public Command getValue(Command object) {
            return object;
        }

    };

    List<HasCell<Command, ?>> hasCells = new ArrayList<HasCell<Command, ?>>(2);
    hasCells.add(nameHasCell);
    hasCells.add(versionHasCell);
    for (int i = 0; i < ROWLENGTH; i++) {
        Column<List<Command>, Command> c = new Column<List<Command>, Command>(new CommandIconTextCell(
                N3phele.n3pheleResource.scriptIcon(), new CompositeCell<Command>(hasCells), i)) {

            @Override
            public Command getValue(List<Command> object) {
                int index = ((CommandIconTextCell) this.getCell()).getIndex();
                if (index < object.size()) {
                    return object.get(index);
                } else {
                    return null;
                }
            }
        };
        c.setFieldUpdater(new FieldUpdater<List<Command>, Command>() {

            @Override
            public void update(int index, List<Command> object, Command value) {
                if (value != null) {
                    GWT.log("got-201 " + index + " " + value.getName());
                    commandActivity.goTo(new CommandPlace(value.getUri()));
                }

            }
        });
        grid.addColumn(c);
        grid.setColumnWidth(c, 100.0 / ROWLENGTH, Unit.PCT);
    }

    grid.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);
    simplePager.setDisplay(grid);
    simplePager.setPageSize(PAGESIZE);
    grid.addRangeChangeHandler(new RangeChangeEvent.Handler() {

        /* (non-Javadoc)
         * @see com.google.gwt.view.client.RangeChangeEvent.Handler#onRangeChange(com.google.gwt.view.client.RangeChangeEvent)
         */
        @Override
        public void onRangeChange(RangeChangeEvent event) {
            if (suppressEvent)
                return;
            Range range = grid.getVisibleRange();
            GWT.log("Table range is " + range.getStart() + " length " + range.getLength());
            int start = range.getStart();
            if (start > total)
                start = total;
            //            if(data == null || (data.size() < start) ){

            commandActivity.fetch(start, searchText, !allVersions.getValue());
            //            } else {
            //               if(length+start > data.size())
            //                  length = data.size()-start;
            //               GWT.log("data available start="+start);
            //               grid.setRowData(start, chunk(data.subList(start, start+length)));
            //            }
        }

    });
    this.add(grid);
}