/**
 *
 * Copyright (c) 2006-2016, Speedment, Inc. All Rights Reserved.
 *
 * 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 com.speedment.tool.internal.controller;

import com.speedment.generator.component.EventComponent;
import com.speedment.common.injector.annotation.Inject;
import com.speedment.tool.component.PropertyEditorComponent;
import com.speedment.tool.component.UserInterfaceComponent;
import com.speedment.tool.config.DocumentProperty;
import com.speedment.tool.config.trait.HasNameProperty;
import com.speedment.tool.event.TreeSelectionChange;
import com.speedment.tool.property.PropertyEditor;
import com.speedment.tool.property.PropertySheet;
import javafx.beans.binding.Bindings;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TitledPane;
import javafx.scene.control.TreeItem;

import java.net.URL;
import java.util.ResourceBundle;

/**
 *
 * @author Emil Forslund
 */
public final class WorkspaceController implements Initializable {
    
    private final ObservableList<PropertyEditor.Item> properties;
    
    private @Inject UserInterfaceComponent ui;
    private @Inject EventComponent events;
    private @Inject PropertyEditorComponent editors;
    
    private @FXML TitledPane workspace;
    
    public WorkspaceController() {
        this.properties = FXCollections.observableArrayList();
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        
        final PropertySheet sheet = new PropertySheet(properties);
        
        ui.getSelectedTreeItems()
            .addListener((ListChangeListener.Change<? extends TreeItem<DocumentProperty>> change) -> {
                properties.clear();
                
                if (!change.getList().isEmpty()) {
                    final TreeItem<DocumentProperty> treeItem = change.getList().get(0);
                    
                    if (treeItem != null) {
                        final DocumentProperty property = treeItem.getValue();
                    
                        @SuppressWarnings("unchecked")
                        final HasNameProperty withName = (HasNameProperty) property;
                        
                        workspace.textProperty().bind(
                            Bindings.createStringBinding(() -> String.format(
                                "Editing %s '%s'",
                                withName.mainInterface().getSimpleName(),
                                withName.getName()
                            ), withName.nameProperty())
                        );
                       editors.getUiVisibleProperties( treeItem.getValue() )
                            .forEach(properties::add);
                    }
                }
                
                events.notify(new TreeSelectionChange(change, properties));
            });
        
        workspace.setContent(sheet);
        
        Bindings.bindContentBidirectional(ui.getProperties(), properties);
    }
}
@@ -786,16 +786,65 @@
 Inject;%0A
+import com.speedment.runtime.internal.util.Cast;%0A
 import c
@@ -888,32 +888,32 @@
 ditorComponent;%0A
-
 import com.speed
@@ -948,32 +948,81 @@
 rfaceComponent;%0A
+import com.speedment.tool.config.ColumnProperty;%0A
 import com.speed
@@ -1592,16 +1592,43 @@
 et.URL;%0A
+import java.util.Optional;%0A
 import j
@@ -2949,32 +2949,330 @@
                %0A
+                        final Optional%3CString%3E extraInfo = Cast.cast(property, ColumnProperty.class)%0A                            .map(ColumnProperty::findDatabaseType)%0A                            .map(Class::getSimpleName)%0A                            .map(s -%3E %22(%22+s+%22)%22);%0A                        %0A
                 
@@ -3436,16 +3436,19 @@
  %25s '%25s'
+ %25s
 %22,%0A     
@@ -3516,16 +3516,16 @@
 Name(),%0A
-
         
@@ -3566,16 +3566,70 @@
 etName()
+,%0A                                extraInfo.orElse(%22%22)
 %0A       

Add Column JDBC type in UI. Fix #250