Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removing a one or more now updates commodities lists #104

Merged
merged 3 commits into from
Jun 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions cyclist/src/edu/utexas/cycic/Cycic.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@
import edu.utah.sci.cyclist.Cyclist;
import edu.utah.sci.cyclist.core.controller.CyclistController;
import edu.utah.sci.cyclist.core.event.dnd.DnD;
import edu.utah.sci.cyclist.core.event.notification.CyclistNotification;
import edu.utah.sci.cyclist.core.model.CyclusJob;
import edu.utah.sci.cyclist.core.model.CyclusJob.Status;
import edu.utah.sci.cyclist.core.model.Preferences;
import edu.utah.sci.cyclist.core.ui.components.ViewBase;
import edu.utah.sci.cyclist.core.util.AwesomeIcon;
import edu.utah.sci.cyclist.core.util.GlyphRegistry;
import edu.utexas.cycic.presenter.CycicPresenter;

public class Cycic extends ViewBase{
static Logger log = Logger.getLogger(Cycic.class);
Expand Down Expand Up @@ -552,6 +554,7 @@ public void handle(ActionEvent e){
facility.cycicCircle.outcommods.remove(i);
}
}
commodListRm(facility.facilityStructure, facility.facilityData, commod);
}
VisFunctions.redrawPane();
buildCommodPane();
Expand Down Expand Up @@ -907,4 +910,29 @@ private void export() {
}
}

public static void commodListRm(ArrayList<Object> facArray, ArrayList<Object> dataArray, String commod){
if(facArray.get(0) instanceof ArrayList){
for(int i = 0; i < facArray.size(); i++){
commodListRm((ArrayList<Object>) facArray.get(i), (ArrayList<Object>) dataArray.get(i), commod);
}
} else if(facArray.get(1) instanceof ArrayList){
for(int i = 0; i < dataArray.size(); i++){
commodListRm((ArrayList<Object>) facArray.get(1), (ArrayList<Object>) dataArray.get(i), commod);
}
} else {
switch ((String) facArray.get(2).toString().toLowerCase()){
case "incommodity":
if(dataArray.get(0).toString().equalsIgnoreCase(commod)){
dataArray.set(0, "");
}
break;
case "outcommodity":
if(dataArray.get(0).toString().equalsIgnoreCase(commod)){
dataArray.set(0, "");
}
break;
}
}
}

}
1 change: 1 addition & 0 deletions cyclist/src/edu/utexas/cycic/CycicNotifications.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public class CycicNotifications {

public static final String NEW_INSTIT = "new_instit";
public static final String FORM_REDRAW = "form_redraw";

}
39 changes: 38 additions & 1 deletion cyclist/src/edu/utexas/cycic/FormBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@ public void handle(ActionEvent e){
public Button arrayListRemove(final GridPane grid, final ArrayList<Object> dataArray, final int dataArrayNumber, ArrayList<Object> facArray){
Button button = new Button();
button.setText("Remove");
ArrayList<Object> tempData = (ArrayList<Object>) ((ArrayList<Object>) dataArray.get(dataArrayNumber)).get(0);
button.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent e) {
commodRemoval((ArrayList<Object>) facArray.get(1), (ArrayList<Object>) dataArray.get(dataArrayNumber));
VisFunctions.redrawPane();
dataArray.remove(dataArrayNumber);
if(dataArray.size() == 0){
facArray.set(10, false);
Expand All @@ -152,6 +153,42 @@ public void handle(ActionEvent e) {
return button;
}

/**
*
* @param facArray
* @param dataArray
*/
public void commodRemoval(ArrayList<Object> facArray, ArrayList<Object> dataArray){
if(facArray.get(0) instanceof ArrayList){
for(int i = 0; i < facArray.size(); i++){
commodRemoval((ArrayList<Object>) facArray.get(i), (ArrayList<Object>) dataArray.get(i));
}
} else if(facArray.get(1) instanceof ArrayList){
for(int i = 0; i < dataArray.size(); i++){
commodRemoval((ArrayList<Object>) facArray.get(1), (ArrayList<Object>) dataArray.get(i));
}
} else {
switch ((String) facArray.get(2).toString().toLowerCase()){
case "incommodity":
for(int i = 0; i < formNode.cycicCircle.incommods.size(); i++){
if(dataArray.get(0).toString().equalsIgnoreCase(formNode.cycicCircle.incommods.get(i))){
formNode.cycicCircle.incommods.remove(i);
break;
}
}
break;
case "outcommodity":
for(int i = 0; i < formNode.cycicCircle.outcommods.size(); i++){
if(dataArray.get(0).toString().equalsIgnoreCase(formNode.cycicCircle.outcommods.get(i))){
formNode.cycicCircle.outcommods.remove(i);
break;
}
}
break;
}
}
}

/**
* This function builds an input form from the data structures associated
* with a facility.
Expand Down
37 changes: 26 additions & 11 deletions cyclist/src/edu/utexas/cycic/FormBuilderFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,19 @@ static ComboBox<String> comboBoxInCommod(final facilityNode facNode, ArrayList<O
cb.setMinWidth(80);
cb.setOnMousePressed(new EventHandler<MouseEvent>(){
public void handle(MouseEvent e){
for(int i =0; i < facNode.cycicCircle.incommods.size(); i++){
/*for(int i =0; i < facNode.cycicCircle.incommods.size(); i++){
if(facNode.cycicCircle.incommods.get(i) == cb.getValue()){
facNode.cycicCircle.incommods.remove(i);
}
}
}*/
cb.getItems().clear();

for(CommodityNode label: DataArrays.CommoditiesList){
cb.getItems().add(label.name.getText());
}
cb.getItems().add("New Commodity");

if(!defaultValue.get(0).equals("")) {
if(defaultValue.get(0) != null) {
cb.setValue((String) defaultValue.get(0));
}
}
Expand All @@ -304,7 +304,15 @@ public void handle(MouseEvent e){
cb.setPromptText("Select a commodity");
cb.valueProperty().addListener(new ChangeListener<String>(){
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue){
if (newValue == "New Commodity"){
if(newValue == null){
for (int i = 0; i < facNode.cycicCircle.incommods.size(); i++) {
if (facNode.cycicCircle.incommods.get(i) == (String) oldValue){
String string = facNode.cycicCircle.incommods.remove(i);
System.out.println(string);
break;
}
}
} else if (newValue == "New Commodity"){
Cycic.addNewCommodity();
} else {
facNode.cycicCircle.incommods.add(newValue);
Expand All @@ -314,7 +322,7 @@ public void changed(ObservableValue<? extends String> observable, String oldValu
}
for (int i = 0; i < facNode.cycicCircle.incommods.size(); i++) {
if (facNode.cycicCircle.incommods.get(i) == (String) oldValue){
facNode.cycicCircle.incommods.remove(i);
String string = facNode.cycicCircle.incommods.remove(i);
break;
}
}
Expand All @@ -340,18 +348,18 @@ static ComboBox<String> comboBoxOutCommod(final facilityNode facNode, ArrayList<

cb.setOnMousePressed(new EventHandler<MouseEvent>(){
public void handle(MouseEvent e){
for(int i = 0; i < facNode.cycicCircle.outcommods.size(); i++){
if(facNode.cycicCircle.outcommods.get(i) == cb.getValue()){
facNode.cycicCircle.outcommods.remove(i);
}
/*for(int i = 0; i < facNode.cycicCircle.outcommods.size(); i++){
if(facNode.cycicCircle.outcommods.get(i) == cb.getValue()){
facNode.cycicCircle.outcommods.remove(i);
}
}*/
cb.getItems().clear();
for (CommodityNode label: DataArrays.CommoditiesList){
cb.getItems().add(label.name.getText());
}
cb.getItems().add("New Commodity");

if (defaultValue.get(0) != "") {
if (defaultValue.get(0) != null) {
cb.setValue((String) defaultValue.get(0));
}
}
Expand All @@ -362,7 +370,14 @@ public void handle(MouseEvent e){
cb.setPromptText("Select a commodity");
cb.valueProperty().addListener(new ChangeListener<String>(){
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue){
if (newValue == "New Commodity"){
if(newValue == null){
for (int i = 0; i < facNode.cycicCircle.outcommods.size(); i++) {
if (facNode.cycicCircle.outcommods.get(i) == (String) oldValue){
facNode.cycicCircle.outcommods.remove(i);
break;
}
}
} else if (newValue == "New Commodity"){
Cycic.addNewCommodity();
} else {
facNode.cycicCircle.outcommods.add(newValue);
Expand Down
6 changes: 5 additions & 1 deletion cyclist/src/edu/utexas/cycic/presenter/CycicPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
import edu.utah.sci.cyclist.core.event.notification.EventBus;
import edu.utah.sci.cyclist.core.presenter.ViewPresenter;
import edu.utah.sci.cyclist.core.presenter.CyclistViewPresenter;
import edu.utah.sci.cyclist.core.event.notification.CyclistNotification;
import edu.utah.sci.cyclist.core.event.notification.CyclistNotifications;
import edu.utah.sci.cyclist.core.event.notification.CyclistViewNotification;
import edu.utah.sci.cyclist.core.event.notification.SimpleNotification;
import edu.utah.sci.cyclist.core.ui.View;
import edu.utah.sci.cyclist.core.model.Table;
import edu.utexas.cycic.CycicNotifications;

public class CycicPresenter extends ViewPresenter {

/**
* CycicPresenter
* Constructor
Expand Down Expand Up @@ -40,5 +43,6 @@ public void call() {
public void onViewSelected(View view) {
super.onViewSelected(view);
}


}