From fc16f56e2a95e23be6cf86ccfe7d4a6d3603baab Mon Sep 17 00:00:00 2001 From: Shireesh Anjal Date: Tue, 8 Mar 2011 22:06:42 +0530 Subject: Removed unnecessary plugin com.sun.jersey, introduced image caching. --- .../management/gui/EntityGroupContentProvider.java | 1 + .../management/gui/actions/AddServerAction.java | 3 +- .../management/gui/actions/CreateVolumeAction.java | 1 + .../storage/management/gui/utils/DatePicker.java | 531 --------- .../management/gui/utils/DatePickerCombo.java | 1142 -------------------- .../gui/utils/DiskViewerEditingSupport.java | 57 - .../storage/management/gui/utils/GUIHelper.java | 7 +- .../management/gui/utils/HyperlinkCellEditor.java | 68 -- .../storage/management/gui/utils/ImageUtil.java | 51 + .../storage/management/gui/utils/LRUCache.java | 55 + .../management/gui/views/details/DisksPage.java | 2 - .../gui/views/details/TabCreatorFactoryImpl.java | 1 + .../gui/views/navigator/ClusterAdapterFactory.java | 3 + .../navigator/NavigationTreeLabelDecorator.java | 1 + 14 files changed, 118 insertions(+), 1805 deletions(-) delete mode 100644 com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/DatePicker.java delete mode 100644 com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/DatePickerCombo.java delete mode 100644 com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/DiskViewerEditingSupport.java delete mode 100644 com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/HyperlinkCellEditor.java create mode 100644 com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/ImageUtil.java create mode 100644 com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/LRUCache.java (limited to 'com.gluster.storage.management.gui/src/com/gluster') diff --git a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/EntityGroupContentProvider.java b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/EntityGroupContentProvider.java index 0ff9937f..26848eef 100644 --- a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/EntityGroupContentProvider.java +++ b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/EntityGroupContentProvider.java @@ -34,6 +34,7 @@ public class EntityGroupContentProvider implements } + @SuppressWarnings("rawtypes") @Override public Object[] getElements(Object inputElement) { if (inputElement instanceof EntityGroup) { diff --git a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java index f621f308..559c5357 100644 --- a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java +++ b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/AddServerAction.java @@ -20,8 +20,6 @@ package com.gluster.storage.management.gui.actions; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.IWorkbenchWindowActionDelegate; import com.gluster.storage.management.core.model.EntityGroup; import com.gluster.storage.management.core.model.Volume; @@ -37,6 +35,7 @@ public class AddServerAction extends AbstractActionDelegate { System.out.println("Disposing [" + this.getClass().getSimpleName() + "]"); } + @SuppressWarnings("rawtypes") @Override public void selectionChanged(IAction action, ISelection selection) { super.selectionChanged(action, selection); diff --git a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CreateVolumeAction.java b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CreateVolumeAction.java index da6768b2..07804c3e 100644 --- a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CreateVolumeAction.java +++ b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/actions/CreateVolumeAction.java @@ -42,6 +42,7 @@ public class CreateVolumeAction extends AbstractActionDelegate { window = null; } + @SuppressWarnings("rawtypes") @Override public void selectionChanged(IAction action, ISelection selection) { super.selectionChanged(action, selection); diff --git a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/DatePicker.java b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/DatePicker.java deleted file mode 100644 index 63d99eed..00000000 --- a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/DatePicker.java +++ /dev/null @@ -1,531 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Gluster, Inc. - * This file is part of Gluster Management Console. - * - * Gluster Management Console is free software; you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Gluster Management Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * . - *******************************************************************************/ -package com.gluster.storage.management.gui.utils; - -import java.text.DateFormatSymbols; -import java.util.Calendar; -import java.util.Date; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ControlAdapter; -import org.eclipse.swt.events.ControlEvent; -import org.eclipse.swt.events.KeyAdapter; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseMoveListener; -import org.eclipse.swt.events.PaintEvent; -import org.eclipse.swt.events.PaintListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -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.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -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.Label; -import org.eclipse.swt.widgets.TypedListener; - -/** - * The date picker panel - * - * changes by sebthom - * ~ setDate will fire the Selection event - * + you can use setDate(null) to clear the selection, - * the calendar will display the current date, but - * getDate will return null until the user explicitely - * selects a date from the control - * - * @author Andrey Onistchuk - */ -public class DatePicker extends Composite { - - //~ Inner Classes - // ---------------------------------------------------------- - private class DatePanel extends Canvas { - //~ Instance fields - // ---------------------------------------------------- - private int colSize; - private Display display = Display.getCurrent(); - private int rowSize; - private Calendar temp = Calendar.getInstance(); - - //~ Constructors - // ------------------------------------------------------- - public DatePanel(Composite parent, int style) { - super(parent, style | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE); - - GC gc = new GC(this); - Point p = gc.stringExtent("Q"); - gc.dispose(); - colSize = p.x * 3; - rowSize = (int) (p.y * 1.2); - - addPaintListener(new PaintListener() { - public void paintControl(PaintEvent event) { - onPaint(event); - } - }); - addControlListener(new ControlAdapter() { - public void controlResized(ControlEvent e) { - redraw(); - } - }); - addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent e) { - onKeyDown(e); - } - }); - addMouseListener(new MouseAdapter() { - public void mouseDoubleClick(MouseEvent e) { - doubleClick(); - } - public void mouseDown(MouseEvent e) { - onMouseDown(e); - } - }); - addMouseMoveListener(new MouseMoveListener() { - public void mouseMove(MouseEvent e) { - onMouseMove(e); - } - }); - } - - //~ Methods - // ------------------------------------------------------------ - private int computeOffset(int day) { - switch (day) { - case Calendar.MONDAY : - return 1; - case Calendar.TUESDAY : - return 2; - case Calendar.WEDNESDAY : - return 3; - case Calendar.THURSDAY : - return 4; - case Calendar.FRIDAY : - return 5; - case Calendar.SATURDAY : - return 6; - case Calendar.SUNDAY : - return 7; - } - return -1; - } - - public Point computeSize(int wHint, int hHint, boolean changed) { - return new Point(colSize * 7, rowSize * 7); - } - - /** - * Method drawTextImage. - * - * @param gc - * @param string - * @param object - * @param i - * @param i1 - * @param i2 - * @param colSize - * @param rowSize - */ - private void drawTextImage(GC gc, String string, int x, int y, - int colSize, int rowSize) { - gc.fillRectangle(x, y, colSize, rowSize); - gc.drawString(string, x, y, true); - } - - private int getDayFromPoint(int x, int y) { - int result = -1; - - for (int i = 1; i <= 31; i++) { - Point p = getDayPoint(i); - Rectangle r = new Rectangle(p.x, p.y, colSize, rowSize); - if (r.contains(x, y)) { - result = i; - break; - } - } - return result; - } - - private String getDayName(int day) { - return dateSymbols.getShortWeekdays()[day]; - } - - private Point getDayPoint(int day) { - syncTime(); - temp.set(Calendar.DAY_OF_MONTH, 1); - - int firstDayOffset = computeOffset(temp.get(Calendar.DAY_OF_WEEK)) - - 1; - temp.set(Calendar.DAY_OF_MONTH, day); - int dayOffset = computeOffset(temp.get(Calendar.DAY_OF_WEEK)); - int x = (dayOffset - 1) * colSize; - int y = (1 + (((firstDayOffset + day) - 1) / 7)) * rowSize; - - return new Point(x, y); - } - - private int getMaxDay() { - syncTime(); - - int day = 28; - - for (int i = 0; i < 10; i++) { - temp.set(Calendar.DAY_OF_MONTH, day); - - if (temp.get(Calendar.MONTH) != cal.get(Calendar.MONTH)) { - return day - 1; - } - day++; - } - return -1; - } - - private void onKeyDown(KeyEvent e) { - if (e.character == SWT.ESC) { - dateSelected(false); - return; - } - - if ((e.character == ' ') || (e.character == '\r')) { - dateSelected(true); - return; - } - - int day = cal.get(Calendar.DAY_OF_MONTH); - int month = cal.get(Calendar.MONTH); - int oldDay = day; - int oldMonth = month; - - if (e.keyCode == SWT.ARROW_LEFT) { - day--; - } - - if (e.keyCode == SWT.ARROW_RIGHT) { - day++; - } - - if (e.keyCode == SWT.ARROW_UP) { - day = ((day - 7) < 1 ? oldDay : day - 7); - } - - if (e.keyCode == SWT.ARROW_DOWN) { - day = ((day + 7) > getMaxDay() ? oldDay : day + 7); - } - - if (e.keyCode == SWT.PAGE_UP) { - month--; - } - - if (e.keyCode == SWT.PAGE_DOWN) { - month++; - } - - cal.set(Calendar.MONTH, month); - cal.set(Calendar.DAY_OF_MONTH, day); - - if ((day != oldDay) || (month != oldMonth)) { - redraw(); - - if (month != oldMonth) { - updateMonthLabel(); - } - } - } - - private void onMouseDown(MouseEvent e) { - int day = getDayFromPoint(e.x, e.y); - - if (day > 0) { - cal.set(Calendar.DAY_OF_MONTH, day); - dateSelected(true); - updateDate(); - } - } - - private void onMouseMove(MouseEvent e) { - int day = getDayFromPoint(e.x, e.y); - selection = day; - updateDate(); - } - - private void onPaint(PaintEvent event) { - Rectangle rect = getClientArea(); - GC gc0 = event.gc; - Image image = new Image(display, rect.width, rect.height); - GC gc = new GC(image); - gc.setBackground(display - .getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); - gc.fillRectangle(rect); - - int x = 0; - int y = 0; - - for (int i = 0; i < 7; i++) { - if (i == 6) { - gc.setForeground(display.getSystemColor(SWT.COLOR_RED)); - } - drawTextImage(gc, getDayName(1 + i), x, 0, colSize, rowSize); - x += colSize; - } - - gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK)); - y += rowSize; - gc.drawLine(0, 0, rect.width, 0); - gc.drawLine(0, y - 1, rect.width, y - 1); - - syncTime(); - - int day = 1; - - while (true) { - temp.set(Calendar.DAY_OF_MONTH, day); - - if (temp.get(Calendar.MONTH) != cal.get(Calendar.MONTH)) { - break; - } - - int dayOffset = computeOffset(temp.get(Calendar.DAY_OF_WEEK)); - Point p = getDayPoint(day); - - if (day == cal.get(Calendar.DAY_OF_MONTH)) { - gc.setForeground(display.getSystemColor( - SWT.COLOR_LIST_SELECTION_TEXT)); - gc.setBackground(display.getSystemColor( - SWT.COLOR_LIST_SELECTION)); - } else if (day == selection) { - gc.setForeground(display.getSystemColor( - SWT.COLOR_LIST_SELECTION_TEXT)); - gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK)); - } else { - gc.setBackground(display.getSystemColor( - SWT.COLOR_WIDGET_BACKGROUND)); - gc.setForeground(display.getSystemColor(dayOffset == 7 - ? SWT.COLOR_RED - : SWT.COLOR_BLACK)); - } - - drawTextImage(gc, "" + day, p.x, p.y, colSize, rowSize); - day++; - } - - gc0.drawImage(image, 0, 0); - gc.dispose(); - image.dispose(); - } - - private void syncTime() { - temp.setTimeInMillis(cal.getTimeInMillis()); - } - } - - //~ Instance fields - // -------------------------------------------------------- - private Calendar cal = Calendar.getInstance(); - - // sebthom - private Date selectedDate; - - private DatePanel datePanel; - private DateFormatSymbols dateSymbols = new DateFormatSymbols(); - private Label monthLabel; - private int selection = -1; - - //~ Constructors - // ----------------------------------------------------------- - public DatePicker(Composite parent, int style) { - super(parent, style); - - GridLayout gridLayout = new GridLayout(); - gridLayout.numColumns = 5; - gridLayout.verticalSpacing = gridLayout.horizontalSpacing = 0; - gridLayout.marginHeight = gridLayout.marginWidth = 0; - setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_CYAN)); - setLayout(gridLayout); - - GridData gridData; - - // previous year - Button prevYear = new Button(this, SWT.FLAT); - gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); - gridData.heightHint = gridData.widthHint = 20; - prevYear.setLayoutData(gridData); - prevYear.setText("<<"); - prevYear.setSelection(false); - prevYear.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - cal.roll(Calendar.YEAR, -1); - updateDate(); - } - }); - - // previous month - Button prevMonth = new Button(this, SWT.FLAT); - gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); - gridData.heightHint = gridData.widthHint = 20; - prevMonth.setLayoutData(gridData); - prevMonth.setText("<"); - prevMonth.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - cal.roll(Calendar.MONTH, -1); - updateDate(); - } - }); - - // current month - monthLabel = new Label(this, SWT.CENTER); - gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.CENTER); - gridData.heightHint = prevYear.computeSize(20, 20).y; - gridData.grabExcessHorizontalSpace = true; - monthLabel.setLayoutData(gridData); - - // next month - Button nextMonth = new Button(this, SWT.FLAT); - gridData = new GridData(GridData.HORIZONTAL_ALIGN_END); - gridData.heightHint = gridData.widthHint = 20; - nextMonth.setLayoutData(gridData); - nextMonth.setText(">"); - nextMonth.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - cal.roll(Calendar.MONTH, 1); - updateDate(); - } - }); - - // next year - Button nextYear = new Button(this, SWT.FLAT); - gridData = new GridData(GridData.HORIZONTAL_ALIGN_END); - gridData.heightHint = gridData.widthHint = 20; - nextYear.setLayoutData(gridData); - nextYear.setText(">>"); - nextYear.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - cal.roll(Calendar.YEAR, 1); - updateDate(); - } - }); - - // a panel - datePanel = new DatePanel(this, SWT.NONE); - gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL); - gridData.horizontalSpan = 5; - datePanel.setLayoutData(gridData); - - updateDate(); - } - - //~ Methods - // ---------------------------------------------------------------- - public void addSelectionListener(SelectionListener listener) { - checkWidget(); - - if (listener == null) { - SWT.error(SWT.ERROR_NULL_ARGUMENT); - } - TypedListener typedListener = new TypedListener(listener); - addListener(SWT.Selection, typedListener); - addListener(SWT.DefaultSelection, typedListener); - } - - public Point computeSize(int wHint, int hHint, boolean changed) { - Point pSize = datePanel.computeSize(wHint, hHint, changed); - Point labelSize = monthLabel.computeSize(wHint, hHint, changed); - - int x = (pSize.x < (labelSize.x + 80) ? labelSize.x + 80 : pSize.x); - int y = (pSize.y < (labelSize.y + 20) ? labelSize.y + 20 : pSize.y); - return new Point(x, y); - } - - private void dateSelected(boolean good) { - // sebthom - if (good) - selectedDate = cal.getTime(); - - Event event = new Event(); - event.doit = good; - notifyListeners(SWT.Selection, event); - } - - private void doubleClick() { - Event event = new Event(); - event.doit = true; - notifyListeners(SWT.MouseDoubleClick, event); - } - - private String getCurrentMonthName() { - StringBuffer sb = new StringBuffer(); - sb.append(getMonthName(cal.get(Calendar.MONTH))); - sb.append(", "); - sb.append(cal.get(Calendar.YEAR)); - return sb.toString(); - } - - public Date getDate() { - // sebthom - //return cal.getTime(); - return selectedDate; - } - - private String getMonthName(int month) { - return dateSymbols.getMonths()[month]; - } - - public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - - if (listener == null) { - SWT.error(SWT.ERROR_NULL_ARGUMENT); - } - removeListener(SWT.Selection, listener); - removeListener(SWT.DefaultSelection, listener); - } - - public void reset() { - cal = Calendar.getInstance(); - updateDate(); - } - - public void setDate(Date date) { - // sebthom - //cal.setTime(date); - selectedDate = date; - cal.setTime(selectedDate == null ? new Date() : date); - - updateMonthLabel(); - redraw(); - } - - private void updateDate() { - datePanel.redraw(); - updateMonthLabel(); - } - - private void updateMonthLabel() { - monthLabel.setText(getCurrentMonthName()); - } -} \ No newline at end of file diff --git a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/DatePickerCombo.java b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/DatePickerCombo.java deleted file mode 100644 index 91655c46..00000000 --- a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/DatePickerCombo.java +++ /dev/null @@ -1,1142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Gluster, Inc. - * This file is part of Gluster Management Console. - * - * Gluster Management Console is free software; you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Gluster Management Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * . - *******************************************************************************/ -package com.gluster.storage.management.gui.utils; - -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.accessibility.ACC; -import org.eclipse.swt.accessibility.AccessibleAdapter; -import org.eclipse.swt.accessibility.AccessibleControlAdapter; -import org.eclipse.swt.accessibility.AccessibleControlEvent; -import org.eclipse.swt.accessibility.AccessibleEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.TypedListener; - -/** - * The combo widget with drop-down date-picker panel. - * - * changes by sebthom - * ~ declared package accessible methods as private - * ~ declared getEditable() as public - * + added useSingleMouseClickToCommit behaviour - * + manually modifying the date in the text field is reflected in the date picker - * + setDate(null) clears the date. - * + added getText & setText() - * - * @author Andrey Onistchuk - * - */ -public final class DatePickerCombo extends Composite -{ - //~ Static Methods --------------------------------------------------------- - public static int checkStyle(int style) - { - int mask = SWT.BORDER | SWT.READ_ONLY | SWT.FLAT; - - return style & mask; - } - - //~ Instance fields -------------------------------------------------------- - private Button arrow; - private DatePicker dp; - private boolean hasFocus; - - /** - * @author sebthom - */ - private boolean isClosePopupWithSingleMouseClick = false; - private Shell popup; - private Text text; - - //~ Constructors ----------------------------------------------------------- - public DatePickerCombo(Composite parent, int style) - { - super(parent, checkStyle(style)); - - style = getStyle(); - - int textStyle = SWT.SINGLE; - - if ((style & SWT.READ_ONLY) != 0) - { - textStyle |= SWT.READ_ONLY; - } - - if ((style & SWT.FLAT) != 0) - { - textStyle |= SWT.FLAT; - } - - text = new Text(this, textStyle); - - popup = new Shell(getShell(), SWT.NO_TRIM); - - int pickerStyle = SWT.SINGLE; - - if ((style & SWT.FLAT) != 0) - { - pickerStyle |= SWT.FLAT; - } - - dp = new DatePicker(popup, pickerStyle); - - int arrowStyle = SWT.ARROW | SWT.DOWN; - - if ((style & SWT.FLAT) != 0) - { - arrowStyle |= SWT.FLAT; - } - - arrow = new Button(this, arrowStyle); - - Listener listener = new Listener() - { - public void handleEvent(Event event) - { - if (popup == event.widget) - { - popupEvent(event); - return; - } - - if (text == event.widget) - { - textEvent(event); - return; - } - - if (dp == event.widget) - { - dpEvent(event); - return; - } - - if (arrow == event.widget) - { - arrowEvent(event); - return; - } - - if (DatePickerCombo.this == event.widget) - { - comboEvent(event); - return; - } - } - }; - - int[] comboEvents = { SWT.Dispose, SWT.Move, SWT.Resize }; - - for (int i = 0; i < comboEvents.length; i++) - this.addListener(comboEvents[i], listener); - - int[] popupEvents = { SWT.Close, SWT.Paint, SWT.Deactivate }; - - for (int i = 0; i < popupEvents.length; i++) - popup.addListener(popupEvents[i], listener); - - int[] textEvents = - { SWT.KeyDown, SWT.KeyUp, SWT.Modify, SWT.MouseDown, SWT.MouseUp, SWT.Traverse, SWT.FocusIn, SWT.FocusOut }; - - for (int i = 0; i < textEvents.length; i++) - text.addListener(textEvents[i], listener); - - int[] dpEvents = - { - SWT.MouseUp, - SWT.MouseDoubleClick, - SWT.Selection, - SWT.Traverse, - SWT.KeyDown, - SWT.KeyUp, - SWT.FocusIn, - SWT.FocusOut }; - - for (int i = 0; i < dpEvents.length; i++) - dp.addListener(dpEvents[i], listener); - - int[] arrowEvents = { SWT.Selection, SWT.FocusIn, SWT.FocusOut }; - - for (int i = 0; i < arrowEvents.length; i++) - arrow.addListener(arrowEvents[i], listener); - - initAccessible(); - } - - //~ Methods ---------------------------------------------------------------- - - /** - * Adds the listener to receive events. - * - * @param listener - * the listener - * - * @exception SWTError(ERROR_THREAD_INVALID_ACCESS) - * when called from the wrong thread - * @exception SWTError(ERROR_WIDGET_DISPOSED) - * when the widget has been disposed - * @exception SWTError(ERROR_NULL_ARGUMENT) - * when listener is null - */ - public void addModifyListener(ModifyListener listener) - { - checkWidget(); - - if (listener == null) - { - SWT.error(SWT.ERROR_NULL_ARGUMENT); - } - - TypedListener typedListener = new TypedListener(listener); - addListener(SWT.Modify, typedListener); - } - - /** - * Adds the listener to receive events. - * - * @param listener - * the listener - * - * @exception SWTError(ERROR_THREAD_INVALID_ACCESS) - * when called from the wrong thread - * @exception SWTError(ERROR_WIDGET_DISPOSED) - * when the widget has been disposed - * @exception SWTError(ERROR_NULL_ARGUMENT) - * when listener is null - */ - public void addSelectionListener(SelectionListener listener) - { - checkWidget(); - - if (listener == null) - { - SWT.error(SWT.ERROR_NULL_ARGUMENT); - } - - TypedListener typedListener = new TypedListener(listener); - addListener(SWT.Selection, typedListener); - addListener(SWT.DefaultSelection, typedListener); - } - - private void arrowEvent(Event event) - { - switch (event.type) - { - case SWT.FocusIn : - { - if (hasFocus) - { - return; - } - - hasFocus = true; - - if (getEditable()) - { - text.selectAll(); - } - - Event e = new Event(); - e.time = event.time; - notifyListeners(SWT.FocusIn, e); - break; - } - - case SWT.FocusOut : - { - Control focusControl = getDisplay().getFocusControl(); - - if ((focusControl == dp) || (focusControl == text)) - { - return; - } - - hasFocus = false; - - Event e = new Event(); - e.time = event.time; - notifyListeners(SWT.FocusOut, e); - break; - } - - case SWT.Selection : - { - dropDown(!isDropped()); - break; - } - } - } - - /** - * Clears the current selection. - * - * @exception SWTError(ERROR_THREAD_INVALID_ACCESS) - * when called from the wrong thread - * @exception SWTError(ERROR_WIDGET_DISPOSED) - * when the widget has been disposed - */ - public void clearSelection() - { - checkWidget(); - text.clearSelection(); - dp.reset(); - } - - private void comboEvent(Event event) - { - switch (event.type) - { - case SWT.Dispose : - - if ((popup != null) && !popup.isDisposed()) - { - popup.dispose(); - } - - popup = null; - text = null; - dp = null; - arrow = null; - break; - - case SWT.Move : - dropDown(false); - break; - - case SWT.Resize : - internalLayout(); - break; - } - } - - public Point computeSize(int wHint, int hHint, boolean changed) - { - checkWidget(); - - int width = 0; - int height = 0; - Point textSize = text.computeSize(wHint, SWT.DEFAULT, changed); - Point arrowSize = arrow.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed); - Point listSize = dp.computeSize(wHint, SWT.DEFAULT, changed); - int borderWidth = getBorderWidth(); - - height = Math.max(hHint, Math.max(textSize.y, arrowSize.y) + (2 * borderWidth)); - width = Math.max(wHint, Math.max(textSize.x + arrowSize.x + (2 * borderWidth), listSize.x + 2)); - - return new Point(width, height); - } - - private void dpEvent(Event event) - { - switch (event.type) - { - case SWT.FocusIn : - { - if (hasFocus) - { - return; - } - - hasFocus = true; - - if (getEditable()) - { - text.selectAll(); - } - - Event e = new Event(); - e.time = event.time; - notifyListeners(SWT.FocusIn, e); - break; - } - - case SWT.FocusOut : - { - Control focusControl = getDisplay().getFocusControl(); - - if ((focusControl == text) || (focusControl == arrow)) - { - return; - } - - hasFocus = false; - - Event e = new Event(); - e.time = event.time; - notifyListeners(SWT.FocusOut, e); - break; - } - - case SWT.MouseDown : - { - if (event.button != 1) - { - return; - } - - dropDown(false); - - Event e = new Event(); - e.time = event.time; - notifyListeners(SWT.DefaultSelection, e); - break; - } - - case SWT.Selection : - { - // sebthom - if (!isClosePopupWithSingleMouseClick) - { - Date date = dp.getDate(); - text.setText(DateFormat.getDateInstance().format(date)); - text.selectAll(); - - Event e = new Event(); - e.time = event.time; - e.stateMask = event.stateMask; - e.doit = event.doit; - notifyListeners(SWT.Selection, e); - event.doit = e.doit; - - break; - } - // otherwise perform the code of SWT.MouseDoubleClick - } - - case SWT.MouseDoubleClick : - { - dropDown(false); - - Date date = dp.getDate(); - - // sebthom - if (date == null) - { - text.setText(""); - } - else - { - text.setText(DateFormat.getDateInstance().format(date)); - text.selectAll(); - } - - Event e = new Event(); - e.time = event.time; - e.stateMask = event.stateMask; - e.doit = event.doit; - notifyListeners(SWT.Selection, e); - event.doit = e.doit; - break; - } - - case SWT.Traverse : - { - switch (event.detail) - { - case SWT.TRAVERSE_TAB_NEXT : - case SWT.TRAVERSE_RETURN : - case SWT.TRAVERSE_ESCAPE : - case SWT.TRAVERSE_ARROW_PREVIOUS : - case SWT.TRAVERSE_ARROW_NEXT : - event.doit = false; - break; - } - - Event e = new Event(); - e.time = event.time; - e.detail = event.detail; - e.doit = event.doit; - e.keyCode = event.keyCode; - notifyListeners(SWT.Traverse, e); - event.doit = e.doit; - break; - } - - case SWT.KeyUp : - { - Event e = new Event(); - e.time = event.time; - e.character = event.character; - e.keyCode = event.keyCode; - e.stateMask = event.stateMask; - notifyListeners(SWT.KeyUp, e); - break; - } - - case SWT.KeyDown : - { - if (event.character == SWT.ESC) - { - // escape key cancels popup dp - dropDown(false); - } - - if ((event.character == SWT.CR) || (event.character == '\t')) - { - // Enter and Tab cause default selection - dropDown(false); - - Event e = new Event(); - e.time = event.time; - e.stateMask = event.stateMask; - notifyListeners(SWT.DefaultSelection, e); - } - - //At this point the widget may have been disposed. - // If so, do not continue. - if (isDisposed()) - { - break; - } - - Event e = new Event(); - e.time = event.time; - e.character = event.character; - e.keyCode = event.keyCode; - e.stateMask = event.stateMask; - notifyListeners(SWT.KeyDown, e); - break; - } - } - } - - private void dropDown(boolean drop) - { - if (drop == isDropped()) - { - return; - } - - if (!drop) - { - popup.setVisible(false); - text.setFocus(); - return; - } - - Rectangle listRect = dp.getBounds(); - Point point = getParent().toDisplay(getLocation()); - Point comboSize = getSize(); - int width = Math.max(comboSize.x, listRect.width + 2); - popup.setBounds(point.x, point.y + comboSize.y, width, listRect.height + 2); - popup.setVisible(true); - dp.setFocus(); - } - - public Control[] getChildren() - { - checkWidget(); - - return new Control[0]; - } - - public Date getDate() - { - checkWidget(); - - return dp.getDate(); - } - - public boolean getEditable() - { - return text.getEditable(); - } - - /** - * @author sebthom - */ - public String getText() - { - return text.getText(); - } - - public void setText(String txt) - { - text.setText(txt); - } - - public int getTextHeight() - { - checkWidget(); - return text.getLineHeight(); - } - - private void initAccessible() - { - getAccessible().addAccessibleListener(new AccessibleAdapter() - { - public void getHelp(AccessibleEvent e) - { - e.result = getToolTipText(); - } - }); - - getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() - { - public void getChildAtPoint(AccessibleControlEvent e) - { - Point testPoint = toControl(new Point(e.x, e.y)); - - if (getBounds().contains(testPoint)) - { - e.childID = ACC.CHILDID_SELF; - } - } - - public void getChildCount(AccessibleControlEvent e) - { - e.detail = 0; - } - - public void getLocation(AccessibleControlEvent e) - { - Rectangle location = getBounds(); - Point pt = toDisplay(new Point(location.x, location.y)); - e.x = pt.x; - e.y = pt.y; - e.width = location.width; - e.height = location.height; - } - - public void getRole(AccessibleControlEvent e) - { - e.detail = ACC.ROLE_COMBOBOX; - } - - public void getState(AccessibleControlEvent e) - { - e.detail = ACC.STATE_NORMAL; - } - - public void getValue(AccessibleControlEvent e) - { - e.result = text.getText(); - } - }); - } - - private void internalLayout() - { - if (isDropped()) - { - dropDown(false); - } - - Rectangle rect = getClientArea(); - int width = rect.width; - int height = rect.height; - Point arrowSize = arrow.computeSize(SWT.DEFAULT, height); - text.setBounds(0, 0, width - arrowSize.x, height); - arrow.setBounds(width - arrowSize.x, 0, arrowSize.x, arrowSize.y); - - Point size = getSize(); - int itemHeight = dp.getBounds().height; - Point listSize = dp.computeSize(SWT.DEFAULT, itemHeight); - dp.setBounds(1, 1, Math.max(size.x - 2, listSize.x), listSize.y); - } - - /** - * determines if you need to double click a date in the expanded calender control to hide it - * default is false meaning you have to double click a date - * - * @author sebthom - * - * @param useSingleMouseClickToCommit - */ - public boolean isClosePopupWithSingleMouseClick() - { - return isClosePopupWithSingleMouseClick; - } - - private boolean isDropped() - { - return popup.getVisible(); - } - - public boolean isFocusControl() - { - checkWidget(); - - if (text.isFocusControl() || arrow.isFocusControl() || dp.isFocusControl() || popup.isFocusControl()) - { - return true; - } - else - { - return super.isFocusControl(); - } - } - - private void popupEvent(Event event) - { - switch (event.type) - { - case SWT.Paint : - - // draw black rectangle around dp - Rectangle listRect = dp.getBounds(); - Color black = getDisplay().getSystemColor(SWT.COLOR_BLACK); - event.gc.setForeground(black); - event.gc.drawRectangle(0, 0, listRect.width + 1, listRect.height + 1); - break; - - case SWT.Close : - event.doit = false; - dropDown(false); - break; - - case SWT.Deactivate : - dropDown(false); - break; - } - } - - public void redraw(int x, int y, int width, int height, boolean all) - { - checkWidget(); - - if (!all) - { - return; - } - - Point location = text.getLocation(); - text.redraw(x - location.x, y - location.y, width, height, all); - location = dp.getLocation(); - dp.redraw(x - location.x, y - location.y, width, height, all); - - if (arrow != null) - { - location = arrow.getLocation(); - arrow.redraw(x - location.x, y - location.y, width, height, all); - } - } - - /** - * Removes the listener. - * - * @param listener - * the listener - * - * @exception SWTError(ERROR_THREAD_INVALID_ACCESS) - * when called from the wrong thread - * @exception SWTError(ERROR_WIDGET_DISPOSED) - * when the widget has been disposed - * @exception SWTError(ERROR_NULL_ARGUMENT) - * when listener is null - */ - public void removeModifyListener(ModifyListener listener) - { - checkWidget(); - - if (listener == null) - { - SWT.error(SWT.ERROR_NULL_ARGUMENT); - } - - removeListener(SWT.Modify, listener); - } - - /** - * Removes the listener. - * - * @param listener - * the listener - * - * @exception SWTError(ERROR_THREAD_INVALID_ACCESS) - * when called from the wrong thread - * @exception SWTError(ERROR_WIDGET_DISPOSED) - * when the widget has been disposed - * @exception SWTError(ERROR_NULL_ARGUMENT) - * when listener is null - */ - public void removeSelectionListener(SelectionListener listener) - { - checkWidget(); - - if (listener == null) - { - SWT.error(SWT.ERROR_NULL_ARGUMENT); - } - - removeListener(SWT.Selection, listener); - removeListener(SWT.DefaultSelection, listener); - } - - public void setBackground(Color color) - { - super.setBackground(color); - - if (text != null) - { - text.setBackground(color); - } - - if (dp != null) - { - dp.setBackground(color); - } - - if (arrow != null) - { - arrow.setBackground(color); - } - } - - /** - * set if you need to double click a date in the expanded calender control to hide it - * default is false meaning you have to double click a date - * - * @author sebthom - * - * @param useSingleMouseClickToCommit - */ - public void setClosePopupWithSingleMouseClick(boolean isClosePopupWithSingleMouseClick) - { - this.isClosePopupWithSingleMouseClick = isClosePopupWithSingleMouseClick; - } - - /** - * Selects an item. - *

- * If the item at an index is not selected, it is selected. Indices that - * are out of range are ignored. Indexing is zero based. - * - * @param index - * the index of the item - * - * @exception SWTError(ERROR_THREAD_INVALID_ACCESS) - * when called from the wrong thread - * @exception SWTError(ERROR_WIDGET_DISPOSED) - * when the widget has been disposed - */ - public void setDate(Date date) - { - checkWidget(); - - //sebthom - if (date != null) - { - text.setText(DateFormat.getDateInstance().format(date)); - text.selectAll(); - } - else - { - text.setText(""); - } - - dp.setDate(date); - } - - public boolean setFocus() - { - checkWidget(); - return text.setFocus(); - } - - public void setFont(Font font) - { - super.setFont(font); - text.setFont(font); - dp.setFont(font); - internalLayout(); - } - - public void setForeground(Color color) - { - super.setForeground(color); - - if (text != null) - { - text.setForeground(color); - } - - if (dp != null) - { - dp.setForeground(color); - } - - if (arrow != null) - { - arrow.setForeground(color); - } - } - - /** - * Sets the new selection. - * - * @param selection - * point representing the start and the end of the new selection - * - * @exception SWTError(ERROR_THREAD_INVALID_ACCESS) - * when called from the wrong thread - * @exception SWTError(ERROR_WIDGET_DISPOSED) - * when the widget has been disposed - * @exception SWTError(ERROR_NULL_ARGUMENT) - * when selection is null - */ - public void setSelection(Point selection) - { - checkWidget(); - - if (selection == null) - { - SWT.error(SWT.ERROR_NULL_ARGUMENT); - } - - text.setSelection(selection.x, selection.y); - } - - /** - * Sets the text limit - * - * @param limit - * new text limit - * - * @exception SWTError(ERROR_THREAD_INVALID_ACCESS) - * when called from the wrong thread - * @exception SWTError(ERROR_WIDGET_DISPOSED) - * when the widget has been disposed - * @exception SWTError(ERROR_CANNOT_BE_ZERO) - * when limit is 0 - */ - public void setTextLimit(int limit) - { - checkWidget(); - text.setTextLimit(limit); - } - - public void setToolTipText(String string) - { - checkWidget(); - super.setToolTipText(string); - arrow.setToolTipText(string); - text.setToolTipText(string); - } - - public void setVisible(boolean visible) - { - super.setVisible(visible); - - if (!visible) - { - popup.setVisible(false); - } - } - - private void textEvent(Event event) - { - switch (event.type) - { - case SWT.FocusIn : - { - if (hasFocus) - { - return; - } - - hasFocus = true; - - if (getEditable()) - { - text.selectAll(); - } - - Event e = new Event(); - e.time = event.time; - notifyListeners(SWT.FocusIn, e); - break; - } - - case SWT.FocusOut : - { - Control focusControl = getDisplay().getFocusControl(); - - if ((focusControl == dp) || (focusControl == arrow)) - { - return; - } - - hasFocus = false; - - Event e = new Event(); - e.time = event.time; - notifyListeners(SWT.FocusOut, e); - break; - } - - case SWT.KeyDown : - { - if (event.character == SWT.ESC) - { - // escape key cancels popup dp - dropDown(false); - } - - if (event.character == SWT.CR) - { - dropDown(false); - - Event e = new Event(); - e.time = event.time; - e.stateMask = event.stateMask; - notifyListeners(SWT.DefaultSelection, e); - } - - //At this point the widget may have been disposed. - // If so, do not continue. - if (isDisposed()) - { - break; - } - - if ((event.keyCode == SWT.ARROW_UP) || (event.keyCode == SWT.ARROW_DOWN)) - { - //Date oldDate = getDate(); - - //At this point the widget may have been disposed. - // If so, do not continue. - if (isDisposed()) - { - break; - } - } - - // Further work : Need to add support for incremental - // search in - // pop up dp as characters typed in text widget - Event e = new Event(); - e.time = event.time; - e.character = event.character; - e.keyCode = event.keyCode; - e.stateMask = event.stateMask; - notifyListeners(SWT.KeyDown, e); - break; - } - - case SWT.KeyUp : - { - Event e = new Event(); - e.time = event.time; - e.character = event.character; - e.keyCode = event.keyCode; - e.stateMask = event.stateMask; - notifyListeners(SWT.KeyUp, e); - break; - } - - case SWT.Modify : - { - // sebthom - if (!popup.isVisible()) - { - if (text.getText().length() == 0) - { - dp.setDate(null); - } - else - { - try - { - dp.setDate(SimpleDateFormat.getDateInstance().parse(text.getText())); - } - catch (ParseException pe) - { - dp.setDate(null); - } - } - } - // dp.deselectAll (); - Event e = new Event(); - e.time = event.time; - notifyListeners(SWT.Modify, e); - break; - } - - case SWT.MouseDown : - { - if (event.button != 1 || text.getEditable()) - { - return; - } - - boolean dropped = isDropped(); - text.selectAll(); - - if (!dropped) - { - setFocus(); - } - dropDown(!dropped); - - break; - } - - case SWT.MouseUp : - { - if (event.button != 1 || text.getEditable()) - { - return; - } - text.selectAll(); - break; - } - - case SWT.Traverse : - { - switch (event.detail) - { - case SWT.TRAVERSE_RETURN : - case SWT.TRAVERSE_ARROW_PREVIOUS : - case SWT.TRAVERSE_ARROW_NEXT : - // The enter causes default selection and - // the arrow keys are used to manipulate the dp - // contents so do not use them for traversal. - event.doit = false; - break; - } - - Event e = new Event(); - e.time = event.time; - e.detail = event.detail; - e.doit = event.doit; - e.keyCode = event.keyCode; - notifyListeners(SWT.Traverse, e); - event.doit = e.doit; - break; - } - } - } -} \ No newline at end of file diff --git a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/DiskViewerEditingSupport.java b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/DiskViewerEditingSupport.java deleted file mode 100644 index cc150b39..00000000 --- a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/DiskViewerEditingSupport.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Gluster, Inc. - * This file is part of Gluster Management Console. - * - * Gluster Management Console is free software; you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Gluster Management Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * . - *******************************************************************************/ -package com.gluster.storage.management.gui.utils; - -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.ui.forms.widgets.FormToolkit; - -import com.gluster.storage.management.core.model.Disk; - -public class DiskViewerEditingSupport extends EditingSupport { - private FormToolkit toolkit; - - public DiskViewerEditingSupport(FormToolkit toolkit, TableViewer viewer) { - super(viewer); - this.toolkit = toolkit; - } - - @Override - protected CellEditor getCellEditor(Object element) { - return new HyperlinkCellEditor(toolkit, (TableViewer)getViewer(), (Disk) element); - } - - @Override - protected boolean canEdit(Object element) { - Disk disk = (Disk) element; - return (disk.isUninitialized()); - } - - @Override - protected Object getValue(Object element) { - return ((Disk) element).getStatus(); - } - - @Override - protected void setValue(Object element, Object value) { - getViewer().update(element, new String[] { "status" }); - } - -} diff --git a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/GUIHelper.java b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/GUIHelper.java index d6d977a3..8957f0e6 100644 --- a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/GUIHelper.java +++ b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/GUIHelper.java @@ -65,6 +65,7 @@ import com.gluster.storage.management.gui.IImageKeys; public class GUIHelper { private static final GUIHelper instance = new GUIHelper(); + private static final ImageUtil imageUtil = new ImageUtil(); private GUIHelper() { @@ -134,7 +135,7 @@ public class GUIHelper { public Composite createTab(TabFolder tabFolder, String title, String imageKey) { TabItem item = new TabItem(tabFolder, SWT.NONE); item.setText(title); - item.setImage(AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID, imageKey).createImage()); + item.setImage(getImage(imageKey)); Composite composite = new Composite(tabFolder, SWT.NONE); composite.setLayout(new FillLayout()); @@ -145,11 +146,11 @@ public class GUIHelper { } public ImageDescriptor getImageDescriptor(String imagePath) { - return AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID, imagePath); + return imageUtil.getImageDescriptor(imagePath); } public Image getImage(String imagePath) { - return getImageDescriptor(imagePath).createImage(); + return imageUtil.getImage(imagePath); } public Action createPullDownMenu(String menuName, String iconPath, final MenuManager menuManager) { diff --git a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/HyperlinkCellEditor.java b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/HyperlinkCellEditor.java deleted file mode 100644 index 03a94e49..00000000 --- a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/HyperlinkCellEditor.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Gluster, Inc. - * This file is part of Gluster Management Console. - * - * Gluster Management Console is free software; you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Gluster Management Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * . - *******************************************************************************/ -package com.gluster.storage.management.gui.utils; - -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.forms.widgets.FormToolkit; -import org.eclipse.ui.forms.widgets.ImageHyperlink; - -import com.gluster.storage.management.core.model.Disk; - -public class HyperlinkCellEditor extends CellEditor { - private FormToolkit toolkit; - private Disk disk; - private ImageHyperlink link; - private TableViewer viewer; - - public HyperlinkCellEditor(FormToolkit toolkit, TableViewer viewer, Disk disk) { - this.toolkit = toolkit; - this.viewer = viewer; - this.disk = disk; - } - - @Override - protected Control createControl(Composite parent) { - link = toolkit.createImageHyperlink(viewer.getTable(), SWT.NONE); - // link.setImage(guiHelper.getImage(IImageKeys.DISK_UNINITIALIZED)); - link.setText("Initialize"); - return link; - } - - @Override - protected Object doGetValue() { - return disk.getStatus(); - } - - @Override - protected void doSetFocus() { - link.setFocus(); - } - - @Override - protected void doSetValue(Object value) { - if(!disk.isUninitialized()) { - this.deactivate(); - this.dispose(); - } - } -} diff --git a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/ImageUtil.java b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/ImageUtil.java new file mode 100644 index 00000000..efa169de --- /dev/null +++ b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/ImageUtil.java @@ -0,0 +1,51 @@ +/** + * ImageUtil.java + * + * Copyright (c) 2011 Gluster, Inc. + * This file is part of Gluster Management Console. + * + * Gluster Management Console is free software; you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Gluster Management Console is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License + * for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * . + */ +package com.gluster.storage.management.gui.utils; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.plugin.AbstractUIPlugin; + +import com.gluster.storage.management.gui.Application; + +/** + * + */ +public class ImageUtil { + private static final LRUCache imageCache = new LRUCache(20); + + public ImageDescriptor getImageDescriptor(String imagePath) { + return AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID, imagePath); + } + + public synchronized Image getImage(String imagePath) { + if(imageCache.containsKey(imagePath)) { + return imageCache.get(imagePath); + } + return createImage(imagePath); + } + + private Image createImage(String imagePath) { + Image image = getImageDescriptor(imagePath).createImage(); + imageCache.put(imagePath, image); + return image; + } +} \ No newline at end of file diff --git a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/LRUCache.java b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/LRUCache.java new file mode 100644 index 00000000..3c805ac8 --- /dev/null +++ b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/utils/LRUCache.java @@ -0,0 +1,55 @@ +/** + * LRUCache.java + * + * Copyright (c) 2011 Gluster, Inc. + * This file is part of Gluster Management Console. + * + * Gluster Management Console is free software; you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Gluster Management Console is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License + * for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see + * . + */ +package com.gluster.storage.management.gui.utils; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * An LRU cache, based on LinkedHashMap. + *

+ * This cache has a fixed maximum number of elements (cacheSize). If the cache is full and another entry is + * added, the LRU (least recently used) entry is dropped. + * + */ +public class LRUCache extends LinkedHashMap { + + private static final long serialVersionUID = 1L; + private static final float loadFactor = 0.75f; + private int cacheSize; + + /** + * Creates a new LRU cache. + * + * @param cacheSize + * the maximum number of entries that will be kept in this cache. + */ + public LRUCache(int cacheSize) { + super((int) Math.ceil(cacheSize / loadFactor) + 1, loadFactor, true); + this.cacheSize = cacheSize; + } + + @Override + protected boolean removeEldestEntry(Map.Entry eldest) { + return size() > cacheSize; + } + +} diff --git a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/details/DisksPage.java b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/details/DisksPage.java index 8f96a8ee..9ea962de 100644 --- a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/details/DisksPage.java +++ b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/details/DisksPage.java @@ -22,7 +22,6 @@ import java.util.List; import org.eclipse.jface.layout.TableColumnLayout; import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Table; @@ -30,7 +29,6 @@ import org.eclipse.ui.IWorkbenchSite; import com.gluster.storage.management.core.model.Disk; import com.gluster.storage.management.gui.DiskTableLabelProvider; -import com.gluster.storage.management.gui.utils.DiskViewerEditingSupport; public class DisksPage extends AbstractDisksPage { diff --git a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/details/TabCreatorFactoryImpl.java b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/details/TabCreatorFactoryImpl.java index 2a28aae3..28d3d4aa 100644 --- a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/details/TabCreatorFactoryImpl.java +++ b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/details/TabCreatorFactoryImpl.java @@ -38,6 +38,7 @@ public class TabCreatorFactoryImpl implements TabCreatorFactory { * Again, "class name" includes "entity type" in case of {@link EntityGroup}
* 4) Add the newly created tab creator to the cache and return it */ + @SuppressWarnings("rawtypes") @Override public TabCreator getTabCreator(Entity entity) { Class entityClass = entity.getClass(); diff --git a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/navigator/ClusterAdapterFactory.java b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/navigator/ClusterAdapterFactory.java index 3e4cbcb1..d7ef44ac 100644 --- a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/navigator/ClusterAdapterFactory.java +++ b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/navigator/ClusterAdapterFactory.java @@ -46,6 +46,7 @@ public class ClusterAdapterFactory implements IAdapterFactory { return ((Entity)o).getName(); } + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public ImageDescriptor getImageDescriptor(Object object) { String iconPath = null; @@ -81,6 +82,7 @@ public class ClusterAdapterFactory implements IAdapterFactory { } }; + @SuppressWarnings("rawtypes") @Override public Object getAdapter(Object adaptableObject, Class adapterType) { if (adapterType == IWorkbenchAdapter.class) { @@ -91,6 +93,7 @@ public class ClusterAdapterFactory implements IAdapterFactory { return null; } + @SuppressWarnings("rawtypes") @Override public Class[] getAdapterList() { return new Class[] { IWorkbenchAdapter.class }; diff --git a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/navigator/NavigationTreeLabelDecorator.java b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/navigator/NavigationTreeLabelDecorator.java index 028b9a4b..4cdc2e66 100644 --- a/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/navigator/NavigationTreeLabelDecorator.java +++ b/com.gluster.storage.management.gui/src/com/gluster/storage/management/gui/views/navigator/NavigationTreeLabelDecorator.java @@ -49,6 +49,7 @@ public class NavigationTreeLabelDecorator implements ILightweightLabelDecorator public void removeListener(ILabelProviderListener listener) { } + @SuppressWarnings("rawtypes") @Override public void decorate(Object element, IDecoration decoration) { if (element instanceof Volume) { -- cgit