User Tools

Site Tools


struktura:marklar-fx-common:standardlayout:genericcells

Generic Cells

GenericCell je bunka vkladana do ExperimntListView. Jediny konstruktor, o jehoz spravne volani se stara jadro, zajistuje, ze kazda GenericCell si uchovava ExperimentInstance, ke ktere se vaze.

public GenericCell(ExperimentInstance expInst) {
  this.expInst = expInst;
}

Pri vytvareni GenericCell je treba dodrzovat par striktnich reguli, jejichz prehled nasleduje

AnchorPane

GenericCell obsauje promenou anchorPane, takze je treba, aby graficky obsah byl vlozen do jedne AnchorPane, ktera se musi mit fx:id=anchorPane

@FXML
protected AnchorPane anchorPane;

FXML File

Bezne musi byt FXML soubor svazan s jeho controllerem. V pripade GenericCell vazbu vytvari constructor. Neni dovoleno GenericCell prirazovat jakykoliv controller. Constructor pak vypada nasledovne

public PlastEndedCellController(ExperimentInstance expInst) {
  super(expInst);
  // provazani s view
  setFXMLFile("PlastEndedCell.fxml");
 
  // nastaveni prislusnych Listeneru
  ServiceLocator.getInstance().getLogicModuleManager().registerListener(expInst.getExperimentType(), new ExperimentLogicListener() {
    @Override
    public void processEvent(LogicModuleEvent event) {
      if (event instanceof PlastLogAxisChangeEvent) {
        // do somenthing
      }
    }
  });
}

Plneni grafiky

O dokresleni grafiky se stara metoda fillGraphics(), ktera by zpravidla mela nastavit pozadi, obrazek a pripadne vykreslit graf a naplnit labely obsahem.

@Override
public void fillGraphics() {
  if (expInst == null)
    return;
 
  // protected metoda GenericCell, ktera nastavi pozadi v zavislosti na ExperimentStatus
  setBackgroundColor();
  setImage();
 
  lblInstrument.setText(expInst.getInstrument().getName());
  // ... a dalse
}
 
private void setImage() {
  if (expInst.getStatus() == ExperimentStatus.ENDED) {
    imgView.setImage(new Image(this.getClass().getResourceAsStream("check.png")));
  } else if (expInst.getStatus() == ExperimentStatus.ABORTED) {
    imgView.setImage(new Image(this.getClass().getResourceAsStream("check.png")));
  }
}

MainResultCell

Mezi GenericCell je jedna vyjimecna a to tim, ze misto jedne ExperimentInstance potrebuje zpravidla List<ExperimentInstance>. Jedna se o bunku, ktera zobrazuje statisticke vysledky z nekolika ExperimentInstance. List<experimentInstance> se teto bunce preda constructorem.

private List<ExperimentInstance> expInstances;
 
public PlastMainResultCellController(ExperimentInstance expInst) {
  super(expInst);
  setFXMLFile("PlastMainResultCell.fxml");
}
 
public PlastMainResultCellController(List<ExperimentInstance> expInstances) {
  super(null);
  this.expInstances = expInstances;
  setFXMLFile("PlastMainResultCell.fxml");
}

ExperimentTypeGraphicFactory

ExperimentTypeGraphicFactory obsahuje dve metody vracejici GenericCell. Jejich konkretni implementace vypada nasledovne

@Override
public GenericCell getMainTableCellForInstance(ExperimentInstance expInstance) {
  GenericCell cell = null;
 
  switch (expInstance.getStatus()) {
    case NEW: {
      cell = new PlastPrepareCellController(expInstance);
      break;
    }
    case NEW_LOCKED: {
      cell = new PlastPrepareCellController(expInstance);
      break;
    }
    case RUNNING: {
      cell = new PlastRunningCellController(expInstance);
      break;
    }
    case PAUSED: {
      cell = new PlastPausedCellController(expInstance);
      break;
    }
    case SUSPENDED: {
      cell = new PlastPausedCellController(expInstance);
      break;
    }
    case CRASHED: {
      cell = new PlastCrashedCellController(expInstance);
      break;
    }
    case ENDED: {
      cell = new PlastEndedCellController(expInstance);
      break;
    }
    case ABORTED: {
      cell = new PlastEndedCellController(expInstance);
      break;
    }
  }
 
  return cell;
}
 
@Override
public GenericCell getMainResultCellForInstances(List<ExperimentInstance> expInstances) {
  return new PlastMainResultCellController(expInstances);
}
struktura/marklar-fx-common/standardlayout/genericcells.txt · Last modified: 2016/07/20 18:33 by jlochman