List of usage examples for com.google.gwt.user.client Element getId
@Override
public String getId()
From source file:org.geomajas.gwt.client.gfx.context.DomHelper.java
License:Open Source License
/** * Move an element from on group to another. The elements name will remain the same. * //from w w w . j av a 2 s . c o m * @param name * The name of the element within the sourceParent group. * @param sourceParent * The original parent group of the element. * @param targetParent * The target parent group for the element. * @return true when move was successful */ public boolean moveElement(String name, Object sourceParent, Object targetParent) { Element sourceGroup = null; Element targetGroup = null; Element element = null; if (sourceParent != null) { sourceGroup = getGroup(sourceParent); element = getElement(sourceParent, name); } if (targetParent != null) { targetGroup = getGroup(targetParent); } if (sourceGroup == null || targetGroup == null) { return false; } if (Dom.isOrHasChild(sourceGroup, element)) { Dom.removeChild(sourceGroup, element); String newId = Dom.assembleId(targetGroup.getId(), name); elementToName.remove(element.getId()); elementToName.put(newId, name); Dom.setElementAttribute(element, "id", newId); Dom.appendChild(targetGroup, element); return true; } return false; }
From source file:org.geomajas.gwt.client.gfx.context.DomHelper.java
License:Open Source License
/** * Generic creation method for non-group elements. * /*from www. ja v a2s . com*/ * @param parent * the parent group * @param name * local group name of the element (should be unique within the group) * @param type * the type of the element (tag name, e.g. 'image') * @param style * The style to apply on the element. * @param generateId * true if a unique id may be generated, otherwise the name will be used as id * @return the newly created element or null if creation failed or the name was null */ protected Element createElement(Object parent, String name, String type, Style style, boolean generateId) { if (null == name) { return null; } Element parentElement; if (parent == null) { parentElement = getRootElement(); } else { parentElement = getGroup(parent); } if (parentElement == null) { return null; } else { Element element; String id = generateId ? Dom.assembleId(parentElement.getId(), name) : name; elementToName.put(id, name); switch (namespace) { case SVG: element = Dom.createElementNS(Dom.NS_SVG, type, id); if (style != null) { applyStyle(element, style); } break; case VML: element = Dom.createElementNS(Dom.NS_VML, type, id); Element stroke = Dom.createElementNS(Dom.NS_VML, "stroke"); element.appendChild(stroke); Element fill = Dom.createElementNS(Dom.NS_VML, "fill"); element.appendChild(fill); if ("shape".equals(name)) { // Set the size .....if the parent has a coordsize defined, take it over: String coordsize = parentElement.getAttribute("coordsize"); if (coordsize != null && coordsize.length() > 0) { element.setAttribute("coordsize", coordsize); } } Dom.setStyleAttribute(element, "position", "absolute"); VmlStyleUtil.applyStyle(element, style); break; case HTML: default: element = Dom.createElementNS(Dom.NS_HTML, type, id); if (style != null) { applyStyle(element, style); } } parentElement.appendChild(element); Dom.setElementAttribute(element, "id", id); return element; } }
From source file:org.geomajas.gwt.client.gfx.context.DomHelper.java
License:Open Source License
private void deleteRecursively(Element parent, Element element) { for (int i = element.getChildCount() - 1; i >= 0; i--) { Node node = element.getChild(i); if (node instanceof Element) { deleteRecursively(element, (Element) node); }//from w w w .j a v a 2 s.c om } try { groupToId.remove(element); if (element.getId() != null) { Log.logDebug("Removing element " + element.getId()); elementToName.remove(element.getId()); } if (Dom.getEventListener(element) != null) { Dom.setEventListener(element, null); } Dom.removeChild(parent, element); } catch (Exception e) { Log.logError("Problem during recursive delete of " + element.getId() + " from " + parent.getId() + ", " + e.getMessage()); } }
From source file:org.gk.client.GKEngine.java
License:Open Source License
public void renderElement(Element ele) { String gulSyntax = "<page>" + ele.getInnerHTML() + "</page>"; Element div = DOM.createDiv(); div.setId(ele.getId()); ele.getParentElement().replaceChild(div, ele); if (div.getId().equals("")) { div.setId(DOM.createUniqueId()); }//ww w. j a v a2 s .c om LayoutContainer lc = new LayoutContainer(); lc.setLayout(new FitLayout()); RootPanel.get(div.getId()).add(lc); gk.render(gulSyntax, lc); }
From source file:org.gk.engine.client.Engine.java
License:Open Source License
/** * Grid??Grid?ColumnConfigEngineDataStore * //w ww .j a v a 2 s. c om * @param grid */ private void removeColumnModel(Grid grid) { ColumnModel cm = grid.getColumnModel(); Iterator<ColumnConfig> columnIt = cm.getColumns().iterator(); while (columnIt.hasNext()) { String id = columnIt.next().getId(); removeComponent(id); removeRenderPanelComById(id); } // ??DomQuerygridid_rowIndex com.google.gwt.dom.client.NodeList<Element> nodes = DomQuery.select("*[id*=_]", grid.getElement()); for (int i = 0; i < nodes.getLength(); i++) { Element ele = nodes.getItem(i); removeComponent(ele.getId()); removeRenderPanelComById(ele.getId()); } }
From source file:org.gk.engine.client.event.attrib.ValueAttribute.java
License:Open Source License
@Override public Object getAttributeValue(Component com) { Object value = null;//from ww w .j av a 2s .c om if (com instanceof IC) { value = ((IC) com).getInfo(); } else if (com instanceof gkHtmlContainer) { gkHtmlContainer hc = (gkHtmlContainer) com; value = hc.getHtml(); } else if (com instanceof Field) { Field field = (Field) com; if (field instanceof DateField) { value = DateTimeUtils.getValue((DateField) field); } else if (field instanceof gkTimeField) { value = ((gkTimeField) field).getTimeValue(); } else { value = field.getValue(); } } else if (com instanceof gkButton) { gkButton field = (gkButton) com; value = field.getValue(); } else if (com instanceof LayoutContainer) { // LayoutContainer,Frame?URL // XFrameLayoutContainerFrame ( XFrame) Object obj = ((LayoutContainer) com).getItem(0); if (obj instanceof WidgetComponent && ((WidgetComponent) obj).getWidget() instanceof Frame) { Frame frame = (Frame) ((WidgetComponent) obj).getWidget(); value = frame.getUrl(); } } else { // ???Element?html Element ele = com.getElement(); value = ele.getInnerHTML(); Component g = ComponentManager.get().get(ele.getAttribute("gid")); if (g instanceof Grid) { // ??cellEditor?? String[] param = ele.getId().split("_"); if (param.length != 2) { return value; } String columnName = ((Grid) g).getColumnModel().getColumnById(param[0]).getDataIndex(); int rowIdx = Integer.parseInt(param[1]); ModelData md = (ModelData) ((Grid) g).getStore().getModels().get(rowIdx); value = md.get(columnName); } } return value; }
From source file:org.gk.engine.client.event.attrib.ValueAttribute.java
License:Open Source License
@Override public void setAttributeValue(Component com, Object value) { if (com instanceof IC) { // TreeMap if (com instanceof gkXMLTreePanelIC && value instanceof Map) { TreeUtils.updateSelectNode((gkXMLTreePanelIC) com, (Map) value); } else if (com instanceof gkTreeDirPanelIC && value instanceof Map) { // ????name Map map = (Map) value; assert map.containsKey(gkTreeDirPanelIC.ID) : "can't found nodeId:" + map; String id = map.get(gkTreeDirPanelIC.ID).toString(); if (map.containsKey(gkTreeDirPanelIC.NAME)) { // name?path?? String name = map.get(gkTreeDirPanelIC.NAME).toString(); TreePanel tree = (TreePanel) com; TreeStore store = tree.getStore(); ModelData md = store.findModel(id); ModelData parent = store.getParent(md); int index = store.indexOf(md); gkMap newmd = (gkMap) gkMap.clone((Map) md); String oldPath = md.get(gkTreeDirPanelIC.PATH).toString(); String oldName = md.get(gkTreeDirPanelIC.NAME).toString(); int last = oldPath.lastIndexOf(oldName); String lastPath = oldPath.substring(last); lastPath = lastPath.replace(oldName, name); String newPath = oldPath.substring(0, last) + lastPath; newmd.set(gkTreeDirPanelIC.NAME, name); newmd.set(gkTreeDirPanelIC.PATH, newPath); store.insert(parent, newmd, index, false); store.remove(md);// ww w . j a va 2 s . c o m } } else { ((IC) com).setInfo(value); } } else if (com instanceof gkButton) { gkButton btn = (gkButton) com; btn.setValue((String) value); } else if (com instanceof gkHtmlContainer) { gkHtmlContainer hc = (gkHtmlContainer) com; if (value instanceof Map) { hc.setInfo((Map) value); } else { hc.setHtml((String) value); } } else if (com instanceof LayoutContainer) { String v = (String) value; LayoutContainer lc = (LayoutContainer) com; // LayoutContainer?Frameurl Object obj = lc.getItem(0); if (obj instanceof WidgetComponent && ((WidgetComponent) obj).getWidget() instanceof Frame) { ((Frame) ((WidgetComponent) obj).getWidget()).setUrl(v); } else { Engine.get().renderPanel(v, lc, true); } } else if (com instanceof Field) { Field field = (Field) com; boolean orgFireChange = field.isFireChangeEventOnSetValue(); // field.setFireChangeEventOnSetValue(true); if (field instanceof DateField) { DateTimeUtils.setValue((DateField) field, value + ""); } else if (field instanceof gkTimeField) { ((gkTimeField) field).setTimeValue(value + ""); } else if (field instanceof gkComboBox && value instanceof Map && ((ComboBox) com).getStore().getCount() == 0) { // ????text:valuemap // addstoresetValue ComboBox combo = (ComboBox) com; Map data = (Map) value; combo.getStore().add(new gkMap(data)); combo.getPropertyEditor().setList(combo.getStore().getModels()); field.setValue(value); } else { if (value instanceof String) { field.setValue(field.getPropertyEditor().convertStringValue((String) value)); } else { field.setValue(value); } } field.setFireChangeEventOnSetValue(orgFireChange); // } else { // ???Elementhtml // gidgridModelData Element ele = com.getElement(); ele.setInnerHTML((String) value); // gid????labelField // ?gid?gid,?gid // ??Grid store? String gid = ele.getAttribute("gid"); if (gid == null || gid.equals("")) { gid = ele.getParentElement().getAttribute("gid"); } Component g = ComponentManager.get().get(gid); if (g instanceof Grid) { // ?cellEditor?? String[] param = ele.getId().split("_"); if (param.length != 2) { return; } ListStore ds = ((Grid) g).getStore(); String columnName = ((Grid) g).getColumnModel().getColumnById(param[0]).getDataIndex(); int rowIdx = Integer.parseInt(param[1]); ModelData md = (ModelData) ds.getModels().get(rowIdx); md.set(columnName, value); StoreEvent evt = new StoreEvent(ds); evt.setModel(md); evt.setOperation(RecordUpdate.EDIT); ds.fireEvent(Store.Update, evt); // cellEditor ? Component editorField = ComponentUtils.findComponent(param[0]); if (editorField instanceof Field) { ((Field) editorField).setValue(value); } } } }
From source file:org.spacetimeresearch.gwt.addthis.client.AddThisWidget.java
License:Apache License
/** * Creates the AddThisWidget's id and sets its state. *//*from ww w .ja va 2 s . co m*/ @Override protected void onAttach() { assert this.anchorElement != null : "Anchor element not set"; Element element = this.getElement(); String elementId = element.getId(); if (elementId == null || elementId.isEmpty()) { element.setId(getNextAutoElementId()); } createAddThis(); super.onAttach(); }
From source file:org.talend.mdm.webapp.base.client.widget.ComboBoxEx.java
License:Open Source License
@SuppressWarnings("rawtypes") protected void initList() { if (listView == null) { listView = new ListView<D>(); }/*from w w w .j a v a 2 s. co m*/ String style = listStyle; listView.setStyleAttribute("overflowX", "hidden"); //$NON-NLS-1$ //$NON-NLS-2$ listView.addStyleName(style + "-inner"); //$NON-NLS-1$ listView.setStyleAttribute("padding", "0px"); //$NON-NLS-1$//$NON-NLS-2$ listView.setItemSelector(itemSelector != null ? itemSelector : "." + style + "-item"); //$NON-NLS-1$ //$NON-NLS-2$ listView.setSelectOnOver(true); listView.setBorders(false); listView.setLoadingText(getMessages().getLoadingText()); listView.getSelectionModel().addListener(Events.SelectionChange, new Listener<SelectionChangedEvent<D>>() { @Override public void handleEvent(SelectionChangedEvent<D> se) { selectedItem = listView.getSelectionModel().getSelectedItem(); if (GXT.isAriaEnabled()) { Element e = listView.getElement(listView.getStore().indexOf(selectedItem)); ComboBoxEx.this.setAriaState("aria-activedescendant", e.getId()); //$NON-NLS-1$ } } }); listView.addListener(Events.Select, new Listener<ListViewEvent<D>>() { @Override public void handleEvent(ListViewEvent<D> le) { onViewClick(le, true); } }); if (template == null) { String html = "<tpl for=\".\"><div role=\"listitem\" class=\"" + style + "-item\" title=\"{" //$NON-NLS-1$//$NON-NLS-2$ + getDisplayField() + "}\">{" + getDisplayField() //$NON-NLS-1$ + "}</div></tpl>"; //$NON-NLS-1$ template = XTemplate.create(html); } if (pageTb != null) { pageTb.bind((PagingLoader) store.getLoader()); } list = new LayoutContainer() { @Override protected void doAttachChildren() { super.doAttachChildren(); ComponentHelper.doAttach(ComboBoxEx.this.pageTb); } @Override protected void doDetachChildren() { super.doDetachChildren(); ComponentHelper.doDetach(ComboBoxEx.this.pageTb); } @Override protected void onRender(Element parent, int index) { super.onRender(parent, index); eventPreview.getIgnoreList().add(getElement()); if (pageTb != null) { footer = list.el().createChild("<div class='" + listStyle + "-ft'></div>"); //$NON-NLS-1$ //$NON-NLS-2$ pageTb.setBorders(false); pageTb.render(footer.dom); } } }; list.setScrollMode(Scroll.NONE); list.setShim(true); list.setShadow(true); list.setBorders(true); list.setStyleName(style); list.hide(); list.addStyleName("x-ignore"); //$NON-NLS-1$ assert store != null : "ComboBox needs a store"; //$NON-NLS-1$ list.add(listView); listView.setTemplate(template); listView.setSelectStyle(selectedStyle); bindStore(store); if (!lazyRender) { createList(true); } }
From source file:org.xwiki.gwt.wysiwyg.client.plugin.sync.SyncPlugin.java
License:Open Source License
private void removeCursor(Document doc) { try {//w ww . j a v a2 s . co m Node cursorNode = null; NodeList list = doc.getElementsByTagName("span"); for (int i = 0; i < list.getLength(); i++) { Element element = (Element) list.getItem(i); if (element.getId().equals("cursor-" + id)) { cursorNode = element; } } if (cursorNode != null) { debugMessage("found cursor element"); Node firstNode = null; Node lastNode = null; Node pNode = cursorNode; NodeList childs = cursorNode.getChildNodes(); // readd all childs of the cursor to the left of the cursor node int nb = childs.getLength(); for (int i = nb - 1; i >= 0; i--) { Node node = childs.getItem(i); if (i == 0) { firstNode = node; } if (i == nb - 1) { lastNode = node; } // we want to insert the node in it's parent before the cursor Node cursorNode.removeChild(node); cursorNode.getParentNode().insertBefore(node, pNode); pNode = node; } // remove the cursor node itself Node previousNode = cursorNode.getPreviousSibling(); debugMessage("removing cursor node"); cursorNode.getParentNode().removeChild(cursorNode); debugMessage("creating new range"); Range range = RangeFactory.INSTANCE.createRange(doc); if (firstNode != null) { debugMessage("set range with first node and last node"); range.setStartBefore(firstNode); range.setEndAfter(lastNode); } else if (previousNode != null) { debugMessage("set range with previous node"); Node nextNode = previousNode.getNextSibling(); if (nextNode != null) { range.setStart(nextNode, 0); } else { range.setStartAfter(previousNode); range.setEndAfter(previousNode); range.collapse(true); } } doc.getSelection().removeAllRanges(); doc.getSelection().addRange(range); getTextArea().setFocus(true); } else { debugMessage("could not find cursor element"); } } catch (Exception e) { debugMessage("Uncaught exception in insertCursor: " + e.getMessage()); } }