/** * Updates a Widget with the properties which have been defined in the metamodel. This also * updates all the contained Widgets. This is necessary when we try to reload a previously saved * Widget which has since had properties added to or removed from it. * * @param widget The Widget to update */ private boolean updateWidget(Widget widget) { // try { // widgetLock.uiSafeAcquire(false); // } catch (InterruptedException ex) { // ex.printStackTrace(); // return false; // } WidgetType wt = widget.getType(); if (wt == null) { return false; // @see xtext factory } updateProperties(wt.getAllPropertyTypes(), widget.getProperties()); for (Event event : widget.getEvents()) { update(event); } for (Snippet snippet : widget.getSnippets()) { update(snippet); } // Now iterate over the child Widgets for (Widget w : widget.getContents()) { updateWidget(w); } // widgetLock.release(); return true; }
/** * Creates the properties defined in the template and initialises their default values. * * @param type The WidgetType * @return List of Property Objects */ private List<Property> createProperties(WidgetType type) { List<Property> allProperties = new ArrayList<Property>(); for (PropertyType pt : type.getAllPropertyTypes().values()) { Property p = createProperty(pt); allProperties.add(p); } return allProperties; }
@Override public List<Property> filter(Widget widget) { // These are the WidgetType's of the Label and Field MetaModel mm = MetaModelRegistry.getMetaModel(); String library = widget.getLibraryName(); WidgetType wt = mm.findWidgetType(library, widget.getTypeName()); // Add all the PropertyTypes which exist Set<PropertyType> allowedTypes = new HashSet<PropertyType>(); allowedTypes.addAll(wt.getAllPropertyTypes().values()); // hide some properties allowedTypes.remove(mm.findPropertyType(library, PropertyTypeConstants.EDITABLE)); List<Property> result = new ArrayList<Property>(); for (Property p : widget.getProperties()) { if (allowedTypes.contains(p.getType())) { result.add(p); } } return result; }
/** * Creates a Widget without any properties. * * @param type The WidgetType * @return Widget The newly created Widget */ private Widget createEmptyWidget(WidgetType type) { Widget widget = getModelFactory().createWidget(); widget.setTypeName(type.getName()); widget.setLibraryName(type.getLibrary().getName()); return widget; }