Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarin Wright2008-02-25 22:50:15 -0500
committerDarin Wright2008-02-25 22:50:15 -0500
commit6a2394da0df6bacb6dd64a30f6889d73c2895b7a (patch)
tree2624ef4be435f6bf7ec85e2da5ce036d22e57484 /org.eclipse.debug.examples.ui
parentbe6af1c4491dc07f91f855a5ac86c14b7956ac06 (diff)
downloadeclipse.platform.debug-6a2394da0df6bacb6dd64a30f6889d73c2895b7a.tar.gz
eclipse.platform.debug-6a2394da0df6bacb6dd64a30f6889d73c2895b7a.tar.xz
eclipse.platform.debug-6a2394da0df6bacb6dd64a30f6889d73c2895b7a.zip
Midi example - track content in variables view
Diffstat (limited to 'org.eclipse.debug.examples.ui')
-rw-r--r--org.eclipse.debug.examples.ui/plugin.xml13
-rw-r--r--org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/MidiAdapterFactory.java14
-rw-r--r--org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/MidiEventLabelProvider.java62
-rw-r--r--org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/TrackColumnFactory.java45
-rw-r--r--org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/TrackColumnPresentation.java79
-rw-r--r--org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/TrackContentProvider.java63
6 files changed, 276 insertions, 0 deletions
diff --git a/org.eclipse.debug.examples.ui/plugin.xml b/org.eclipse.debug.examples.ui/plugin.xml
index a646b37c0..28322f77c 100644
--- a/org.eclipse.debug.examples.ui/plugin.xml
+++ b/org.eclipse.debug.examples.ui/plugin.xml
@@ -228,6 +228,12 @@
class="org.eclipse.debug.examples.ui.midi.adapters.MidiAdapterFactory"
adaptableType="javax.sound.midi.Track">
<adapter type="org.eclipse.debug.internal.ui.viewers.model.provisional.IElementLabelProvider"/>
+ <adapter
+ type="org.eclipse.debug.internal.ui.viewers.model.provisional.IElementContentProvider">
+ </adapter>
+ <adapter
+ type="org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentationFactory">
+ </adapter>
</factory>
<factory
adaptableType="org.eclipse.debug.examples.core.midi.launcher.SequencerControl"
@@ -238,6 +244,13 @@
<adapter
type="org.eclipse.debug.internal.ui.viewers.model.provisional.IElementEditor">
</adapter>
+ </factory>
+ <factory
+ adaptableType="javax.sound.midi.MidiEvent"
+ class="org.eclipse.debug.examples.ui.midi.adapters.MidiAdapterFactory">
+ <adapter
+ type="org.eclipse.debug.internal.ui.viewers.model.provisional.IElementLabelProvider">
+ </adapter>
</factory>
</extension>
<extension
diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/MidiAdapterFactory.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/MidiAdapterFactory.java
index 1876feb1c..2fe6cc27c 100644
--- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/MidiAdapterFactory.java
+++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/MidiAdapterFactory.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.debug.examples.ui.midi.adapters;
+import javax.sound.midi.MidiEvent;
import javax.sound.midi.Track;
import org.eclipse.core.runtime.IAdapterFactory;
@@ -30,11 +31,14 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxyFactor
public class MidiAdapterFactory implements IAdapterFactory {
private static IElementContentProvider fgSequencerContentProvider = new SequencerContentProvider();
+ private static IElementContentProvider fgTackContentProvider = new TrackContentProvider();
private static IElementLabelProvider fgTrackLabelProvider = new TrackLabelProvider();
private static IElementLabelProvider fgControlLabelProvider = new ControlLabelProvider();
+ private static IElementLabelProvider fgMidiEventLabelProvdier = new MidiEventLabelProvider();
private static IColumnPresentationFactory fgSequencerColumnFactory = new SequencerColumnFactory();
+ private static IColumnPresentationFactory fgTrackColumnFactory = new TrackColumnFactory();
private static IModelProxyFactory fgSequencerModelProxyFactory = new SequencerModelProxyFactory();
@@ -45,6 +49,9 @@ public class MidiAdapterFactory implements IAdapterFactory {
if (adaptableObject instanceof MidiLaunch) {
return fgSequencerContentProvider;
}
+ if (adaptableObject instanceof Track) {
+ return fgTackContentProvider;
+ }
}
if (IElementLabelProvider.class.equals(adapterType)) {
if (adaptableObject instanceof Track) {
@@ -53,11 +60,18 @@ public class MidiAdapterFactory implements IAdapterFactory {
if (adaptableObject instanceof SequencerControl) {
return fgControlLabelProvider;
}
+ if (adaptableObject instanceof MidiEvent) {
+ return fgMidiEventLabelProvdier;
+ }
}
+
if (IColumnPresentationFactory.class.equals(adapterType)) {
if (adaptableObject instanceof MidiLaunch) {
return fgSequencerColumnFactory;
}
+ if (adaptableObject instanceof Track) {
+ return fgTrackColumnFactory;
+ }
}
if (IElementEditor.class.equals(adapterType)) {
if (adaptableObject instanceof SequencerControl) {
diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/MidiEventLabelProvider.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/MidiEventLabelProvider.java
new file mode 100644
index 000000000..955b12846
--- /dev/null
+++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/MidiEventLabelProvider.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.debug.examples.ui.midi.adapters;
+
+import javax.sound.midi.MidiEvent;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.internal.ui.model.elements.ElementLabelProvider;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
+import org.eclipse.jface.viewers.TreePath;
+
+/**
+ * Provides labels for MIDI tracks.
+ *
+ * @since 1.0
+ */
+public class MidiEventLabelProvider extends ElementLabelProvider {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.model.elements.ElementLabelProvider#getLabel(org.eclipse.jface.viewers.TreePath, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, java.lang.String)
+ */
+ protected String getLabel(TreePath elementPath, IPresentationContext presentationContext, String columnId) throws CoreException {
+ MidiEvent event = (MidiEvent) elementPath.getLastSegment();
+ if (TrackColumnPresentation.COL_TICK.equals(columnId)) {
+ return Long.toString(event.getTick());
+ } else if (TrackColumnPresentation.COL_MESSAGE.equals(columnId)) {
+ byte[] bytes = event.getMessage().getMessage();
+ StringBuffer buffer = new StringBuffer();
+ int status = event.getMessage().getStatus();
+ appendByte(buffer, status);
+ for (int i = 1; i < bytes.length; i++) {
+ buffer.append(' ');
+ appendByte(buffer, bytes[i]);
+ }
+ return buffer.toString();
+ }
+ return "";
+ }
+
+ /**
+ * Appends a byte to the buffer with 2 hex characters.
+ *
+ * @param buffer
+ * @param b
+ */
+ private void appendByte(StringBuffer buffer, int b) {
+ String hex = Integer.toHexString(b).toUpperCase();
+ for (int i = hex.length(); i < 2; i++) {
+ buffer.append('0');
+ }
+ buffer.append(hex);
+ }
+
+}
diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/TrackColumnFactory.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/TrackColumnFactory.java
new file mode 100644
index 000000000..0a5b5fb7e
--- /dev/null
+++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/TrackColumnFactory.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.debug.examples.ui.midi.adapters;
+
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentation;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentationFactory;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
+import org.eclipse.debug.ui.IDebugUIConstants;
+
+/**
+ * Column presentation factory for a track.
+ *
+ * @since 1.0
+ */
+public class TrackColumnFactory implements IColumnPresentationFactory {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentationFactory#createColumnPresentation(org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, java.lang.Object)
+ */
+ public IColumnPresentation createColumnPresentation(IPresentationContext context, Object element) {
+ if (IDebugUIConstants.ID_VARIABLE_VIEW.equals(context.getId())) {
+ return new TrackColumnPresentation();
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentationFactory#getColumnPresentationId(org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, java.lang.Object)
+ */
+ public String getColumnPresentationId(IPresentationContext context, Object element) {
+ if (IDebugUIConstants.ID_VARIABLE_VIEW.equals(context.getId())) {
+ return TrackColumnPresentation.ID;
+ }
+ return null;
+ }
+
+}
diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/TrackColumnPresentation.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/TrackColumnPresentation.java
new file mode 100644
index 000000000..c09337169
--- /dev/null
+++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/TrackColumnPresentation.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.debug.examples.ui.midi.adapters;
+
+import org.eclipse.debug.internal.ui.viewers.provisional.AbstractColumnPresentation;
+
+/**
+ * Columns for sequencer in the variables view.
+ *
+ * @since 1.0
+ */
+public class TrackColumnPresentation extends AbstractColumnPresentation {
+
+ /**
+ * Column identifiers
+ */
+ public static final String COL_TICK = "TICK";
+ public static final String COL_MESSAGE = "MESSAGE";
+
+ /**
+ * All columns
+ */
+ public static final String[] COLUMN_IDS = new String[]{COL_TICK, COL_MESSAGE};
+
+ /**
+ * Column presentation ID.
+ */
+ public static final String ID = "org.eclipse.debug.examples.ui.midi.trackColumns";
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentation#getAvailableColumns()
+ */
+ public String[] getAvailableColumns() {
+ return COLUMN_IDS;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentation#getHeader(java.lang.String)
+ */
+ public String getHeader(String id) {
+ if (COL_TICK.equals(id)) {
+ return "Tick";
+ }
+ if (COL_MESSAGE.equals(id)) {
+ return "Message";
+ }
+ return "";
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentation#getId()
+ */
+ public String getId() {
+ return ID;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentation#getInitialColumns()
+ */
+ public String[] getInitialColumns() {
+ return COLUMN_IDS;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentation#isOptional()
+ */
+ public boolean isOptional() {
+ return false;
+ }
+
+}
diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/TrackContentProvider.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/TrackContentProvider.java
new file mode 100644
index 000000000..34c16a775
--- /dev/null
+++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/midi/adapters/TrackContentProvider.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.debug.examples.ui.midi.adapters;
+
+import javax.sound.midi.MidiEvent;
+import javax.sound.midi.Track;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.internal.ui.model.elements.ElementContentProvider;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate;
+import org.eclipse.debug.ui.IDebugUIConstants;
+
+/**
+ * Content provider for track in the variables view. Returns MIDI events
+ * in the track.
+ *
+ * @since 1.0
+ */
+public class TrackContentProvider extends ElementContentProvider {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.model.elements.ElementContentProvider#getChildCount(java.lang.Object, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate)
+ */
+ protected int getChildCount(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException {
+ Track track = (Track) element;
+ if (IDebugUIConstants.ID_VARIABLE_VIEW.equals(context.getId())) {
+ return track.size();
+ }
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.model.elements.ElementContentProvider#getChildren(java.lang.Object, int, int, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate)
+ */
+ protected Object[] getChildren(Object parent, int index, int length, IPresentationContext context, IViewerUpdate monitor) throws CoreException {
+ if (IDebugUIConstants.ID_VARIABLE_VIEW.equals(context.getId())) {
+ Track track = (Track) parent;
+ MidiEvent[] events= new MidiEvent[length];
+ for (int i = 0; i < length; i++) {
+ events[i] = track.get(i+index);
+ }
+ return events;
+ }
+ return EMPTY;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.model.elements.ElementContentProvider#supportsContextId(java.lang.String)
+ */
+ protected boolean supportsContextId(String id) {
+ return IDebugUIConstants.ID_VARIABLE_VIEW.equals(id);
+ }
+
+}

Back to the top