| /** |
| ******************************************************************************** |
| * Copyright (c) 2020 Eclipse APP4MC contributors. |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| ******************************************************************************** |
| */ |
| |
| package org.eclipse.app4mc.amalthea._import.atdb; |
| |
| import java.lang.reflect.InvocationTargetException; |
| import java.sql.SQLException; |
| import java.util.ArrayList; |
| import java.util.List; |
| |
| import org.eclipse.app4mc.amalthea.model.Amalthea; |
| import org.eclipse.app4mc.amalthea.model.AmaltheaPackage; |
| import org.eclipse.app4mc.amalthea.model.Label; |
| import org.eclipse.app4mc.amalthea.model.SWModel; |
| import org.eclipse.app4mc.amalthea.model.util.CustomPropertyUtil; |
| import org.eclipse.app4mc.amalthea.model.util.ModelUtil; |
| import org.eclipse.app4mc.atdb.ATDBConnection; |
| import org.eclipse.app4mc.atdb.EntityProperty; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| |
| public class LabelConverter extends AConverter { |
| |
| public LabelConverter(final Amalthea model, final ATDBConnection con) { |
| super(model, con); |
| } |
| |
| @Override |
| public void run(IProgressMonitor progressMonitor) throws InvocationTargetException { |
| progressMonitor.beginTask("Converting labels", 1); |
| final SWModel swModel = ModelUtil.getOrCreateSwModel(this.model); |
| try { |
| final List<Label> labels = new ArrayList<>(); |
| this.con.getAllLabels().forEach(labelName -> { |
| final Label label = AmaltheaModelUtil.getOrAddNew(swModel, |
| AmaltheaPackage.eINSTANCE.getSWModel_Labels(), labelName, Label.class); |
| labels.add(label); |
| }); |
| for(final Label label:labels) { |
| final String initialValue = this.con.getLabelInitialValue(label.getName()); |
| if (initialValue.length() > 0) { |
| CustomPropertyUtil.customPut(label, EntityProperty.INITIAL_VALUE.camelName, initialValue); |
| } |
| } |
| progressMonitor.worked(1); |
| } catch (SQLException e) { |
| throw new InvocationTargetException(e); |
| } finally { |
| progressMonitor.done(); |
| } |
| } |
| |
| } |