All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.micromata.mgc.javafx.launcher.gui.AbstractConfigTabController Maven / Gradle / Ivy

There is a newer version: 3.1.3
Show newest version
//
// Copyright (C) 2010-2016 Micromata GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package de.micromata.mgc.javafx.launcher.gui;

import java.lang.reflect.Field;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

import org.apache.commons.lang3.StringUtils;

import de.micromata.genome.util.bean.FieldMatchers;
import de.micromata.genome.util.bean.PrivateBeanUtils;
import de.micromata.genome.util.i18n.OptionalTranslationProvider;
import de.micromata.genome.util.runtime.config.LocalSettingsConfigModel;
import de.micromata.genome.util.validation.ValMessage;
import de.micromata.mgc.javafx.FXEvents;
import de.micromata.mgc.javafx.ModelController;
import de.micromata.mgc.javafx.ValMessageEvent;
import de.micromata.mgc.javafx.feedback.FeedbackPanel;
import de.micromata.mgc.javafx.launcher.MgcLauncher;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Control;
import javafx.scene.control.Tab;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.Pane;

/**
 * 
 * @author Roger Rene Kommer ([email protected])
 *
 * @param  the type of the model controller
 */
public abstract class AbstractConfigTabControllerextends AbstractModelController
    implements Initializable, ModelController
{

  protected AbstractConfigDialog configDialog;
  protected Tab tab;
  protected Pane tabPane;
  /**
   * Feedback messages.
   */
  @FXML
  protected FeedbackPanel feedback;

  public abstract String getTabTitle();

  @Override
  public void initialize(URL arg0, ResourceBundle arg1)
  {

  }

  @Override
  public void addToFeedback(ValMessage msg)
  {
    feedback.addMessage(msg);
    msg.consume();
  }

  @Override
  public void registerValMessageReceivers()
  {
    super.registerValMessageReceivers();
    FXEvents.get().addEventHandler(this, getThisNode(), ValMessageEvent.MESSAGE_EVENT_TYPE, event -> {
      //      if (event.getMessage().getReference() != null
      //          && type.isAssignableFrom(event.getMessage().getReference().getClass()) == true) {
      if (isMessageReceiver(event.getMessage()) == true) {
        markTabWithError(event.getMessage());
      }
    });
  }

  protected boolean isMessageReceiver(ValMessage msg)
  {
    return msg.getReference() == getModel();
  }

  protected DialogBuilder dialogBuilder()
  {
    DialogBuilder builder = new DialogBuilder((Pane) getThisNode());
    builder.setTranslation(new OptionalTranslationProvider(MgcLauncher.get().getApplication().getTranslateService()));
    return builder;
  }

  public void clearTabErros()
  {
    getTab().setStyle("");
  }

  public void markTabWithError(ValMessage msg)
  {
    if (msg.getValState().isErrorOrWorse() == true) {
      getTab().setStyle("-fx-background-color: red");
    }
  }

  protected void addTooltip(String field)
  {
    Field nodeField = PrivateBeanUtils.findField(getClass(), field);
    if (Control.class.isAssignableFrom(nodeField.getType()) == false) {
      return;
    }
    Control node = (Control) PrivateBeanUtils.readField(this, nodeField);
    if (node == null) {
      return;
    }
    addTooltip(node, field);
  }

  protected void addTooltip(Control node, String field)
  {
    String cmd = getModel().findCommentForProperty(field);
    if (StringUtils.isBlank(cmd) == true) {
      return;
    }
    node.setTooltip(new Tooltip(cmd));
  }

  public void addToolTips()
  {
    List fields = PrivateBeanUtils.findAllFields(getClass(), FieldMatchers.assignableTo(Control.class));
    for (Field field : fields) {
      Control control = (Control) PrivateBeanUtils.readField(this, field);
      if (control == null) {
        continue;
      }
      addTooltip(control, field.getName());
    }
  }

  public Pane getTabPane()
  {
    return tabPane;
  }

  public void setTabPane(Pane tabPane)
  {
    this.tabPane = tabPane;
  }

  public AbstractConfigDialog getConfigDialog()
  {
    return configDialog;
  }

  public void setConfigDialog(AbstractConfigDialog configDialog)
  {
    this.configDialog = configDialog;
  }

  public FeedbackPanel getFeedback()
  {
    return feedback;
  }

  public void setFeedback(FeedbackPanel feedback)
  {
    this.feedback = feedback;
  }

  public Tab getTab()
  {
    return tab;
  }

  public void setTab(Tab tab)
  {
    this.tab = tab;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy