| /******************************************************************************* |
| * Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| * 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: |
| * Pierre Allard - initial API and implementation |
| * Regent L'Archeveque |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| *******************************************************************************/ |
| package org.eclipse.apogy.addons.sensors.imaging.camera.composites; |
| |
| import java.util.HashMap; |
| import java.util.Map; |
| |
| import org.eclipse.apogy.addons.sensors.imaging.camera.ApogyAddonsSensorsImagingCameraPackage; |
| import org.eclipse.apogy.addons.sensors.imaging.camera.CameraViewConfiguration; |
| import org.eclipse.apogy.addons.sensors.imaging.camera.CameraViewConfigurationList; |
| import org.eclipse.apogy.common.emf.ui.emfforms.ApogyCommonEMFUiEMFFormsFacade; |
| import org.eclipse.emf.edit.provider.ComposedAdapterFactory; |
| import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; |
| import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; |
| import org.eclipse.jface.viewers.IBaseLabelProvider; |
| import org.eclipse.jface.viewers.IContentProvider; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.custom.CTabFolder; |
| import org.eclipse.swt.custom.CTabItem; |
| import org.eclipse.swt.custom.ScrolledComposite; |
| import org.eclipse.swt.events.DisposeEvent; |
| import org.eclipse.swt.events.DisposeListener; |
| import org.eclipse.swt.events.SelectionAdapter; |
| import org.eclipse.swt.events.SelectionEvent; |
| import org.eclipse.swt.graphics.Image; |
| import org.eclipse.swt.graphics.Rectangle; |
| import org.eclipse.swt.layout.FillLayout; |
| import org.eclipse.swt.layout.GridData; |
| import org.eclipse.swt.layout.GridLayout; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Control; |
| import org.eclipse.swt.widgets.Event; |
| import org.eclipse.swt.widgets.Listener; |
| |
| public class CameraViewComposite extends Composite { |
| private final String DETAILS_ID = "Details"; |
| private final String OVERLAYS_ID = "Overlays"; |
| private final String FILTERS_ID = "Filters"; |
| private final String TOOLS_ID = "Tools"; |
| |
| private CameraViewConfiguration cameraViewConfiguration = null; |
| |
| private final ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory( |
| ComposedAdapterFactory.Descriptor.Registry.INSTANCE); |
| |
| private final CameraViewConfigurationComposite cameraComposite; |
| |
| private Composite toolbarMenuComposite; |
| private CTabFolder tabFolder; |
| private Map<String, CTabItem> tabItemMap; |
| |
| private CameraViewConfigurationList configurationList; |
| |
| public CameraViewComposite(Composite parent, int style) { |
| super(parent, style); |
| setLayout(new GridLayout(1, false)); |
| addDisposeListener(new DisposeListener() { |
| |
| @Override |
| public void widgetDisposed(DisposeEvent e) { |
| if (CameraViewComposite.this.tabFolder != null && !CameraViewComposite.this.tabFolder.isDisposed()) { |
| for (Control control : CameraViewComposite.this.tabFolder.getChildren()) { |
| control.dispose(); |
| } |
| } |
| } |
| }); |
| |
| this.cameraComposite = new CameraViewConfigurationComposite(this, SWT.None); |
| this.cameraComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
| } |
| |
| public void setCameraViewConfiguration(CameraViewConfiguration cameraViewConfiguration) { |
| this.cameraViewConfiguration = cameraViewConfiguration; |
| |
| // Update view |
| this.cameraComposite.setCameraViewConfiguration(cameraViewConfiguration); |
| |
| // Update tool bar if applicable |
| if (this.toolbarMenuComposite != null && !this.toolbarMenuComposite.isDisposed()) { |
| if (this.tabFolder != null && !this.tabFolder.isDisposed()) { |
| for (Control control : this.tabFolder.getChildren()) { |
| control.dispose(); |
| } |
| } |
| this.toolbarMenuComposite.dispose(); |
| |
| for (Object key : this.tabItemMap.keySet()) { |
| if (this.tabItemMap.get(key) == this.tabFolder.getSelection()) { |
| updatetoolbarMenuComposite((String) key, true); |
| } |
| } |
| } |
| |
| // Notify there is a new selection. |
| newCameraViewConfigurationSelected(cameraViewConfiguration); |
| } |
| |
| protected void newCameraViewConfigurationSelected(CameraViewConfiguration newCameraViewConfiguration) { |
| |
| } |
| |
| /** |
| * Updates the toolBarMenu. |
| * |
| * @param parameterID ID of the parameter to display |
| * @param selected id true, the selected tabItem will change. Otherwise, if |
| * false the composite will be disposed. |
| */ |
| public void updatetoolbarMenuComposite(String parameterID, boolean selected) { |
| if (selected) { |
| if (this.toolbarMenuComposite == null || this.toolbarMenuComposite.isDisposed()) { |
| /** |
| * Composite |
| */ |
| this.toolbarMenuComposite = new Composite(this, SWT.None); |
| this.toolbarMenuComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); |
| this.toolbarMenuComposite.setLayout(new FillLayout(SWT.HORIZONTAL)); |
| // Limits the height of the toolBarMenu at 1/3 of the total height of the |
| // composite. |
| this.toolbarMenuComposite.addListener(SWT.Resize, new Listener() { |
| @Override |
| public void handleEvent(Event event) { |
| if (CameraViewComposite.this.toolbarMenuComposite |
| .getSize().y > CameraViewComposite.this.getBounds().height / 3) { |
| int diff = CameraViewComposite.this.toolbarMenuComposite.getSize().y |
| - CameraViewComposite.this.getBounds().height / 3; |
| Rectangle bounds = CameraViewComposite.this.toolbarMenuComposite.getBounds(); |
| CameraViewComposite.this.toolbarMenuComposite.setBounds(bounds.x, bounds.y + diff, |
| bounds.width, bounds.height - diff); |
| CameraViewComposite.this.cameraComposite.setSize( |
| CameraViewComposite.this.cameraComposite.getSize().x, |
| CameraViewComposite.this.cameraComposite.getSize().y + diff); |
| } |
| } |
| }); |
| |
| /** |
| * Folder |
| */ |
| this.tabFolder = new CTabFolder(this.toolbarMenuComposite, SWT.BORDER); |
| this.tabFolder.setLayout(new FillLayout()); |
| this.tabFolder.addSelectionListener(new SelectionAdapter() { |
| @Override |
| public void widgetSelected(SelectionEvent e) { |
| for (Object key : CameraViewComposite.this.tabItemMap.keySet()) { |
| if (CameraViewComposite.this.tabItemMap.get(key) == ((CTabFolder) e.getSource()) |
| .getSelection()) { |
| newTabFolderSelection((String) key); |
| } |
| } |
| } |
| }); |
| |
| /** |
| * Details |
| */ |
| CTabItem tbtmDetails = new CTabItem(this.tabFolder, SWT.NONE); |
| tbtmDetails.setText("Details"); |
| ScrolledComposite emfFormsScrolledComposite = new ScrolledComposite(this.tabFolder, |
| SWT.H_SCROLL | SWT.V_SCROLL); |
| emfFormsScrolledComposite.setExpandHorizontal(true); |
| emfFormsScrolledComposite.setExpandVertical(true); |
| Composite emfFormsDetails = new Composite(emfFormsScrolledComposite, SWT.None); |
| emfFormsDetails.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE)); |
| ApogyCommonEMFUiEMFFormsFacade.INSTANCE.createEMFForms(emfFormsDetails, |
| getSelectedCameraViewConfiguration()); |
| emfFormsScrolledComposite.setContent(emfFormsDetails); |
| emfFormsScrolledComposite.setMinSize(emfFormsDetails.computeSize(SWT.DEFAULT, SWT.DEFAULT)); |
| tbtmDetails.setControl(emfFormsScrolledComposite); |
| |
| /** |
| * Overlays |
| */ |
| CTabItem tbtmOverlays = new CTabItem(this.tabFolder, SWT.NONE); |
| tbtmOverlays.setText("Overlays"); |
| CameraImageAnnotationListComposite overlayComposite = new CameraImageAnnotationListComposite( |
| this.tabFolder, SWT.NONE); |
| overlayComposite.setCameraViewConfiguration(getSelectedCameraViewConfiguration(), |
| ApogyAddonsSensorsImagingCameraPackage.Literals.CAMERA_VIEW_CONFIGURATION__OVERLAY_LIST); |
| tbtmOverlays.setControl(overlayComposite); |
| |
| /** |
| * Filters |
| */ |
| CTabItem tbtmFilters = new CTabItem(this.tabFolder, SWT.NONE); |
| tbtmFilters.setText("Filters"); |
| FiltersListComposite filtersComposite = new FiltersListComposite(this.tabFolder, SWT.NONE); |
| filtersComposite.setCameraViewConfiguration(getSelectedCameraViewConfiguration()); |
| tbtmFilters.setControl(filtersComposite); |
| |
| /** |
| * Tools |
| */ |
| CTabItem tbtmTools = new CTabItem(this.tabFolder, SWT.NONE); |
| tbtmTools.setText("Tools"); |
| CameraImageAnnotationListComposite toolsComposite = new CameraImageAnnotationListComposite( |
| this.tabFolder, SWT.NONE); |
| toolsComposite.setCameraViewConfiguration(getSelectedCameraViewConfiguration(), |
| ApogyAddonsSensorsImagingCameraPackage.Literals.CAMERA_VIEW_CONFIGURATION__TOOL_LIST); |
| tbtmTools.setControl(toolsComposite); |
| |
| this.tabItemMap = new HashMap<String, CTabItem>(); |
| this.tabItemMap.put(this.DETAILS_ID, tbtmDetails); |
| this.tabItemMap.put(this.FILTERS_ID, tbtmFilters); |
| this.tabItemMap.put(this.OVERLAYS_ID, tbtmOverlays); |
| this.tabItemMap.put(this.TOOLS_ID, tbtmTools); |
| |
| layout(); |
| } |
| this.tabFolder.setSelection(this.tabItemMap.get(parameterID)); |
| } |
| /** Otherwise close the menu toolBar */ |
| else { |
| /** |
| * Dispose |
| */ |
| if (!this.toolbarMenuComposite.isDisposed()) { |
| for (Control control : this.tabFolder.getChildren()) { |
| control.dispose(); |
| } |
| this.toolbarMenuComposite.dispose(); |
| } |
| |
| layout(); |
| } |
| } |
| |
| protected void newTabFolderSelection(String parameterID) { |
| } |
| |
| public CameraViewConfiguration getSelectedCameraViewConfiguration() { |
| return this.cameraViewConfiguration; |
| } |
| |
| public void setCameraViewConfigurationList(CameraViewConfigurationList cameraViewConfigurationList) { |
| this.configurationList = cameraViewConfigurationList; |
| } |
| |
| protected IContentProvider getContentProvider() { |
| return new AdapterFactoryContentProvider(this.adapterFactory) { |
| @Override |
| public Object[] getElements(Object object) { |
| return CameraViewComposite.this.configurationList.getCameraViewConfigurations().toArray(); |
| } |
| |
| @Override |
| public Object[] getChildren(Object object) { |
| return null; |
| } |
| }; |
| } |
| |
| protected IBaseLabelProvider getLabelProvider() { |
| return new AdapterFactoryLabelProvider(this.adapterFactory) { |
| @Override |
| public String getText(Object object) { |
| if (object instanceof CameraViewConfiguration) { |
| return ((CameraViewConfiguration) object).getName(); |
| } |
| return ""; |
| } |
| |
| @Override |
| public Image getImage(Object object) { |
| return null; |
| } |
| }; |
| } |
| } |