1 /******************************************************************************* 2 * Copyright (c) 2008, 2018 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.debug.examples.ui.midi.detailpanes; 15 16 import java.util.HashSet; 17 import java.util.Set; 18 19 import org.eclipse.debug.examples.core.midi.launcher.ClockControl; 20 import org.eclipse.debug.examples.core.midi.launcher.TempoControl; 21 import org.eclipse.debug.ui.IDetailPane; 22 import org.eclipse.debug.ui.IDetailPaneFactory; 23 import org.eclipse.jface.viewers.IStructuredSelection; 24 25 /** 26 * Creates detail panes for sequencer controls. 27 * 28 * @since 1.0 29 */ 30 public class ControlDetailPaneFactory implements IDetailPaneFactory { 31 32 /** 33 * Identifier for the tempo slider detail pane 34 */ 35 public static final String ID_TEMPO_SLIDER = "TEMPO_SLIDER"; //$NON-NLS-1$ 36 37 /** 38 * Identifier for the clock slider detail pane 39 */ 40 public static final String ID_CLOCK_SLIDER = "CLOCK_SLIDER"; //$NON-NLS-1$ 41 42 @Override createDetailPane(String paneID)43 public IDetailPane createDetailPane(String paneID) { 44 if (ID_TEMPO_SLIDER.equals(paneID)) { 45 return new TempoSliderDetailPane(); 46 } 47 if (ID_CLOCK_SLIDER.equals(paneID)) { 48 return new ClockSliderDetailPane(); 49 } 50 return null; 51 } 52 53 @Override getDefaultDetailPane(IStructuredSelection selection)54 public String getDefaultDetailPane(IStructuredSelection selection) { 55 if (selection.size() == 1) { 56 Object element = selection.getFirstElement(); 57 if (element instanceof TempoControl) { 58 return ID_TEMPO_SLIDER; 59 } 60 if (element instanceof ClockControl) { 61 return ID_CLOCK_SLIDER; 62 } 63 } 64 return null; 65 } 66 67 @Override getDetailPaneDescription(String paneID)68 public String getDetailPaneDescription(String paneID) { 69 if (ID_TEMPO_SLIDER.equals(paneID)) { 70 return "Tempo Slider"; //$NON-NLS-1$ 71 } 72 if (ID_CLOCK_SLIDER.equals(paneID)) { 73 return "Clock Slider"; //$NON-NLS-1$ 74 } 75 return null; 76 } 77 78 @Override getDetailPaneName(String paneID)79 public String getDetailPaneName(String paneID) { 80 if (ID_TEMPO_SLIDER.equals(paneID)) { 81 return "Tempo Slider"; //$NON-NLS-1$ 82 } 83 if (ID_CLOCK_SLIDER.equals(paneID)) { 84 return "Clock Slider"; //$NON-NLS-1$ 85 } 86 return null; 87 } 88 89 @Override getDetailPaneTypes(IStructuredSelection selection)90 public Set<String> getDetailPaneTypes(IStructuredSelection selection) { 91 Set<String> set = new HashSet<>(); 92 if (selection.size() == 1) { 93 Object element = selection.getFirstElement(); 94 if (element instanceof TempoControl) { 95 set.add(ID_TEMPO_SLIDER); 96 } 97 if (element instanceof ClockControl) { 98 set.add(ID_CLOCK_SLIDER); 99 } 100 } 101 return set; 102 } 103 104 } 105