Dépôt officiel du code source de l'ERP OpenConcerto
Blame | Last modification | View Log | RSS feed
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.erp.rights;
import org.openconcerto.erp.core.supplychain.stock.element.DepotStockSQLElement;
import org.openconcerto.sql.element.SQLElementDirectory;
import org.openconcerto.sql.model.DBRoot;
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
import org.openconcerto.sql.users.rights.RightEditor;
import org.openconcerto.sql.users.rights.RightEditorManager;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.JComponent;
import javax.swing.JTextField;
public class DepotStockViewRightEditor implements RightEditor {
public static final String ID_RIGHT = "DEPOT_STOCK_VIEW";
@Override
public void setValue(final String object, final DBRoot root, final SQLElementDirectory directory, final JComponent editorComponent) {
if (object != null && object.trim().length() > 0) {
((SQLRequestComboBox) editorComponent).setValue(Integer.valueOf(object));
} else {
((SQLRequestComboBox) editorComponent).setValue(directory.getElement(DepotStockSQLElement.class).getTable().getUndefinedID());
}
}
@Override
public JComponent getRightEditor(final String right, final DBRoot root, final SQLElementDirectory directory, final JTextField fieldObject) {
final SQLRequestComboBox box = new SQLRequestComboBox();
box.uiInit(directory.getElement(DepotStockSQLElement.class).getComboRequest());
box.addModelListener("wantedID", new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
int id = box.getWantedID();
fieldObject.setText(String.valueOf(id));
}
});
return box;
}
public static void register() {
RightEditorManager.getInstance().register(ID_RIGHT, new DepotStockViewRightEditor());
}
}