From: joon.c.baek Date: Thu, 9 Jun 2016 08:41:14 +0000 (+0900) Subject: [SRADA-779] Implements a search dialog X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3288d1e3aa48283fd83c0a4fafddd25e5823602d;p=sdk%2Ftools%2Fdynamic-analyzer.git [SRADA-779] Implements a search dialog Implements a search dialog, Search dialog written based on FindDialog class. Known issues: Not support category, Just support 'ALL', Dropdown arrow disappeared, Only support Startup, Calltrace table, Checkbox color doesn't match width guide, Contents area doesn't match with guide, Change-Id: Ib24265ce63efdc656f77b3a710bd25b1e91e7c81 Signed-off-by: joon.c.baek --- diff --git a/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/resources/ColorResources.java b/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/resources/ColorResources.java index 1e986db..27f9988 100644 --- a/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/resources/ColorResources.java +++ b/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/resources/ColorResources.java @@ -590,7 +590,10 @@ public class ColorResources { // preferences and remote device dialog public static Color DIALOG_TOP_LINE_COLOR = getColor("dialog_top_line_color"); //$NON-NLS-1$ public static Color DIALOG_CONTENT_BACKGROUND = getColor("dialog_content_background"); //$NON-NLS-1$ + public static Color DIALOG_BUTTON_BACKGROUND = getColor("dialog_button_background"); //$NON-NLS-1$ public static Color DIALOG_MIDDLE_LINE_COLOR = getColor("dialog_middle_line_color"); //$NON-NLS-1$ + public static Color DIALOG_BUTTON_LINE_COLOR = getColor("dialog_button_line_color"); //$NON-NLS-1$ + public static Color DIALOG_TEXT_FONT_COLOR = getColor("dialog_text_font_color"); //$NON-NLS-1$ // setting public static Color SETTING_STROKE = getColor("setting_stroke"); //$NON-NLS-1$ diff --git a/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/theme/DAThemeFlat.java b/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/theme/DAThemeFlat.java index 3e4abc7..832ebfd 100644 --- a/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/theme/DAThemeFlat.java +++ b/org.tizen.dynamicanalyzer.appearance/src/org/tizen/dynamicanalyzer/theme/DAThemeFlat.java @@ -582,7 +582,10 @@ public class DAThemeFlat extends DATheme { /*** preferences and remote device dialog ***/ setColor("dialog_top_line_color", new RGB(204, 204, 204)); //$NON-NLS-1$ setColor("dialog_content_background", new RGB(244, 244, 244)); //$NON-NLS-1$ + setColor("dialog_button_background", new RGB(255, 255, 255)); //$NON-NLS-1$ setColor("dialog_middle_line_color", new RGB(173, 173, 173)); //$NON-NLS-1$ + setColor("dialog_button_line_color", new RGB(170, 170, 170)); //$NON-NLS-1$ + setColor("dialog_text_font_color", new RGB(88, 88, 88)); //$NON-NLS-1$ /*** setting ***/ setColor("setting_stroke", new RGB(186, 186, 186)); //$NON-NLS-1$ diff --git a/org.tizen.dynamicanalyzer.widgets/META-INF/MANIFEST.MF b/org.tizen.dynamicanalyzer.widgets/META-INF/MANIFEST.MF index 31413c2..ef2cee8 100644 --- a/org.tizen.dynamicanalyzer.widgets/META-INF/MANIFEST.MF +++ b/org.tizen.dynamicanalyzer.widgets/META-INF/MANIFEST.MF @@ -13,6 +13,7 @@ Export-Package: org.tizen.dynamicanalyzer.widgets, org.tizen.dynamicanalyzer.widgets.animation, org.tizen.dynamicanalyzer.widgets.button, org.tizen.dynamicanalyzer.widgets.button.checkbox, + org.tizen.dynamicanalyzer.widgets.button.dropdown, org.tizen.dynamicanalyzer.widgets.button.radio, org.tizen.dynamicanalyzer.widgets.button.splitButton, org.tizen.dynamicanalyzer.widgets.button.toggle, @@ -29,4 +30,3 @@ Export-Package: org.tizen.dynamicanalyzer.widgets, org.tizen.dynamicanalyzer.widgets.timeline, org.tizen.dynamicanalyzer.widgets.timer, org.tizen.dynamicanalyzer.widgets.tooltip -Import-Package: org.tizen.dynamicanalyzer.widgets.scale diff --git a/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/dropdown/DACustomDropdown.java b/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/dropdown/DACustomDropdown.java new file mode 100644 index 0000000..df1b208 --- /dev/null +++ b/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/dropdown/DACustomDropdown.java @@ -0,0 +1,1062 @@ +package org.tizen.dynamicanalyzer.widgets.button.dropdown; + +import java.util.ArrayList; +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.tizen.dynamicanalyzer.util.Logger; +import org.tizen.dynamicanalyzer.widgets.DAWidgetConstants; +import org.tizen.dynamicanalyzer.widgets.button.DACustomButton; +import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonAttribute; +import org.tizen.dynamicanalyzer.widgets.button.IDACustomButtonRenderer; +import org.tizen.dynamicanalyzer.widgets.combo.DACustomComboPopupRenderer; +import org.tizen.dynamicanalyzer.widgets.combo.IDACustomComboPopupRenderer; +import org.tizen.dynamicanalyzer.widgets.combo.Messages; +import org.tizen.dynamicanalyzer.widgets.helper.ColorResources; + +public class DACustomDropdown extends Canvas { + public static final int MAX_SIZE = 10; + public static final int STATE_NORMAL = 0; + public static final int STATE_HOVER = 1; + public static final int STATE_PUSH = 2; + public static final int STATE_DISABLE = 3; + public static final int STATE_DROP = 4; + + public static final int TEXT_ALIGN_CENTER = SWT.CENTER; + public static final int TEXT_ALIGN_LEFT = SWT.LEFT; + public static final int TEXT_ALIGN_RIGHT = SWT.RIGHT; + + public static final int TYPE_IMAGE = 0; + public static final int TYPE_COLOR = 1; + public static final int TYPE_GRADATION = 2; + + private static final int pageSize = 5; + + Composite parent; + private Canvas dropdown = null; + private Canvas popup = null; + private int itemHeight = 0; + private int tmpItemIndex = 0; + private int itemIndex = 0; + private boolean dirty = false; + private Timer closeTimer = null; + private static final int CLOSE_WAITING_TIME = 500; + private List items; + private List rects = null; + private boolean enabled = true; + private Shell childShell = null; + private Shell parentShell = null; + private int selection = 0; + private int tmpSelection = 0; + private Font itemFont = null; + private Color itemFontColor = null; + private IDACustomComboPopupRenderer popupRenderer = new DACustomComboPopupRenderer(); + + //Tooltip Disabled + //private DACustomdropdownTooltip tooltip = null; + + // dropdown button + private int state = STATE_NORMAL; // 0 normal 1 hover 2 push 3 disable + protected DACustomButtonAttribute attr; + private boolean showSelectedText = true; + private DACustomDropdownRenderer dropdownRenderer = new DACustomDropdownRenderer(); + + // arrow button + private static final int arrowButtonHeight = 15; + private DACustomButton upArrowButton = null; + private DACustomButton downArrowButton = null; + private Image buttonUp = null; + private Image buttonDown = null; + private List arrowColors = null; + private List arrowOutlineColors = null; + private List arrowImages = null; + private IDACustomButtonRenderer buttonRenderer = null; + + public DACustomDropdown(Composite parent, int style) { + super(parent, style); + dropdown = this; + + this.parent = parent; + parentShell = parent.getShell(); + parentShell.addListener(SWT.Move, parentShellListener); + addPaintListener(dropdownPaintListener); + setForeground(ColorResources.WHITE); + addListeners(); + initdropdown(); + attr = new DACustomButtonAttribute(); + attr.setAlign(TEXT_ALIGN_LEFT); + } + + protected void addListeners() { + addListener(SWT.MouseEnter, dropdownMouseListener); + addListener(SWT.MouseHover, dropdownMouseListener); + addListener(SWT.MouseExit, dropdownMouseListener); + addListener(SWT.MouseDown, dropdownMouseListener); + addListener(SWT.MouseMove, dropdownMouseListener); + addListener(SWT.MouseUp, dropdownMouseListener); + } + + public void setFontPoint(Point fontPoint) { + attr.setFontPoint(fontPoint); + } + + public String getText() { + if (selection < 0) { + return attr.getText(); + } + if (getItems().size() > 0) { + return getItems().get(itemIndex + selection); + } + return null; + } + + public List getItems() { + if (null == items) { + items = new ArrayList(); + } + return items; + } + + private List getRects() { + if (null == rects) { + rects = new ArrayList(); + } + return rects; + } + + private void changedropdownState(int s) { + state = s; + redraw(); + } + + public void addSelectionListener(DACustomDropdownListener listener) { + popupSelectionListener = listener; + } + + private Listener popupSelectionListener = new DACustomDropdownListener() { + + @Override + public void selectionEvent(DACustomDropdown dropdown) { + // TODO Auto-generated method stub + Logger.debug("default selection" + dropdown.getText()); //$NON-NLS-1$ + } + }; + + private Listener parentShellListener = new Listener() { + @Override + public void handleEvent(Event event) { + if (event.type == SWT.Move) { + if (childShell != null && !childShell.isDisposed()) { + + // Tooltip Disabled + //if (null != tooltip) { + // tooltip.close(); + //} + childShell.close(); + childShell = null; + + } + } + } + }; + + private Listener dropdownMouseListener = new Listener() { + @Override + public void handleEvent(Event event) { + Canvas dropdownArea = (Canvas) event.widget; + Rectangle rect = dropdownArea.getClientArea(); + if (enabled) { + if (event.type == SWT.MouseEnter) { + changedropdownState(STATE_HOVER); + if (null != closeTimer) { + closeTimer.cancel(); + closeTimer = null; + } + } + + if (event.type == SWT.MouseHover) { + if (rect.contains(event.x, event.y)) { + if (0 != (event.stateMask & SWT.BUTTON1)) { + changedropdownState(STATE_PUSH); + } else if (0 == (event.stateMask & SWT.BUTTON1)) { + changedropdownState(STATE_HOVER); + } + } + } + + if (event.type == SWT.MouseDown) { + changedropdownState(STATE_PUSH); + } + + if (event.type == SWT.MouseUp) { + changedropdownState(STATE_HOVER); + if (childShell == null || childShell.isDisposed()) { + if (closeTimer != null) { + closeTimer.cancel(); + closeTimer = null; + } + openChildShell(); + } else { + childShell.close(); + childShell = null; + } + } + + if (event.type == SWT.MouseMove) { + if (!rect.contains(event.x, event.y)) { + changedropdownState(STATE_NORMAL); + } else if (!rect.contains(event.x, event.y)) { + if (0 != (event.stateMask & SWT.BUTTON1)) { + changedropdownState(STATE_PUSH); + } else if (0 == (event.stateMask & SWT.BUTTON1)) { + changedropdownState(STATE_HOVER); + } + } + } + + if (event.type == SWT.MouseExit) { + changedropdownState(STATE_NORMAL); + if (event.x < rect.x || event.x >= rect.x + rect.width + || event.y < rect.y ){ + closePopup(CLOSE_WAITING_TIME); + } + } + } + } + }; + + private int getShellWidth() { + if (getItems().isEmpty()) { + return 0; + } + int max = 0; + int size = items.size(); + GC gc = new GC(parent.getDisplay(), SWT.NONE); + for (int i = 0; i < size; i++) { + Point p = gc.textExtent(items.get(i), SWT.DRAW_MNEMONIC); + if (p.x > max) { + max = p.x; + } + } + max += 10; + gc.dispose(); + return max; + } + + public int getItemHeight() { + return itemHeight; + } + + public void setItemHeight(int height) { + itemHeight = height; + } + + private void openChildShell() { + childShell = new Shell(parent.getShell(), SWT.NO_TRIM); + childShell.setLayout(new FormLayout()); + Point p = dropdown.toDisplay(0, 0); + Rectangle rect = dropdown.getBounds(); + int size = getItems().size(); + + int boundSize = (size > MAX_SIZE) ? MAX_SIZE : (size > 0) ? size : 1; + + int textSize = getShellWidth() + 4; + int shellWidth = (textSize > rect.width) ? textSize : rect.width; + int height = 0; + + if (getItemHeight() == 0) { + height = rect.height; + } else { + height = getItemHeight(); + } + int shellHeight = height * boundSize + 5; + + childShell.setSize(shellWidth, shellHeight); + childShell.setLocation(p.x, p.y + rect.height); + childShell.addDisposeListener(new DisposeListener() { + + @Override + public void widgetDisposed(DisposeEvent e) { + if (null != closeTimer) { + closeTimer.cancel(); + closeTimer = null; + } + } + }); + setSelect(attr.getText()); + + tmpSelection = selection; + tmpItemIndex = itemIndex; + + popup = new Canvas(childShell, SWT.DOUBLE_BUFFERED); + popup.setData(this); + popup.setBackground(ColorResources.WHITE); + popup.addPaintListener(popupPaintListener); + popup.addListener(SWT.MouseUp, popupMouseEventListener); + popup.addListener(SWT.MouseMove, popupMouseEventListener); + popup.addListener(SWT.FocusIn, popupMouseEventListener); + popup.addListener(SWT.MouseUp, popupSelectionListener); + popup.addListener(SWT.MouseWheel, popupMouseEventListener); + popup.addListener(SWT.MouseExit, popupMouseEventListener); + popup.addListener(SWT.MouseEnter, popupMouseEventListener); + + if (size > MAX_SIZE) { + upArrowButton = makeButton(); + if (buttonUp == null) { + upArrowButton.setText(Messages.DACustomCombo_1); + } else { + upArrowButton.setButtonImages(buttonUp, buttonUp, buttonUp, buttonUp); + } + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + data.height = arrowButtonHeight; + upArrowButton.setLayoutData(data); + upArrowButton.addListener(SWT.MouseExit, upButtonMouseListener); + upArrowButton.addListener(SWT.MouseEnter, upButtonMouseListener); + upArrowButton.addListener(SWT.MouseUp, upButtonMouseListener); + upArrowButton.addListener(SWT.FocusIn, upButtonMouseListener); + shellHeight += arrowButtonHeight; + if (tmpItemIndex > 0) { + upArrowButton.setButtonEnabled(true); + } else { + upArrowButton.setButtonEnabled(false); + } + + data = new FormData(); + data.top = new FormAttachment(upArrowButton, 0); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + data.height = height * boundSize + 5 - 2; + popup.setLayoutData(data); + + downArrowButton = makeButton(); + if (null == buttonDown) { + downArrowButton.setText(Messages.DACustomCombo_2); + } else { + downArrowButton.setButtonImages(buttonDown, buttonDown, buttonDown, + buttonDown); + } + data = new FormData(); + data.top = new FormAttachment(popup, 0); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + data.height = arrowButtonHeight; + downArrowButton.setLayoutData(data); + downArrowButton.addListener(SWT.MouseExit, downButtonMouseListener); + downArrowButton.addListener(SWT.MouseEnter, downButtonMouseListener); + downArrowButton.addListener(SWT.MouseUp, downButtonMouseListener); + downArrowButton.addListener(SWT.FocusIn, downButtonMouseListener); + shellHeight += arrowButtonHeight; + if (tmpItemIndex + MAX_SIZE < size - 1) { + downArrowButton.setButtonEnabled(true); + } else { + downArrowButton.setButtonEnabled(false); + } + + childShell.setSize(shellWidth, shellHeight); + } else { + FormData data = new FormData(); + data.top = new FormAttachment(0, 0); + data.left = new FormAttachment(0, 0); + data.right = new FormAttachment(100, 0); + data.height = shellHeight - 2; + popup.setLayoutData(data); + } + + getRects().clear(); + for (int i = 0; i < boundSize; i++) { + Rectangle r = new Rectangle(2, 2 + i * height, shellWidth - 2, height); + getRects().add(r); + } + childShell.open(); + } + + private PaintListener popupPaintListener = new PaintListener() { + + @Override + public void paintControl(PaintEvent e) { + List items = getItems(); + List input = new ArrayList(); + int size = (items.size() > MAX_SIZE) ? MAX_SIZE : items.size(); + for (int i = 0; i < size; i++) { + input.add(items.get(tmpItemIndex + i)); + } + if (input.size() != getRects().size()) { + int inputSize = input.size(); + int rectsSize = getRects().size(); + + if (inputSize > rectsSize) { + reAdjustRectsAdd(rectsSize, inputSize); + } + if (inputSize < rectsSize) { + reAdjustRectsRemove(rectsSize, inputSize); + } + popupRenderer.draw(e.gc, popup, getRects(), tmpSelection, + input, itemFont, itemFontColor); + childShell.close(); + childShell = null; + openChildShell(); + redraw(); + //Tooltip Disabled + //setTooltip(tooltip); + + } else { + popupRenderer.draw(e.gc, popup, getRects(), tmpSelection, + input, itemFont, itemFontColor); + } + + } + }; + + public void reAdjustRectsAdd(int sizeofRects, int sizeofInput){ + for(int i = sizeofRects; i rect.width) ? textSize : rect.width; + int height = 0; + if (getItemHeight() == 0) { + height = rect.height; + } else { + height = getItemHeight(); + } + Rectangle r = new Rectangle(2, 50 + i * height, shellWidth - 2, height); + getRects().add(i, r); + } + } + + public void reAdjustRectsRemove(int sizeofRects, int sizeofInput){ + for(int i = sizeofInput; i= size) { + int lower = size - index; + selection = MAX_SIZE - lower; + itemIndex = size - MAX_SIZE; + select(selection); + } else { + if (index >= MAX_SIZE) { + itemIndex = index / MAX_SIZE; + itemIndex *= MAX_SIZE; + index %= MAX_SIZE; + } + + selection = index; + select(selection); + } + return true; + } + + public void upEvent() { + if (isShowSelectedText()) { + if (getItems().size() > 0) { + setText(getItems().get(itemIndex + selection)); + } + } else if (null != attr.getText()) { + setText(attr.getText()); + } else { + setText(DAWidgetConstants.EMPTY_STRING); + } + if (childShell != null) { + childShell.close(); + } + childShell = null; + } + + private Listener popupMouseEventListener = new Listener() { + + @Override + public void handleEvent(Event event) { + if (event.type == SWT.MouseMove) { + List rs = getRects(); + int size = rs.size(); + for (int i = 0; i < size; i++) { + if (rs.get(i).contains(event.x, event.y)) { + tmpSelection = i; + popup.redraw(); + break; + } + } + } + + if (event.type == SWT.MouseUp) { + selection = tmpSelection; + itemIndex = tmpItemIndex; + } + + if (event.type == SWT.MouseWheel) { + int size = getItems().size(); + if (null != downArrowButton && !downArrowButton.isDisposed() + && null != upArrowButton && !upArrowButton.isDisposed()) { + if (event.count < 0) { + if (tmpItemIndex - event.count + MAX_SIZE >= size - 1) { + tmpItemIndex = size - MAX_SIZE; + downArrowButton.setButtonEnabled(false); + } else { + tmpItemIndex -= event.count; + } + + if (tmpItemIndex > 0) { + upArrowButton.setButtonEnabled(true); + } + } else { + + if (tmpItemIndex - event.count < 0) { + tmpItemIndex = 0; + upArrowButton.setButtonEnabled(false); + } else { + tmpItemIndex -= event.count; + } + + if (tmpItemIndex + event.count < size - 1) { + downArrowButton.setButtonEnabled(true); + } + } + popup.redraw(); + } + } + + if (event.type == SWT.MouseExit) { + Canvas canvas = (Canvas) event.widget; + Rectangle rect = canvas.getClientArea(); + if (event.x < rect.x || event.x >= rect.x + rect.width + || event.y < rect.y || event.y >= rect.y + rect.height) { + closePopup(CLOSE_WAITING_TIME); + } + } + + if (event.type == SWT.MouseEnter || event.type == SWT.FocusIn) { + if (null != closeTimer) { + closeTimer.cancel(); + closeTimer = null; + } + } + + // tooltip open and move + // if (event.type == SWT.MouseEnter || event.type == SWT.MouseMove) { + // if ((null != tooltip) && (tmpSelection >= 0)) { + // tooltip.setSeletedItem(items.get(tmpItemIndex + tmpSelection)); + // tooltip.openAndMove(childShell); + // } + // } + } + }; + + // Tooltip Disabled + //public void setTooltip(DACustomdropdownTooltip tooltip) { + // this.tooltip = tooltip; + //} + + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + this.enabled = enabled; + if (enabled) { + changedropdownState(STATE_NORMAL); + setBackgroundImageAndColor(STATE_NORMAL); + } else { + changedropdownState(STATE_DISABLE); + setBackgroundImageAndColor(STATE_DISABLE); + + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + if (null != childShell && !childShell.isDisposed()) { + childShell.close(); + childShell = null; + } + } + }); + } + } + + private void setBackgroundImageAndColor(int state) { + int drawType = attr.getDrawType(); + if (drawType == TYPE_IMAGE) { + setBackgroundImage(attr.getImage(state)); + } else if (drawType == TYPE_COLOR) { + setBackground(attr.getColor(state)); + } else if (drawType == TYPE_GRADATION) { + int index = state * 2; + setForeground(attr.getColor(index)); + setBackground(attr.getColor(index + 1)); + } else { + Logger.debug("DACustomdropdown drawType : " + state); + } + } + + private PaintListener dropdownPaintListener = new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + dropdownRenderer.draw(e.gc, dropdown, state, attr, isChildShellOpened()); + } + }; + + public void setdropdownRender(DACustomDropdownRenderer newRenderer) { + dropdownRenderer = newRenderer; + } + + public void setdropdownPopupRender(DACustomComboPopupRenderer newRenderer) { + popupRenderer = newRenderer; + } + + public void add(String item) { + if (dirty) { + getItems().add(item); + } else { + getItems().set(0, item); + dirty = true; + } + } + + public void select(int index) { + selection = index; + if (isShowSelectedText()) { + String text = items.get(itemIndex + selection); + attr.setText(text); + this.setToolTipText(text); + } + redraw(); + } + + public String getItem(int index) { + if (getItems().size() > 0) { + return getItems().get(index); + } + return DAWidgetConstants.EMPTY_STRING; + } + + public void setdropdownColors(Color normal, Color push, Color hover, Color disable) { + attr.setColor(STATE_NORMAL, normal); + attr.setColor(STATE_HOVER, hover); + attr.setColor(STATE_PUSH, push); + attr.setColor(STATE_DISABLE, disable); + attr.setDrawType(TYPE_COLOR); + } + + public void setdropdownGradation(Color normalStart, Color normalEnd, Color pushStart, + Color pushEnd, Color hoverStart, Color hoverEnd, Color disableStart, + Color disableEnd) { + attr.setColor(0, normalStart); + attr.setColor(1, normalEnd); + attr.setColor(2, hoverStart); + attr.setColor(3, hoverEnd); + attr.setColor(4, pushStart); + attr.setColor(5, pushEnd); + attr.setColor(6, disableStart); + attr.setColor(7, disableEnd); + attr.setDrawType(TYPE_GRADATION); + } + + public void setImages(Image normal, Image hover, Image push, Image disable) { + if (null == normal || null == hover || null == push || null == disable) { + Logger.debug("DACustomdropdown setImages parameter is null"); + return; + } + attr.setImage(STATE_NORMAL, normal); + attr.setImage(STATE_HOVER, hover); + attr.setImage(STATE_PUSH, push); + attr.setImage(STATE_DISABLE, disable); + attr.setDrawType(TYPE_IMAGE); + } + + public void setOutlineColors(Color normal, Color push, Color hover, Color disable) { + attr.setOutlineColor(STATE_NORMAL, normal); + attr.setOutlineColor(STATE_HOVER, hover); + attr.setOutlineColor(STATE_PUSH, push); + attr.setOutlineColor(STATE_DISABLE, disable); + } + + public void setdropdownImages(Image normal, Image push, Image hover, Image disable) { + attr.setButtonImage(STATE_NORMAL, normal); + attr.setButtonImage(STATE_HOVER, hover); + attr.setButtonImage(STATE_PUSH, push); + attr.setButtonImage(STATE_DISABLE, disable); + } + + public void setdropdownImagePoint(Point dropdownImagePoint) { + attr.setButtonImagePoint(dropdownImagePoint); + } + + private Listener upButtonMouseListener = new Listener() { + @Override + public void handleEvent(Event event) { + DACustomButton upButton = (DACustomButton) event.widget; + Rectangle rect = upButton.getBounds(); + + if (event.type == SWT.MouseExit) { + if (event.y < rect.y || + event.x < rect.x || event.x >= rect.x + rect.width) { + closePopup(CLOSE_WAITING_TIME); + } + } + + if (event.type == SWT.MouseEnter || event.type == SWT.FocusIn) { + if (null != closeTimer) { + closeTimer.cancel(); + closeTimer = null; + } + } + + if (event.type == SWT.MouseUp) { + if (!upArrowButton.isButtonEnabled()) { + return; + } + + if (null != upArrowButton) { + Rectangle rectangle = upArrowButton.getBounds(); + int x = event.x; + int y = event.y; + + if (x < 0 || x > rectangle.width || y < 0 || y > rectangle.height) { + return; + } + } + + int size = getItems().size(); + if (tmpItemIndex - pageSize < 0) { + tmpItemIndex = 0; + upArrowButton.setButtonEnabled(false); + } else { + tmpItemIndex -= pageSize; + } + + if (tmpItemIndex + pageSize < size - 1) { + downArrowButton.setButtonEnabled(true); + } + popup.redraw(); + } + + // tooltip close Tooltip Disabled + //if (event.type == SWT.MouseEnter) { + // if (null != tooltip) { + // tooltip.close(); + // } + //} + } + }; + + private Listener downButtonMouseListener = new Listener() { + @Override + public void handleEvent(Event event) { + DACustomButton upButton = (DACustomButton) event.widget; + Rectangle rect = upButton.getClientArea(); + + if (event.type == SWT.MouseExit) { + if ( event.x < rect.x || event.x >= rect.x + rect.width + || event.y >= rect.y + rect.height ){ + closePopup(CLOSE_WAITING_TIME); + } + } + + if (event.type == SWT.MouseEnter || event.type == SWT.FocusIn) { + if (null != closeTimer) { + closeTimer.cancel(); + closeTimer = null; + } + } + + if (event.type == SWT.MouseUp) { + if (!downArrowButton.isButtonEnabled()) { + return; + } + + if (null != downArrowButton) { + Rectangle rectangle = downArrowButton.getBounds(); + int x = event.x; + int y = event.y; + + if (x < 0 || x > rectangle.width || y < 0 || y > rectangle.height) { + return; + } + } + + int size = getItems().size(); + if (tmpItemIndex + pageSize + MAX_SIZE >= size - 1) { + tmpItemIndex = size - MAX_SIZE; + downArrowButton.setButtonEnabled(false); + } else { + tmpItemIndex += pageSize; + } + + if (tmpItemIndex > 0) { + upArrowButton.setButtonEnabled(true); + } + popup.redraw(); + } + + // tooltip close Tooltip Disabled + //if (event.type == SWT.MouseEnter) { + // if (null != tooltip) { + // tooltip.close(); + // } + //} + } + }; + + public boolean isDirty() { + return dirty; + } + + public void initdropdown() { + getItems().clear(); + tmpItemIndex = 0; + selection = 0; + items.add(DAWidgetConstants.EMPTY_STRING); + dirty = false; + itemIndex = 0; + } + + public void initdropdownText(String text) { + getItems().clear(); + tmpItemIndex = 0; + selection = 0; + items.add(text); + dirty = false; + itemIndex = 0; + } + + public void setdropdownButtonColor(Color normal, Color push, Color hover, Color disable) { + arrowColors = new ArrayList(); + arrowColors.add(normal); + arrowColors.add(hover); + arrowColors.add(push); + arrowColors.add(disable); + } + + public void setdropdownButtonImage(Image normal, Image push, Image hover, Image disable) { + arrowImages = new ArrayList(); + arrowImages.add(normal); + arrowImages.add(push); + arrowImages.add(hover); + arrowImages.add(disable); + } + + public void setdropdownButtonGradation(Color normalStart, Color normalEnd, + Color pushStart, Color pushEnd, Color hoverStart, Color hoverEnd, + Color disableStart, Color disableEnd) { + arrowColors = new ArrayList(); + arrowColors.add(normalStart); + arrowColors.add(normalEnd); + arrowColors.add(hoverStart); + arrowColors.add(hoverEnd); + arrowColors.add(pushStart); + arrowColors.add(pushEnd); + arrowColors.add(disableStart); + arrowColors.add(disableEnd); + } + + private List getArrowOutlineColors() { + if (null == arrowOutlineColors) { + arrowOutlineColors = new ArrayList(); + } + return arrowOutlineColors; + } + + public void setArrowOutlineColors(Color normal, Color push, Color hover, Color disable) { + List dropdownArrowOutlineColors = getArrowOutlineColors(); + dropdownArrowOutlineColors.add(normal); + dropdownArrowOutlineColors.add(hover); + dropdownArrowOutlineColors.add(push); + dropdownArrowOutlineColors.add(disable); + } + + private DACustomButton makeButton() { + DACustomButton button = null; + if (arrowImages != null) { + // image + button = new DACustomButton(childShell, arrowImages.get(STATE_NORMAL), + arrowImages.get(STATE_PUSH), arrowImages.get(STATE_HOVER), + arrowImages.get(STATE_DISABLE)); + } else if (arrowColors != null) { + if (arrowColors.size() > 4) { + // gradation + button = new DACustomButton(childShell, arrowColors.get(STATE_NORMAL), + arrowColors.get(STATE_NORMAL + 1), + arrowColors.get(STATE_PUSH * 2), + arrowColors.get(STATE_PUSH * 2 + 1), + arrowColors.get(STATE_HOVER * 2), + arrowColors.get(STATE_HOVER * 2 + 1), + arrowColors.get(STATE_DISABLE * 2), + arrowColors.get(STATE_DISABLE * 2 + 1)); + } else { + // color + button = new DACustomButton(childShell, SWT.NONE); + button.setColors(arrowColors.get(STATE_NORMAL), + arrowColors.get(STATE_PUSH), arrowColors.get(STATE_HOVER), + arrowColors.get(STATE_DISABLE)); + } + + if (arrowOutlineColors != null) { + button.setOutlineColors(arrowOutlineColors.get(STATE_NORMAL), + arrowOutlineColors.get(STATE_PUSH), + arrowOutlineColors.get(STATE_HOVER), + arrowOutlineColors.get(STATE_DISABLE)); + } + } else { + button = new DACustomButton(childShell, SWT.NONE); + } + if (null != buttonRenderer) { + button.setRenderer(buttonRenderer); + } + + return button; + } + + public void setButtonRenderer(IDACustomButtonRenderer renderer) { + buttonRenderer = renderer; + } + + public void setButtonImages(Image up, Image down) { + buttonUp = up; + buttonDown = down; + } + + public boolean isChildShellOpened() { + if (childShell == null || childShell.isDisposed()) { + return false; + } + return true; + } + + public void closePopup(int interval) { + if (null == childShell || childShell.isDisposed()) { + return; + } + closeTimer = new Timer(); + closeTimer.schedule(new TimerTask() { + public void run() { + Display.getDefault().syncExec(new Runnable() { + @Override + public void run() { + if (null != childShell && !childShell.isDisposed()) { + // tooltip close Tooltip Disabled + //if (null != tooltip) { + // tooltip.close(); + //} + + childShell.close(); + childShell = null; + redraw(); + } else { + Logger.debug("dropdown timer bug : try close child shell "); + } + } + }); + } + }, interval); + } + + public void setTextAlign(int align) { + attr.setAlign(align); + } + + public void setdropdownFont(Font font) { + attr.setFont(font); + } + + public void setFontColors(Color normal, Color push, Color hover, Color disable) { + attr.setFontColor(STATE_NORMAL, normal); + attr.setFontColor(STATE_PUSH, push); + attr.setFontColor(STATE_HOVER, hover); + attr.setFontColor(STATE_DISABLE, disable); + } + + public void setItemFontColor(Color itemFontColor) { + this.itemFontColor = itemFontColor; + } + + public boolean isShowSelectedText() { + return showSelectedText; + } + + public void setShowSelectedText(boolean showSelectedText) { + this.showSelectedText = showSelectedText; + } + + public void initDropdown() { + // TODO Auto-generated method stub + + } + + public void setDropdownFont(Font combo) { + // TODO Auto-generated method stub + + } + + public void setDropdownColors(Color black, Color black2, Color black3, Color gRAY_170) { + // TODO Auto-generated method stub + + } + + public void setDropdownImagePoint(Point point) { + // TODO Auto-generated method stub + + } + + public void setDropdownImages(Image dropArrowDownNor, Image dropArrowDownSel, Image dropArrowDownHover, + Image dropArrowDownDim) { + // TODO Auto-generated method stub + + } +} diff --git a/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/dropdown/DACustomDropdownListener.java b/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/dropdown/DACustomDropdownListener.java new file mode 100644 index 0000000..de23fa7 --- /dev/null +++ b/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/dropdown/DACustomDropdownListener.java @@ -0,0 +1,20 @@ +package org.tizen.dynamicanalyzer.widgets.button.dropdown; + +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; + +public abstract class DACustomDropdownListener implements Listener { + + @Override + public void handleEvent(Event event) { + Canvas popup = (Canvas) event.widget; + DACustomDropdown combo = (DACustomDropdown) popup.getData(); + if (null != combo) { + selectionEvent(combo); + combo.upEvent(); + } + } + + public abstract void selectionEvent(DACustomDropdown combo); +} diff --git a/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/dropdown/DACustomDropdownRenderer.java b/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/dropdown/DACustomDropdownRenderer.java new file mode 100644 index 0000000..07268bb --- /dev/null +++ b/org.tizen.dynamicanalyzer.widgets/src/org/tizen/dynamicanalyzer/widgets/button/dropdown/DACustomDropdownRenderer.java @@ -0,0 +1,213 @@ +package org.tizen.dynamicanalyzer.widgets.button.dropdown; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Canvas; +import org.tizen.dynamicanalyzer.util.Logger; +import org.tizen.dynamicanalyzer.widgets.DAWidgetConstants; +import org.tizen.dynamicanalyzer.widgets.button.DACustomButton; +import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonAttribute; +import org.tizen.dynamicanalyzer.widgets.button.IDACustomButtonRenderer; +import org.tizen.dynamicanalyzer.widgets.combo.DACustomCombo; +import org.tizen.dynamicanalyzer.widgets.helper.ColorResources; +import org.tizen.dynamicanalyzer.widgets.helper.FontResources; + +public class DACustomDropdownRenderer implements IDACustomButtonRenderer { + + public static final int STATE_COMBO_DROP = 4; + public static final int DEVICE_COMBO = 0; + public static final int APP_COMBO = 1; + public static final int PROCESS_COMBO = 2; + + public void draw(GC gc, Canvas combo, int state, + DACustomButtonAttribute attr, boolean childOpen) { + Rectangle rect = combo.getClientArea(); + if (attr.getDrawType() == DACustomCombo.TYPE_IMAGE) { + drawImageButton(gc, rect, state, attr); + } else if (attr.getDrawType() == DACustomCombo.TYPE_COLOR + || attr.getDrawType() == DACustomCombo.TYPE_GRADATION) { + drawButton(gc, rect, state, attr, childOpen); + } else { + Logger.debug("DACustomCombo drawType : " + state); + } + } + + protected void drawImageButton(GC gc, Rectangle rect, int state, + DACustomButtonAttribute attr) { + Image image = attr.getImage(state); + if (null == image) { + return; + } + + // draw image + gc.drawImage(image, rect.x, rect.y); + + // draw text + drawButtonText(gc, rect, attr, state); + Rectangle clipping = new Rectangle(rect.x + rect.width - 17, rect.y, 17, rect.height); + gc.setClipping(clipping); + gc.drawImage(image, rect.x, rect.y); + } + + protected void drawButton(GC gc, Rectangle rect, int state, + DACustomButtonAttribute attr, boolean isChildOpen) { + // draw color + if (attr.getDrawType() == DACustomCombo.TYPE_COLOR) { + gc.setBackground(attr.getColor(state)); + gc.fillRectangle(rect); + } else if (attr.getDrawType() == DACustomCombo.TYPE_GRADATION) { + gc.setBackground(attr.getColor(state)); + gc.fillRectangle(rect); + } + + // draw text + drawButtonText(gc, rect, attr, state); + + // stroke + Color c = gc.getForeground(); + Rectangle r = new Rectangle(rect.x, rect.y, rect.width - 1, rect.height - 1); + if (null != attr.getOutlineColor(state)) { + gc.setForeground(ColorResources.GRAY_170); + } else { + gc.setForeground(ColorResources.GRAY_170); + return; + } + //gc.drawRectangle(r); + gc.drawLine(rect.x, rect.y, rect.x + 168, rect.y); + gc.drawLine(rect.x, rect.y + 24 - 1, rect.x + 168 + 10 , rect.y + 24 - 1); + gc.drawLine(rect.x, rect.y, rect.x, rect.y + 24); + + //draw triangle + gc.setForeground(c); + + // draw button image + if(isChildOpen){ + drawButtonImage(gc, rect, attr, STATE_COMBO_DROP); + } + else{ + drawButtonImage(gc, rect, attr, state); + } + } + + protected void drawButtonImage(GC gc, Rectangle rect, + DACustomButtonAttribute attr, int state) { + + if (attr != null) { + Image img = attr.getButtonImage(state); + + if(state == STATE_COMBO_DROP){ + // TODO: Assign image file + img = null; + } + + if(img != null) { + Point p = null; + Rectangle imgRect = img.getBounds(); + + int x = 0, y = 0; + if (null == (p = attr.getButtonImagePoint())) { + int width = rect.width - imgRect.width; + int height = rect.height - imgRect.height; + if (width > 0) { + x = width / 2; + } // else : the image is drawn without the left and right margins. + + if (height > 0) { + y = height / 2; + } // else : the image is drawn without the top and bottom margin. + } else { + // Combo Button text position + x = p.x + 10; + y = p.y; + } + + gc.drawImage(img, x, y); + } // else : imag is null + } // else : attr is null + } + + protected void drawButtonText(GC gc, Rectangle rect, + DACustomButtonAttribute attr, int state) { + Font font = attr.getFont(); + Point fontPoint = attr.getFontPoint(); + String text = attr.getText(); + int align = attr.getAlign(); + + // set font style, size + if (null == font) { + gc.setFont(FontResources.COMBO); + } else { + gc.setFont(font); + } + + // set font color + if (null != attr.getFontColor(state)) { + gc.setForeground(attr.getFontColor(state)); + } else { + if (state == DACustomButton.STATE_DISABLE) { + gc.setForeground(ColorResources.COMBO_DISABLE_FONT); + } else { + gc.setForeground(ColorResources.COMBO_ENABLE_FONT); + } + } + + if (text == null) { + text = DAWidgetConstants.EMPTY_STRING; + } // else case text is not null + + // text position + if (fontPoint == null) { + Point p = gc.textExtent(text, SWT.DRAW_MNEMONIC); + int textX = 0; + if (align == DACustomCombo.TEXT_ALIGN_LEFT) { + textX = 5; + } else if (align == DACustomCombo.TEXT_ALIGN_RIGHT) { + textX = rect.width - p.x; + } else { // DACustomCombo.TEXT_ALIGN_CENTER + textX = (rect.width / 2) - (p.x / 2); + } + String dispText = cuttingTextbyRectWidth(text,gc,rect.width - 60); + gc.drawString(dispText, textX + 10, (rect.height - p.y) / 2, true); + } else { + String dispText = cuttingTextbyRectWidth(text,gc,rect.width - 60); + gc.drawString(dispText, fontPoint.x + 10, fontPoint.y, true); + } + } + + //// cutting String by input Width Pixel + private String cuttingTextbyRectWidth(String srcText, GC gc, int srcWidth){ + + String cutText = ""; + int pixelSize = 0; + int cutIndex = 0; + + for(char ch : srcText.toCharArray()){ + if(gc.getCharWidth(ch) == 1){ + /// char pixel val "1" is not real pixel value... (ex : 'i', 'l' take more 1 pixel) + pixelSize += (gc.getFontMetrics().getAverageCharWidth() / 2); + } + else { + pixelSize += (gc.getCharWidth(ch)); + } + if(pixelSize > srcWidth){ + cutText = srcText.substring(0, cutIndex - 2); + cutText = cutText + "..."; + return cutText; + } + cutIndex++; + } + + return srcText; + } + + @Override + public void draw(GC gc, Canvas canvas, int state, DACustomButtonAttribute attr) { + // TODO Auto-generated method stub + + } +} diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.java index ab4286b..99e8e4e 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.java @@ -189,7 +189,17 @@ public class AnalyzerLabels extends NLS { public static String FIND_DLG_OPTION; public static String FIND_DLG_CASE_SENSITIVE; public static String FIND_DLG_WHOLE_WORD; - + + public static String SEARCH_DLG_TITLE; + public static String SEARCH_DLG_DESC_PREFIX; + public static String SEARCH_DLG_DESC_POSTFIX; + public static String SEARCH_DLG_CANCEL_BUTTON; + public static String SEARCH_DLG_BACK_BUTTON; + public static String SEARCH_DLG_NEXT_BUTTON; + public static String SEARCH_DLG_OPTION; + public static String SEARCH_DLG_CASE_SENSITIVE; + public static String SEARCH_DLG_WHOLE_WORD; + public static String FILTER_DLG_TITLE_PREFIX; public static String FILTER_DLG_TITLE_POSTFIX; public static String FILTER_DLG_ADD_BUTTON; @@ -228,19 +238,23 @@ public class AnalyzerLabels extends NLS { public static String HEAP_MEMORY_WARNING_PRE; public static String HEAP_MEMORY_WARNING_POST; - + public static String TIME_MS; - + public static String DETAIL_INFORMATION_PACKAGE_NAME; public static String DETAIL_INFORMATION_PACKAGE_VERSION; public static String DETAIL_INFORMATION_PACKAGE_INSTALL_TIME; public static String DETAIL_INFORMATION_APPLICATION_NAME; public static String DETAIL_INFORMATION_APPLICATION_EXEC_PATH; - + // advanced menu text public static String ADVANCED_MENU_SEARCH; public static String ADVANCED_MENU_FILTER; - + + // Search dialog + public static String SEARCH_DROPDOWN_TITLE; + public static String SEARCH_DROPDOWN_PID; + static { NLS.initializeMessages(BUNDLE_NAME, AnalyzerLabels.class); } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.properties b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.properties index 6768947..0786f95 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.properties +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/nl/AnalyzerLabels.properties @@ -165,6 +165,16 @@ FIND_DLG_OPTION=Option : FIND_DLG_CASE_SENSITIVE=Case sensitive FIND_DLG_WHOLE_WORD=Whole word +SEARCH_DLG_TITLE=Search +SEARCH_DLG_DESC_PREFIX=Search for +SEARCH_DLG_DESC_POSTFIX= table +SEARCH_DLG_CANCEL_BUTTON=Cancel +SEARCH_DLG_BACK_BUTTON=Back +SEARCH_DLG_NEXT_BUTTON=Next +SEARCH_DLG_OPTION=Option +SEARCH_DLG_CASE_SENSITIVE=Case sensitive +SEARCH_DLG_WHOLE_WORD=Whole word + FILTER_DLG_TITLE_PREFIX=Filter from FILTER_DLG_TITLE_POSTFIX= table FILTER_DLG_ADD_BUTTON=Add @@ -205,3 +215,6 @@ DETAIL_INFORMATION_APPLICATION_EXEC_PATH=Application Exec Path : ADVANCED_MENU_SEARCH=Search ADVANCED_MENU_FILTER=Filter + +SEARCH_DROPDOWN_TITLE=All +SEARCH_DROPDOWN_PID=Pid diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/DAAdvancedPopupMenu.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/DAAdvancedPopupMenu.java index 8b37ec7..b5d0568 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/DAAdvancedPopupMenu.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/DAAdvancedPopupMenu.java @@ -83,8 +83,8 @@ public class DAAdvancedPopupMenu extends DAPopupMenu { public void run() { Shell shell = WorkbenchUtil.getWorkbenchWindow() .getShell(); - FindDialog findDialog = new FindDialog(shell, ownTable); - findDialog.open(); + SearchDialog searchDialog = new SearchDialog(shell, ownTable); + searchDialog.open(); } }); } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/SearchDialog.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/SearchDialog.java new file mode 100644 index 0000000..7d0d071 --- /dev/null +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/SearchDialog.java @@ -0,0 +1,458 @@ +/* + * Dynamic Analyzer + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Jooyoul Lee + * Juyoung Kim + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Contributors: + * - S-Core Co., Ltd + * + */ + +package org.tizen.dynamicanalyzer.ui.widgets; + +import java.util.List; + +import org.eclipse.nebula.widgets.grid.Grid; +import org.eclipse.nebula.widgets.grid.GridItem; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.tizen.dynamicanalyzer.appearance.DesignConstants; +import org.tizen.dynamicanalyzer.common.AnalyzerConstants; +import org.tizen.dynamicanalyzer.constant.CommonConstants; +import org.tizen.dynamicanalyzer.model.FindProperty; +import org.tizen.dynamicanalyzer.nl.AnalyzerLabels; +import org.tizen.dynamicanalyzer.resources.ColorResources; +import org.tizen.dynamicanalyzer.resources.FontResources; +import org.tizen.dynamicanalyzer.resources.ImageResources; +import org.tizen.dynamicanalyzer.ui.widgets.table.DATableComposite; +import org.tizen.dynamicanalyzer.ui.widgets.table.DATreeComposite; +import org.tizen.dynamicanalyzer.widgets.button.DACustomButton; +import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonClickEventListener; +import org.tizen.dynamicanalyzer.widgets.button.DACustomButtonRenderer; +import org.tizen.dynamicanalyzer.widgets.button.checkbox.DACheckBox; +import org.tizen.dynamicanalyzer.widgets.button.checkbox.DACheckboxSelectionListener; +import org.tizen.dynamicanalyzer.widgets.button.dropdown.DACustomDropdown; +import org.tizen.dynamicanalyzer.widgets.da.base.DAButton; +import org.tizen.dynamicanalyzer.widgets.da.base.DAMessageBox; +import org.tizen.dynamicanalyzer.widgets.da.base.DATextBox; + +public class SearchDialog extends DAMessageBox { + + private static final int ENTER_KEY_CODE = 13; + + final private int WIDTH = 430; + final private int HEIGHT = 230 - 7; // Should remove 7 pixel on titlebar area at MAC + + private DACustomDropdown categoryDropdown= null; + private DATextBox textBox = null; + private DAButton cancelButton = null; + private DAButton backButton = null; + private DAButton nextButton = null; + private DACheckBox caseButton = null; + private DACheckBox wholeWordButton = null; + + private FindProperty findProperty = null; + + private Grid table = null; + private String viewName = null; + private Composite composite = null; + + public SearchDialog(Shell parentShell, Composite comp) { + super(parentShell); + if (comp instanceof DATableComposite) { + this.table = ((DATableComposite) comp).getTable(); + viewName = ((DATableComposite) comp).getTableName(); + } else if (comp instanceof DATreeComposite) { + this.table = ((DATreeComposite) comp).getTable(); + viewName = ((DATreeComposite) comp).getTableName(); + } else { + table = null; + return; + } + this.composite = comp; + findProperty = DATableComposite.getFindProferty(); + findProperty.setIndex(table.getSelectionIndex()); + } + + protected boolean run() { + if (null == table) { + return false; + } + int dialogLocationX = shell.getParent().getLocation().x + (shell.getParent().getSize().x - WIDTH)/2; + int dialogLocationY = shell.getParent().getLocation().y + (shell.getParent().getSize().y - HEIGHT)/2; + shell.setLocation(dialogLocationX, dialogLocationY); + shell.setSize(WIDTH, HEIGHT); + shell.setLayout(new FormLayout()); + shell.setText(AnalyzerLabels.SEARCH_DLG_TITLE); + shell.setBackground(ColorResources.DIALOG_BG_UPPER); + shell.addPaintListener(new PaintListener() { + public void paintControl(PaintEvent e) { + e.gc.setForeground(ColorResources.DIALOG_TOP_LINE_COLOR); + e.gc.drawLine(0, 0, WIDTH, 0); + e.gc.setForeground(ColorResources.DIALOG_BUTTON_LINE_COLOR); + e.gc.drawLine(0, 139, WIDTH, 139); + } + }); + + Composite contentComp = new Composite(shell, SWT.NONE); + FormLayout contentLayout = new FormLayout(); + contentComp.setLayout(contentLayout); + contentComp.setBackground(ColorResources.DIALOG_CONTENT_BACKGROUND); + + FormData data = new FormData(); + data.top = new FormAttachment(0, 1); + data.left = new FormAttachment(0, 0); + data.width = WIDTH; + data.height = 138; + contentComp.setLayoutData(data); + + Label descriptionLabel = new Label(contentComp, SWT.TRANSPARENT); + data = new FormData(); + data.top = new FormAttachment(0, 30); + data.left = new FormAttachment(0, 20); + data.height = 26; + data.width = WIDTH-20; + descriptionLabel.setLayoutData(data); + descriptionLabel.setBackground(ColorResources.DIALOG_CONTENT_BACKGROUND); + descriptionLabel.setForeground(ColorResources.DIALOG_TEXT_FONT_COLOR); + descriptionLabel.setText(AnalyzerLabels.SEARCH_DLG_DESC_PREFIX + + CommonConstants.SPACE + viewName + CommonConstants.SPACE + + AnalyzerLabels.SEARCH_DLG_DESC_POSTFIX); + + categoryDropdown = makeDACustomDropdown(contentComp); + data = new FormData(); + data.top = new FormAttachment(0, 30+26); + data.left = new FormAttachment(0, 20); + data.height = 24; + data.width = 96; + categoryDropdown.setLayoutData(data); + categoryDropdown.addListener(SWT.Selection, dropdownListener); + + textBox = new DATextBox(contentComp, SWT.SINGLE); + data = new FormData(); + data.top = new FormAttachment(0, 30+26); + data.left = new FormAttachment(0, 20+96+10); + data.height = 24; + data.width = 284; + textBox.setLayoutData(data); + textBox.setBackground(ColorResources.WHITE); + textBox.setForeground(ColorResources.BLACK); + // TODO: TextBox set outline color + // TODO: TextBox font size, cursor location + textBox.getControl().addKeyListener(keyListener); + textBox.setText(findProperty.getLastSearch()); + textBox.getControl().setSelection(0, findProperty.getLastSearch().length()); + + Label optionLabel = new Label(contentComp, SWT.TRANSPARENT); + data = new FormData(); + data.top = new FormAttachment(0, 30+26+24+16); + data.left = new FormAttachment(0, 20); + data.height = 14; + data.width = 40 + 66; + optionLabel.setLayoutData(data); + optionLabel.setBackground(ColorResources.DIALOG_CONTENT_BACKGROUND); + optionLabel.setForeground(ColorResources.DIALOG_TEXT_FONT_COLOR); + optionLabel.setText(AnalyzerLabels.SEARCH_DLG_OPTION); + + caseButton = new DACheckBox(contentComp, SWT.NONE); + data = new FormData(); + data.top = new FormAttachment(0, 30+26+24+16); + data.left = new FormAttachment(optionLabel, 0); + data.height = 14; + data.width = 14 + 4 + 80 + 38; + caseButton.setLayoutData(data); + caseButton.setBackground(ColorResources.DIALOG_CONTENT_BACKGROUND); + caseButton.setForeground(ColorResources.DIALOG_TEXT_FONT_COLOR); + caseButton.setText(AnalyzerLabels.SEARCH_DLG_CASE_SENSITIVE); + caseButton.addSelectionListener(caseButtonListener); + caseButton.setChecked(findProperty.isCaseSensitive()); + + wholeWordButton = new DACheckBox(contentComp, SWT.NONE); + data = new FormData(); + data.top = new FormAttachment(0, 30+26+24+16); + data.left = new FormAttachment(caseButton, 0); + data.height = 14; + data.width = 14 + 4 + 130; + wholeWordButton.setLayoutData(data); + wholeWordButton.setBackground(ColorResources.DIALOG_CONTENT_BACKGROUND); + wholeWordButton.setForeground(ColorResources.DIALOG_TEXT_FONT_COLOR); + wholeWordButton.setText(AnalyzerLabels.SEARCH_DLG_WHOLE_WORD); + wholeWordButton.addSelectionListener(wholeWordButtonListener); + wholeWordButton.setChecked(findProperty.isWholeWord()); + + Composite buttonComp = new Composite(shell, SWT.NONE); + FormLayout buttonLayout = new FormLayout(); + buttonComp.setLayout(buttonLayout); + buttonComp.setBackground(ColorResources.DIALOG_BUTTON_BACKGROUND); + + data = new FormData(); + data.top = new FormAttachment(0, 140); + data.left = new FormAttachment(0, 0); + data.width = WIDTH; + data.height = 60; + buttonComp.setLayoutData(data); + + cancelButton = new DAButton(buttonComp, SWT.NONE); + data = new FormData(); + data.top = new FormAttachment(0, 17); + data.left = new FormAttachment(100, DesignConstants.DA_BUTTON_WIDTH*(-1)*3-20-20); + data.height = 25; + data.width = DesignConstants.DA_BUTTON_WIDTH; + cancelButton.setLayoutData(data); + cancelButton.setText(AnalyzerLabels.SEARCH_DLG_CANCEL_BUTTON); + cancelButton.addClickListener(cancelButtonListener); + + backButton = new DAButton(buttonComp, SWT.NONE); + data = new FormData(); + data.top = new FormAttachment(0, 17); + data.left = new FormAttachment(100, DesignConstants.DA_BUTTON_WIDTH*(-1)*2-20-10); + data.height = 25; + data.width = DesignConstants.DA_BUTTON_WIDTH; + backButton.setLayoutData(data); + backButton.setText(AnalyzerLabels.SEARCH_DLG_BACK_BUTTON); + backButton.addClickListener(backButtonListener); + + nextButton = new DAButton(buttonComp, SWT.NONE); + data = new FormData(); + data.top = new FormAttachment(0, 17); + data.left = new FormAttachment(100, DesignConstants.DA_BUTTON_WIDTH*(-1)*1-20); + data.height = 25; + data.width = DesignConstants.DA_BUTTON_WIDTH; + nextButton.setLayoutData(data); + nextButton.setText(AnalyzerLabels.SEARCH_DLG_NEXT_BUTTON); + nextButton.addClickListener(nextButtonListener); + + updateCategoryDropdown(); + return true; + } + + private DACustomButtonClickEventListener cancelButtonListener = new DACustomButtonClickEventListener() { + + @Override + public void handleClickEvent(DACustomButton button) { + shell.close(); + } + }; + + private DACustomButtonClickEventListener backButtonListener = new DACustomButtonClickEventListener() { + + @Override + public void handleClickEvent(DACustomButton button) { + findProperty.setBackward(true); + findProperty.setLastSearch(textBox.getText()); + executeFindCommand(); + } + }; + + private DACustomButtonClickEventListener nextButtonListener = new DACustomButtonClickEventListener() { + + @Override + public void handleClickEvent(DACustomButton button) { + findProperty.setBackward(false); + findProperty.setLastSearch(textBox.getText()); + executeFindCommand(); + } + }; + + private KeyListener keyListener = new KeyListener() { + + @Override + public void keyReleased(KeyEvent e) { + if (null != textBox.getText() && !textBox.getText().isEmpty()) { + nextButton.setButtonEnabled(true); + + if (e.keyCode == ENTER_KEY_CODE) { + findProperty.setLastSearch(textBox.getText()); + executeFindCommand(); + } + } else { + nextButton.setButtonEnabled(false); + } + } + + @Override + public void keyPressed(KeyEvent e) { + } + }; + + private DACheckboxSelectionListener caseButtonListener = new DACheckboxSelectionListener() { + + @Override + public void handleSelectionEvent(DACheckBox checkbox) { + findProperty.setCaseSensitive(!findProperty.isCaseSensitive()); + caseButton.setChecked(findProperty.isCaseSensitive()); + } + }; + + private DACheckboxSelectionListener wholeWordButtonListener = new DACheckboxSelectionListener() { + + @Override + public void handleSelectionEvent(DACheckBox checkbox) { + findProperty.setWholeWord(!findProperty.isWholeWord()); + wholeWordButton.setChecked(findProperty.isWholeWord()); + } + }; + + private boolean executeFindCommand() { + + int index = findProperty.getIndex(); + GridItem[] items = table.getItems(); + int itemCount = items.length; + String selectedColumn = categoryDropdown.getText(); + + if (itemCount != 0) { + if (findProperty.isBackward()) { + index = (index - 1 < 0) ? itemCount - 1 : index - 1; + } else { + index = (index + 1 > itemCount - 1) ? 0 : index + 1; + } + int findIndex = -1; + findProperty.setIndex(index); + if (composite instanceof DATableComposite) { + findIndex = ((DATableComposite) composite) + .searchString(findProperty); + } else if (composite instanceof DATreeComposite) { + findIndex = ((DATreeComposite) composite) + .searchString(findProperty); + } else { + return false; + } + findProperty.setIndex(findIndex); + return true; + } + return false; + } + + public DACustomDropdown getCategoryDropdown() { + return categoryDropdown; + } + + private Listener dropdownListener = new Listener() { + + @Override + public void handleEvent(Event event) { + // TODO Auto-generated method stub + // TODO: implement + // Selected item should limit to searching area as column + return; + } + }; + + private boolean selectCategoryDropdown(String item) { + // TODO: implement + boolean ret = false; + + List categoryList = categoryDropdown.getItems(); + int size = categoryList.size(); + for (int i = 0 ; i < size ; i++) { + //ret = table.getCategory(item); + if (ret) { + categoryDropdown.select(i); + if (!item.isEmpty()) { + categoryDropdown.setToolTipText(item); + } + } + } + return ret; + } + + public boolean setCategory(final String text) { + // TODO: implement, At launch search dialog, possible category have to setted. + return true; + } + + public boolean updateCategoryDropdown() { + categoryDropdown.add("All"); + /* TODO: Add column by init or update + categoryDropdown.add("Pid"); + categoryDropdown.add("Tid"); + categoryDropdown.add("Tag"); + categoryDropdown.add("Message"); + */ + categoryDropdown.select(0); + redrawDropdown(categoryDropdown); + return true; + } + + private void redrawDropdown(final DACustomDropdown dropdown) { + Display.getDefault().asyncExec(new Runnable() { + public void run() { + dropdown.redraw(); + } + }); + } + + private DACustomDropdown makeDACustomDropdown(Composite parent) { + DACustomDropdown dropdown = new DACustomDropdown(parent, SWT.NONE); + dropdown.setdropdownGradation(ColorResources.WHITE, + ColorResources.WHITE, ColorResources.WHITE, + ColorResources.WHITE, ColorResources.WHITE, + ColorResources.WHITE, ColorResources.WHITE, + ColorResources.WHITE); + dropdown.setOutlineColors(ColorResources.GRAY_130, + ColorResources.GRAY_130, + ColorResources.GRAY_130, + ColorResources.GRAY_130); + dropdown.setDropdownImages(ImageResources.DROP_ARROW_DOWN_NOR, + ImageResources.DROP_ARROW_DOWN_SEL, + ImageResources.DROP_ARROW_DOWN_HOVER, + ImageResources.DROP_ARROW_DOWN_DIM); + dropdown.setDropdownImagePoint(new Point(90, 9)); + dropdown.setdropdownButtonColor(ColorResources.WHITE, + ColorResources.WHITE, + ColorResources.WHITE, + ColorResources.WHITE); + dropdown.setArrowOutlineColors(ColorResources.GRAY_220, + ColorResources.GRAY_220, + ColorResources.GRAY_220, + ColorResources.GRAY_220); + dropdown.setButtonImages(ImageResources.COMBO_DROPDOWN_UP, + ImageResources.COMBO_DROPDOWN_DOWN); + dropdown.setFontPoint(new Point(5, 5)); + dropdown.setEnabled(true); + dropdown.setDropdownFont(FontResources.COMBO); + dropdown.setItemFont(FontResources.DROPDOWN); + dropdown.setDropdownColors(ColorResources.BLACK, + ColorResources.BLACK, + ColorResources.BLACK, + ColorResources.BLACK); + dropdown.setButtonRenderer(new DACustomButtonRenderer()); + + return dropdown; + } + + public boolean updateCategoryDropdown(String newItem) { + // TODO: Add item to dropdown at start dialog + categoryDropdown.add(newItem); + return true; + } +} diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/table/DATableComposite.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/table/DATableComposite.java index 6573373..9013eab 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/table/DATableComposite.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/table/DATableComposite.java @@ -70,7 +70,7 @@ import org.tizen.dynamicanalyzer.ui.common.PopupAnalysisMenuItemClickListener; import org.tizen.dynamicanalyzer.ui.range.RangeDataManager; import org.tizen.dynamicanalyzer.ui.widgets.DAGrid; import org.tizen.dynamicanalyzer.ui.widgets.FilterDialog; -import org.tizen.dynamicanalyzer.ui.widgets.FindDialog; +import org.tizen.dynamicanalyzer.ui.widgets.SearchDialog; import org.tizen.dynamicanalyzer.util.Logger; import org.tizen.dynamicanalyzer.util.WorkbenchUtil; import org.tizen.dynamicanalyzer.widgets.popupMenu.DAPopupMenu; @@ -230,7 +230,7 @@ public abstract class DATableComposite extends Composite { ctrlPressed = false; if (findEnabled) { Shell shell = WorkbenchUtil.getWorkbenchWindow().getShell(); - FindDialog dialog = new FindDialog(shell, me); + SearchDialog dialog = new SearchDialog(shell, me); dialog.open(); } } diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/table/DAWindowingTableComposite.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/table/DAWindowingTableComposite.java index a3c73f7..103818f 100644 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/table/DAWindowingTableComposite.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/table/DAWindowingTableComposite.java @@ -51,7 +51,7 @@ import org.tizen.dynamicanalyzer.model.FindProperty; import org.tizen.dynamicanalyzer.model.TableInput; import org.tizen.dynamicanalyzer.resources.ColorResources; import org.tizen.dynamicanalyzer.ui.widgets.DAGrid; -import org.tizen.dynamicanalyzer.ui.widgets.FindDialog; +import org.tizen.dynamicanalyzer.ui.widgets.SearchDialog; import org.tizen.dynamicanalyzer.util.CommonUtil; import org.tizen.dynamicanalyzer.util.Logger; import org.tizen.dynamicanalyzer.util.WorkbenchUtil; @@ -199,7 +199,7 @@ public abstract class DAWindowingTableComposite extends DATableComposite { ctrlPressed = false; if (findEnabled) { Shell shell = WorkbenchUtil.getWorkbenchWindow().getShell(); - FindDialog dialog = new FindDialog(shell, me); + SearchDialog dialog = new SearchDialog(shell, me); dialog.open(); } }