dpfmanager.shell.interfaces.gui.component.config.ConfigModel Maven / Gradle / Ivy
/**
* ConfigModel.java
This program is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any later version; or,
* at your choice, under the terms of the Mozilla Public License, v. 2.0. SPDX GPL-3.0+ or MPL-2.0+.
*
This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License and the Mozilla Public License for more details.
* You should have received a copy of the GNU General Public License and the Mozilla Public
* License along with this program. If not, see http://www.gnu.org/licenses/
* and at http://mozilla.org/MPL/2.0 .
NB: for the
* © statement, include Easy Innova SL or other company/Person contributing the code.
©
* 2015 Easy Innova, SL
*
* @author Adria Llorens
* @version 1.0
* @since 23/7/2015
*/
package dpfmanager.shell.interfaces.gui.component.config;
import dpfmanager.conformancechecker.configuration.Configuration;
import dpfmanager.conformancechecker.tiff.TiffConformanceChecker;
import dpfmanager.shell.core.DPFManagerProperties;
import dpfmanager.shell.core.config.BasicConfig;
import dpfmanager.shell.core.mvc.DpfModel;
import dpfmanager.shell.modules.messages.messages.AlertMessage;
import com.easyinnova.policy_checker.model.Field;
import java.util.ArrayList;
/**
* Created by Adria Llorens on 07/03/2016.
*/
public class ConfigModel extends DpfModel {
private Configuration config;
private boolean editingConfig;
private int step;
private String path;
//User Interface
private int uniqueId;
private TiffConformanceChecker conformance;
public ConfigModel() {
// init vars
conformance = new TiffConformanceChecker(null, null);
config = new Configuration();
editingConfig = false;
step = 0;
uniqueId = 0;
}
public void initNewConfig(){
// Trigger when "New" button clicked
step = 0;
editingConfig = false;
config = new Configuration();
config.initDefault();
path = null;
}
public void initEditConfig(String p){
// Trigger when "Edit" button clicked
step = 0;
path = p;
editingConfig = true;
config = readCheckConfig(path);
if (config == null) {
path = null;
editingConfig = false;
config = new Configuration();
config.initDefault();
getContext().send(BasicConfig.MODULE_MESSAGE, new AlertMessage(AlertMessage.Type.ALERT, getBundle().getString("readConfigFail"), getBundle().getString("startingNew")));
}
}
private Configuration readCheckConfig(String path) {
try {
Configuration configuration = new Configuration();
if (path != null && !path.isEmpty()) {
if (!path.contains("/") && !path.contains("\\")) {
// Read from configurations folder
String pathAux = DPFManagerProperties.getConfigDir() + "/" + path + ".dpf";
configuration.ReadFileNew(pathAux);
} else {
// Read from specified file
configuration.ReadFileNew(path);
}
} else {
// Read from jar (default default configuration)
configuration.ReadFileNew(DPFManagerProperties.getDefaultBuiltInConfig());
}
return configuration;
} catch (Exception e) {
return null;
}
}
public void saveConfig(String filename) throws Exception {
config.SaveFile(filename);
}
public boolean isEditing() {
return editingConfig;
}
public Configuration getConfiguration() {
return config;
}
public void setConfigStep(int x) {
step = x;
}
public int getConfigStep() {
return step;
}
public int getNextId(){
int x = uniqueId;
uniqueId++;
return x;
}
public ArrayList getFields() {
return conformance.getConformanceCheckerFields();
}
public String getFieldToolTip(String field) {
for (Field f : conformance.getConformanceCheckerFields()) {
if (f.getName().equals(field)) {
return f.getDescription();
}
}
return field;
}
public ArrayList getFixes() {
ArrayList fixes = new ArrayList<>();
fixes.add("removeTag");
fixes.add("addTag");
return fixes;
}
public ArrayList getFixFields() {
ArrayList fields = new ArrayList<>();
fields.add("ImageDescription");
fields.add("Copyright");
fields.add("Artist");
fields.add("DateTime");
fields.add("Software");
fields.add("Make");
fields.add("Model");
return fields;
}
public ArrayList getOperators(String name){
for (Field field : getFields()) {
if (field.getName().equals(name)) {
return field.getOperators();
}
}
return new ArrayList<>();
}
public ArrayList getValues(String name){
for (Field field : getFields()) {
if (field.getName().equals(name)) {
return field.getValues();
}
}
return new ArrayList<>();
}
public String getPath() {
return path;
}
}