public FieldName(final GObject gObj, ArrayList<String> fieldNames, String type, GridPane gp, int row, HistoryManager hm) {
        gp.add(new Label(LabelGrabber.getLabel("field.name.text") + ":"), 0, row);
        textField = new FieldNameTextField();
        this.fieldNames = fieldNames;
        this.historyManager = hm;
        this.gObj = gObj;

        // Grab the fieldname if already set (which is the case when loading from FXML).
        if (gObj.getFieldName() != null) {
            textField.setText(gObj.getFieldName());
            fieldNames.add(gObj.getFieldName());
        } else {
            //Set default field name
            type = type.substring(0, 1).toLowerCase() + type.substring(1);
            int count = 1;
            while (fieldNames.contains(type + count)) {
                count++;
            }
            textField.setText(type + count);
            gObj.setFieldName(type + count);
            fieldNames.add(type + count);
        }

        gp.add(textField, 1, row);

        //Upon losing focus, save to the GObject
        textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
            @Override
            public void changed(ObservableValue<? extends Boolean> observableValue, Boolean aBoolean, Boolean aBoolean2) {
                if (!aBoolean2) {
                    historyManager.addHistory(new HistoryItem() {
                        String old = gObj.getFieldName();
                        String nnew = textField.getText();

                        @Override
                        public void revert() {
                            gObj.setFieldName(old);
                            textField.setText(old);
                        }

                        @Override
                        public void restore() {
                            gObj.setFieldName(nnew);
                            textField.setText(nnew);
                        }

                        @Override
                        public String getAppearance() {
                            return old + " -> " + nnew;
                        }
                    });
                    gObj.setFieldName(textField.getText());

                }
            }
        });
    }