@Override public void removeItem(T item) { checkNotNullArgument(item, "item is null"); backgroundWorker.checkUIAccess(); checkState(); if (this.item != null && this.item.equals(item)) { setItem(null); } data.remove(item.getId()); detachListener(item); deleted(item); fireCollectionChanged(Operation.REMOVE, Collections.singletonList(item)); }
savedParameters = parameters; invalidate(); valid(); fireStateChanged(prevState); setItem(getItem()); doSort(); fireCollectionChanged(Operation.REFRESH, Collections.emptyList()); Collection prevIds = beforeRefresh(parameters); loadData(parameters); afterRefresh(parameters, prevIds); } finally { inRefresh = false;
protected void internalIncludeItem(T item, Runnable addToData) { backgroundWorker.checkUIAccess(); checkStateBeforeAdd(); addToData.run(); attachListener(item); fireCollectionChanged(Operation.ADD, Collections.singletonList(item)); }
protected void internalAddItem(T item, Runnable addToData) { checkNotNullArgument(item, "item is null"); backgroundWorker.checkUIAccess(); checkStateBeforeAdd(); addToData.run(); attachListener(item); modified(item); fireCollectionChanged(Operation.ADD, Collections.singletonList(item)); }
@Override public void updateItem(T item) { checkNotNullArgument(item, "item is null"); backgroundWorker.checkUIAccess(); checkState(); if (this.item != null && this.item.equals(item)) { T prevItem = item; this.item = item; fireItemChanged(prevItem); } if (data.containsKey(item.getId())) { data.put(item.getId(), item); attachListener(item); fireCollectionChanged(Operation.UPDATE, Collections.singletonList(item)); } }
/** * Load data from middleware into {@link #data} field. * <p>In case of error sets {@link #dataLoadError} field to the exception object.</p> * @param params datasource parameters, as described in {@link CollectionDatasource#refresh(java.util.Map)} */ protected void loadData(Map<String, Object> params) { Security security = AppBeans.get(Security.NAME); if (!security.isEntityOpPermitted(metaClass, EntityOp.READ)) { return; } String tag = getLoggingTag("CDS"); StopWatch sw = new Slf4JStopWatch(tag, LoggerFactory.getLogger(UIPerformanceLogger.class)); if (needLoading()) { LoadContext context = beforeLoadData(params); if (context == null) { return; } try { Collection<T> entities = dataSupplier.loadList(context); afterLoadData(params, context, entities); } catch (Throwable e) { dataLoadError = e; } } sw.stop(); }
public Filter createFakeFilter() { if (filter != null) { return filter; } Filter fakeFilter = AppBeans.get(ComponentsFactory.NAME, ComponentsFactory.class).createComponent(Filter.class); ((HasXmlDescriptor) fakeFilter).setXmlDescriptor(Dom4j.readDocument("<filter/>").getRootElement()); CollectionDatasourceImpl fakeDatasource = new CollectionDatasourceImpl(); LegacyFrame legacyFrame = (LegacyFrame) this.frameOwner; DsContextImpl fakeDsContext = new DsContextImpl(legacyFrame.getDsContext().getDataSupplier()); FrameContextImpl fakeFrameContext = new FrameContextImpl((Frame) legacyFrame); fakeDsContext.setFrameContext(fakeFrameContext); fakeDatasource.setDsContext(fakeDsContext); //Attention: this query should match the logic in com.haulmont.reports.wizard.ReportingWizardBean.createJpqlDataSet() fakeDatasource.setQuery("select queryEntity from " + metaClass.getName() + " queryEntity"); fakeDatasource.setMetaClass(metaClass); fakeFilter.setDatasource(fakeDatasource); fakeFilter.setFrame(UiControllerUtils.getFrame(frameOwner)); return fakeFilter; }
/** * This method is invoked by {@link #loadData(Map)} method immediately after loading entities from {@code DataSupplier}. * <p>If you override this method, be sure to call {@code super()}. If you process the loaded entities somehow, * call {@code super()} after processing. * * @param params datasource parameters, as described in {@link CollectionDatasource#refresh(java.util.Map)} * @param context {@code LoadContext} which was used for loading data * @param entities loaded entities */ protected void afterLoadData(@SuppressWarnings("unused") Map<String, Object> params, LoadContext context, Collection<T> entities) { detachListener(data.values()); data.clear(); for (T entity : entities) { data.put(entity.getId(), entity); attachListener(entity); } lastQuery = context.getQuery(); }
@Override public void clear() { super.clear(); id2Thread.clear(); prevThread2CpuTime.clear(); }
@Override public void deleted(ThreadSnapshot item) { super.deleted(item); id2Thread.remove(item.getThreadId()); prevThread2CpuTime.remove(item.getThreadId()); }
@Override protected void loadData(Map<String, Object> params) { UserSession userSession = AppBeans.get(UserSessionSource.class).getUserSession(); User user; if (userSession.getSubstitutedUser() != null) { user = userSession.getSubstitutedUser(); } else { user = userSession.getUser(); } Map<String, Object> modifiedParams = new HashMap<>(params); modifiedParams.put("userId", user.getId()); super.loadData(modifiedParams); } }
protected CollectionDatasource createCollectionDatasource() { return new CollectionDatasourceImpl(); }
@Override public void addItem(KeyValueEntity item) { super.addItem(item); item.setMetaClass(metaClass); }
protected void afterLoadValues(Map<String, Object> params, ValueLoadContext context, List<KeyValueEntity> entities) { ds.detachListener(ds.data.values()); ds.data.clear(); boolean hasEnumerations = ds.metaClass.getOwnProperties().stream() .anyMatch(p -> p.getRange().isEnum()); if (!hasEnumerations) { for (KeyValueEntity entity : entities) { ds.data.put(entity.getId(), entity); ds.attachListener(entity); entity.setMetaClass(ds.metaClass); } } else { List<MetaProperty> enumProperties = getEnumProperties(ds.metaClass); for (KeyValueEntity entity : entities) { convertEnumValues(entity, enumProperties); ds.data.put(entity.getId(), entity); ds.attachListener(entity); entity.setMetaClass(ds.metaClass); } } }
protected void initRuntimePropertiesDatasources(View view) { rDS = new RuntimePropsDatasourceImpl(dsContext, dataSupplier, "rDS", datasource.getId(), null); MetaClass categoriesMeta = metadata.getSession().getClass(Category.class); categoriesDs = new CollectionDatasourceImpl(); ViewProperty categoryProperty = view.getProperty("category"); if (categoryProperty == null) { throw new IllegalArgumentException("Category property not found. Not a categorized entity?"); } categoriesDs.setup(dsContext, dataSupplier, "categoriesDs", categoriesMeta, categoryProperty.getView()); categoriesDs.setQuery(String.format("select c from sys$Category c where c.entityType='%s'", meta.getName())); categoriesDs.refresh(); dsContext.register(rDS); dsContext.register(categoriesDs); }