KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
22  * Show integers in little endian.
23  * @since 3.0
24  */

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

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

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

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