Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JBIDE-20095] impl'ed validation for parameters
- Loading branch information
Showing
5 changed files
with
289 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
.../org/jboss/tools/openshift/internal/common/ui/utils/TableViewerCellDecorationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2015 Red Hat, Inc. | ||
* Distributed under license by Red Hat, Inc. All rights reserved. | ||
* This program is made available under the terms of the | ||
* Eclipse Public License v1.0 which accompanies this distribution, | ||
* and is available at http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
******************************************************************************/ | ||
package org.jboss.tools.openshift.internal.common.ui.utils; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.eclipse.jface.viewers.ViewerCell; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.custom.TableEditor; | ||
import org.eclipse.swt.graphics.Image; | ||
import org.eclipse.swt.graphics.Rectangle; | ||
import org.eclipse.swt.widgets.Control; | ||
import org.eclipse.swt.widgets.Label; | ||
import org.eclipse.swt.widgets.Table; | ||
import org.eclipse.swt.widgets.TableItem; | ||
|
||
/** | ||
* A manager that controls image based decorations for table viewer cells. | ||
* | ||
* @author Andre Dietisheim | ||
*/ | ||
public class TableViewerCellDecorationManager { | ||
|
||
private Image image; | ||
private Table table; | ||
|
||
/** | ||
* @param table | ||
* the table to handle cell decorations for | ||
* @param image | ||
* the image to show as decoration | ||
*/ | ||
public TableViewerCellDecorationManager(Table table, Image image) { | ||
this.image = image; | ||
this.table = table; | ||
} | ||
|
||
private Map<TableItem, TableEditor> decorationByItem = new HashMap<TableItem, TableEditor>(); | ||
|
||
public void show(ViewerCell cell) { | ||
Control decoration = createDecoration(image, table); | ||
TableEditor editor = decorationByItem.get((TableItem) cell.getItem()); | ||
if (editor == null) { | ||
editor = createTableEditor(image, table); | ||
decorationByItem.put((TableItem) cell.getItem(), editor); | ||
} | ||
editor.setEditor(decoration, (TableItem) cell.getItem(), cell.getColumnIndex()); | ||
} | ||
|
||
public void hide(ViewerCell cell) { | ||
TableEditor editor = decorationByItem.get((TableItem) cell.getItem()); | ||
if (editor != null) { | ||
Control decoration = editor.getEditor(); | ||
if (decoration != null) { | ||
decoration.dispose(); | ||
} | ||
editor.setEditor(null); | ||
} | ||
} | ||
|
||
private Control createDecoration(Image image, Table table) { | ||
Label validationDecoration = new Label(table, SWT.None); | ||
validationDecoration.setImage(image); | ||
return validationDecoration; | ||
} | ||
|
||
private TableEditor createTableEditor(Image image, Table table) { | ||
TableEditor tableEditor = new TableEditor(table); | ||
tableEditor.grabHorizontal = false; | ||
tableEditor.grabVertical = false; | ||
Rectangle bounds = image.getBounds(); | ||
tableEditor.minimumHeight = bounds.height; | ||
tableEditor.minimumWidth = bounds.width; | ||
tableEditor.verticalAlignment = SWT.BEGINNING; | ||
tableEditor.horizontalAlignment = SWT.LEFT; | ||
|
||
return tableEditor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.