1 11 12 package org.eclipse.debug.internal.ui.views.variables; 13 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.custom.CLabel; 16 import org.eclipse.swt.graphics.GC; 17 import org.eclipse.swt.graphics.Point; 18 import org.eclipse.swt.widgets.Composite; 19 20 import org.eclipse.jface.action.ContributionItem; 21 import org.eclipse.jface.action.IContributionManager; 22 import org.eclipse.jface.action.StatusLineLayoutData; 23 24 public class StatusLineContributionItem extends ContributionItem { 25 26 public final static int DEFAULT_CHAR_WIDTH = 40; 27 28 private int charWidth; 29 private CLabel label; 30 35 private Composite statusLine = null; 36 private String text= ""; private int widthHint = -1; 38 39 public StatusLineContributionItem(String id) { 40 this(id, DEFAULT_CHAR_WIDTH); 41 } 42 43 public StatusLineContributionItem(String id, int charWidth) { 44 super(id); 45 this.charWidth = charWidth; 46 setVisible(false); } 48 49 public void fill(Composite parent) { 50 statusLine = parent; 51 label = new CLabel(statusLine, SWT.NONE); 52 StatusLineLayoutData statusLineLayoutData = new StatusLineLayoutData(); 53 54 if (widthHint < 0) { 55 GC gc = new GC(statusLine); 56 gc.setFont(statusLine.getFont()); 57 widthHint = gc.getFontMetrics().getAverageCharWidth() * charWidth; 58 gc.dispose(); 59 } 60 61 statusLineLayoutData.widthHint = widthHint; 62 label.setLayoutData(statusLineLayoutData); 63 label.setText(text); 64 } 65 66 73 public Point getDisplayLocation() { 74 if ((label != null) && (statusLine != null)) { 75 return statusLine.toDisplay(label.getLocation()); 76 } 77 78 return null; 79 } 80 81 public String getText() { 82 return text; 83 } 84 85 public void setText(String text) { 86 if (text == null) 87 throw new NullPointerException (); 88 89 this.text = text; 90 91 if (label != null && !label.isDisposed()) 92 label.setText(this.text); 93 94 if (this.text.length() == 0) { 95 if (isVisible()) { 96 setVisible(false); 97 IContributionManager contributionManager = getParent(); 98 99 if (contributionManager != null) 100 contributionManager.update(true); 101 } 102 } else { 103 if (!isVisible()) { 104 setVisible(true); 105 IContributionManager contributionManager = getParent(); 106 107 if (contributionManager != null) 108 contributionManager.update(true); 109 } 110 } 111 } 112 } 113 | Popular Tags |