blob: 00e68e60b5ff0fafbbe67099f3b50c138f563d29 [file] [log] [blame]
/**
********************************************************************************
* Copyright (c) 2020-2021 Robert Bosch GmbH.
*
* 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
*
* Contributors:
* Robert Bosch GmbH - initial API and implementation
*******************************************************************************/
package org.eclipse.app4mc.amalthea.visualization.hw;
import java.util.List;
import javax.annotation.PostConstruct;
import org.eclipse.app4mc.amalthea.model.HwStructure;
import org.eclipse.app4mc.visualization.ui.registry.Visualization;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.di.extensions.Preference;
import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.osgi.service.component.annotations.Component;
import net.sourceforge.plantuml.eclipse.utils.PlantumlConstants;
@SuppressWarnings("restriction")
@Component(property= {
"name=HW Structure Block Diagram",
"description=Block Diagram Visualization for Hardware Structures"
})
public class HWBlockDiagramVisualization2 implements Visualization {
@PostConstruct
public void createVisualization(
List<HwStructure> structures,
Composite parent,
Shell shell,
@Optional
@Preference(
nodePath = "net.sourceforge.plantuml.eclipse",
value = PlantumlConstants.GRAPHVIZ_PATH)
String dotPath,
UISynchronize sync) {
Browser browser = new Browser(parent, SWT.NONE);
DiagramLocation diagramLocation = new DiagramLocation(structures.get(0));
if (!diagramLocation.isValid()) return;
// *** Execute job
JobChangeAdapter listener = new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
sync.asyncExec(() -> {
if (!browser.isDisposed()) {
browser.setUrl(diagramLocation.getDiagramFilePath());
}
});
}
};
VisualizationHandler handler = new VisualizationHandler();
handler.execute(shell, sync, dotPath, structures, diagramLocation, false, listener);
}
}