Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (C) 2008-2012 AgroSense Foundation.
*
* AgroSense 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.
*
* There are special exceptions to the terms and conditions of the GPLv3 as it is applied to
* this software, see the FLOSS License Exception
* .
*
* AgroSense 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with AgroSense. If not, see .
*/
package nl.cloudfarming.client.fleet.machine.windows;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
import nl.cloudfarming.client.fleet.machine.MachineDataService;
import nl.cloudfarming.client.fleet.machine.MachineDataService.Model;
import nl.cloudfarming.client.fleet.model.Machine;
import nl.cloudfarming.client.fleet.model.MachineProvider;
import nl.cloudfarming.client.util.swing.beanbinding.NonEmptyStringValidator;
import nl.cloudfarming.client.util.swing.beanbinding.ToStringNotEmptyValidator;
import org.jdesktop.beansbinding.*;
import org.netbeans.api.project.Project;
import org.openide.util.NbBundle;
/**
*
* @author Merijn Zengers
*/
@NbBundle.Messages({"MachineOverviewController custom value combox text=Custom",
"MachineOverviewController empty name error message=Name can not be empty",
"MachineOverviewController name exists error message=Name already exists",
"MachineOverviewController empty type error message=No type selected",
"MachineOverviewController empty brand error message=No brand selected",
"MachineOverviewController empty model error message=No model selected"})
public abstract class MachineOverviewController {
private CustomItemString customValue = new CustomItemString();
private Machine machine;
private E machineOverviewPanel;
private Collection extends MachineDataService> dataServices;
public MachineOverviewController(E machineOverviewPanel, Machine machine, Collection extends MachineDataService> dataServices) {
this.machine = machine;
this.machineOverviewPanel = machineOverviewPanel;
this.dataServices = dataServices;
initComboxValues();
bind();
addListeners();
}
/**
* fills the type combobox
*/
private void initComboxValues() {
//Deactivate custom rows
machineOverviewPanel.deactivateCustomBrandInput();
machineOverviewPanel.deactivateCustomModelNumberInput();
//fill the type combo box
Set types = new TreeSet<>();
ModelIterator modelIterator = new ModelIterator();
while (modelIterator.hasNext()) {
MachineDataService.Model model = modelIterator.next();
types.add(model.getType());
}
if (types.size() > 1) {
types.add("");
}
machineOverviewPanel.setTypes(types.toArray());
//Fill the brand combo box or custom value or leave it empty for new machines
String brand = machine.getBrand();
if (brand != null) {
updateBrands();
if (isCustomBrandValue(brand)) {
machineOverviewPanel.getBrandCombobox().setSelectedItem(customValue);
machineOverviewPanel.activateCustomBrandInput();
} else {
machineOverviewPanel.getBrandCombobox().setSelectedItem(brand);
}
}
//Fill the model number combo box or custom value. Or leave it empty for new machines
String modelNumber = machine.getModelNumber();
if (modelNumber != null) {
updateModelNumbers();
if (isCustomModelNumberValue(modelNumber)) {
machineOverviewPanel.getModelNumberCombobox().setSelectedItem(customValue);
machineOverviewPanel.activateCustomModelNumberInput();
} else {
machineOverviewPanel.getModelNumberCombobox().setSelectedItem(modelNumber);
}
}
}
/**
* Checks if the value in that is saved as brand is a custom value or a
* predefined one
*/
boolean isCustomBrandValue(String brand) {
ModelIterator modelIterator = new ModelIterator();
while (modelIterator.hasNext()) {
MachineDataService.Model model = modelIterator.next();
if (model.getBrand().equals(brand)) {
return false;
}
}
return true;
}
boolean isCustomModelNumberValue(String modelNumber) {
ModelIterator modelIterator = new ModelIterator();
while (modelIterator.hasNext()) {
MachineDataService.Model model = modelIterator.next();
if (model.getModelNumber().equals(modelNumber)) {
return false;
}
}
return true;
}
/**
* Update the brands combobox
*/
void updateBrands() {
String selectedModelNumber = machineOverviewPanel.getModelNumberValue();
Set