KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > memory > renderings > BigEndianAction


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.views.memory.renderings;
12
13 import org.eclipse.debug.core.model.MemoryByte;
14 import org.eclipse.jface.action.IAction;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.ui.IObjectActionDelegate;
18 import org.eclipse.ui.IWorkbenchPart;
19
20 /**
21  * Show integers in Big Endian
22  */

23 public class BigEndianAction implements IObjectActionDelegate {
24
25     AbstractIntegerRendering fRendering;
26     
27     /* (non-Javadoc)
28      * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
29      */

30     public void setActivePart(IAction action, IWorkbenchPart targetPart) {
31     }
32
33     /* (non-Javadoc)
34      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
35      */

36     public void run(IAction action) {
37
38         if (fRendering == null)
39             return;
40         
41         if (fRendering.getDisplayEndianess() != RenderingsUtil.BIG_ENDIAN){
42             fRendering.setDisplayEndianess(RenderingsUtil.BIG_ENDIAN);
43             fRendering.refresh();
44         }
45     }
46
47     /* (non-Javadoc)
48      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
49      */

50     public void selectionChanged(IAction action, ISelection selection) {
51         
52         if (selection == null)
53             return;
54         
55         if (selection instanceof IStructuredSelection)
56         {
57             Object JavaDoc obj = ((IStructuredSelection)selection).getFirstElement();
58             if (obj == null)
59                 return;
60             
61             if (obj instanceof AbstractIntegerRendering)
62             {
63                 fRendering = (AbstractIntegerRendering)obj;
64             }
65             
66             int endianess = RenderingsUtil.ENDIANESS_UNKNOWN;
67             if (fRendering.getDisplayEndianess() == RenderingsUtil.ENDIANESS_UNKNOWN)
68             {
69                 MemoryByte[] selectedBytes = fRendering.getSelectedAsBytes();
70                 for (int i=0; i<selectedBytes.length; i++)
71                 {
72                     if (!selectedBytes[i].isEndianessKnown())
73                     {
74                         endianess = RenderingsUtil.ENDIANESS_UNKNOWN;
75                         break;
76                     }
77                     if (i==0)
78                     {
79                         endianess = selectedBytes[i].isBigEndian()?RenderingsUtil.BIG_ENDIAN:RenderingsUtil.LITTLE_ENDIAN;
80                     }
81                     else
82                     {
83                         int byteEndianess = selectedBytes[i].isBigEndian()?RenderingsUtil.BIG_ENDIAN:RenderingsUtil.LITTLE_ENDIAN;
84                         if (endianess != byteEndianess)
85                         {
86                             endianess = RenderingsUtil.ENDIANESS_UNKNOWN;
87                             break;
88                         }
89                     }
90                 }
91             }
92             else
93                 endianess = fRendering.getDisplayEndianess();
94             
95             if (endianess == RenderingsUtil.BIG_ENDIAN)
96                 action.setChecked(true);
97             else
98                 action.setChecked(false);
99         }
100     }
101 }
102
Popular Tags