All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.iwes.widgets.pattern.widget.multiselect.PatternMultiselectData Maven / Gradle / Ivy

The newest version!
/**
 * Copyright 2014-2018 Fraunhofer-Gesellschaft zur Förderung der angewandten Wissenschaften e.V.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.iwes.widgets.pattern.widget.multiselect;

import java.util.Collections;
import java.util.List;

import org.json.JSONObject;
import org.ogema.core.resourcemanager.AccessPriority;
import org.ogema.core.resourcemanager.pattern.ResourcePattern;
import org.ogema.core.resourcemanager.pattern.ResourcePatternAccess;

import de.iwes.widgets.api.extended.mode.UpdateMode;
import de.iwes.widgets.api.extended.pattern.PatternWidgetData;
import de.iwes.widgets.api.widgets.sessionmanagement.OgemaHttpRequest;
import de.iwes.widgets.html.multiselect.TemplateMultiselectData;

public class PatternMultiselectData

> extends TemplateMultiselectData

implements PatternWidgetData

{ protected final ResourcePatternAccess rpa; // Map // private final Map selected = new HashMap(); // either resourceType or resources can / must be != null protected volatile Class patternType = null; public PatternMultiselectData(PatternMultiselect

multiselect, ResourcePatternAccess rpa) { super(multiselect); this.rpa = rpa; } @Override public JSONObject retrieveGETData(OgemaHttpRequest req) { if (getUpdateMode() == UpdateMode.AUTO_ON_GET) { writeLock(); try { updateOnGet(); } finally { writeUnlock(); } } return super.retrieveGETData(req); } // in parent // @Override // public String onPOST(String json, OgemaHttpRequest req) { // String result = super.onPOST(json, req); // Collection selected = getSelectedValues(); // Iterator it = this.selected.keySet().iterator(); // while (it.hasNext()) { // String oldSel = it.next(); // if (!selected.contains(oldSel)) // it.remove(); // } // for (String newSel: selected) { // if (!this.selected.containsKey(newSel)) { // R res = ra.getResource(newSel); // if (res != null) { // this.selected.put(newSel, res); // } // else { // LoggerFactory.getLogger(getClass()).error("Selected value does not correspond to resource"); // may happen in case of race conditions? // } // } // } // // return result; // } public void setType(Class type) { this.patternType = type; } public Class getType() { return this.patternType; } protected void updateOnGet() { List resources; if (patternType == null) { resources = Collections.emptyList(); } else { resources = rpa.getPatterns(patternType, AccessPriority.PRIO_LOWEST); } update(resources); } @SuppressWarnings("unchecked") protected UpdateMode getUpdateMode() { return ((PatternMultiselect

) widget).updateMode; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy