blob: 6e13924459b10e2459c16c4fe361d66824985b10 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.preferences.ui.component;
import java.util.Map;
import java.util.TreeMap;
import org.eclipse.swt.custom.TableTreeItem;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.osbp.preferences.DataSourceConfiguration;
import org.eclipse.osbp.preferences.EnumDatabaseVendor;
import org.eclipse.osbp.preferences.IItemDescribed;
import org.eclipse.osbp.preferences.ItemDescription;
import org.eclipse.osbp.preferences.PersistenceUnitConfiguration;
import org.eclipse.osbp.preferences.DataSourceConfiguration.DataSourceItemDescription;
import org.eclipse.osbp.preferences.PersistenceUnitConfiguration.PersistenceUnitItemDescription;
public class DataSourcesFieldEditor extends ATableTreeFieldEditor {
public DataSourcesFieldEditor(String name, String labelText,
Composite parent) {
super(
name, labelText, parent,
DataSourceItemDescription.INSTANCE);
}
@Override
protected void _doLoad(String value, String defaults) {
Map<String, DataSourceConfiguration> dataItems = DataSourceConfiguration.deserialize(value);
Map<String, DataSourceConfiguration> defaultItems = DataSourceConfiguration.deserialize(defaults);
for (DataSourceConfiguration dataItem : dataItems.values()) {
new TableTreeDescribedItem(this, dataItem, defaultItems.get(dataItem.getName()));
}
}
@Override
protected String _doStore() {
Map<String, DataSourceConfiguration> dataItems = new TreeMap<String, DataSourceConfiguration>();
for (TableTreeItem treeItem : tableTree.getItems()) {
if (treeItem instanceof IItemDescribed) {
IItemDescribed describedItem = (IItemDescribed) treeItem;
DataSourceConfiguration dataItem = new DataSourceConfiguration(
describedItem.getName(),
EnumDatabaseVendor.byName(describedItem.getValue(DataSourceItemDescription.DATABASE_TYPE), "", ""),
describedItem.getValue(DataSourceItemDescription.SERVER_NAME),
ItemDescription.parseInt(describedItem.getValue(DataSourceItemDescription.SERVER_PORT), -1),
describedItem.getValue(DataSourceItemDescription.DATABASE_NAME),
describedItem.getValue(DataSourceItemDescription.DATABASE_USER),
describedItem.getValue(DataSourceItemDescription.DATABASE_PASSWORD)
);
dataItems.put(dataItem.getName(), dataItem);
}
}
return DataSourceConfiguration.serialize(dataItems.values());
}
@Override
protected boolean hasRemoveButton() {
return true;
}
@Override
protected boolean hasAddButton() {
return true;
}
}