deckViewer.setTabEditingStyle(EditingSupport.TABBING_VERTICAL);
TreeViewerColumn columnGroup = new TreeViewerColumn(deckViewer, SWT.LEFT);
columnGroup.getColumn().setText("Group");
columnGroup.getColumn().setWidth(150);
columnGroup.setLabelProvider( new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if(element instanceof CardGroup)
return ((CardGroup) element).getName();
return null;
}
@Override
public Color getForeground(Object element) {
if(element instanceof CardGroup)
return ((CardGroup) element).getColor();
return null;
}
@Override
public Font getFont(Object element) {
if(element instanceof CardGroup) {
CardGroup group = (CardGroup) element;
if (group.getName() == CardGroup.SIDEBOARD)
return boldFont;
else if (group.getName() != CardGroup.MAIN)
return italicFont;
}
return null;
}
@Override
public String getToolTipText(Object element) {
return null;
}
});
columnGroup.setEditingSupport(new EditingSupport(deckViewer) {
CellEditor editor = new TextCellEditor(deckViewer.getTree());
@Override
protected boolean canEdit(Object element) {
if (element instanceof CardGroup) {
CardGroup cardGroup = (CardGroup) element;
if(CardGroup.SIDEBOARD != cardGroup.getName() )
return true;
}
return false;
}
@Override
protected CellEditor getCellEditor(Object element) {
return editor;
}
@Override
protected Object getValue(Object element) {
if (element instanceof CardGroup) {
CardGroup cardGroup = (CardGroup) element;
if(CardGroup.SIDEBOARD != cardGroup.getName() )
return cardGroup.getName();
}
return null;
}
@Override
protected void setValue(Object element, Object value) {
// TODO this was needed in 3.1 and old API, still necessary?
// if (element instanceof Item) {
// element = ((Item) element).getData();
// }
if (element instanceof CardGroup) {
CardGroup group = (CardGroup) element;
if (!group.getName().equals(value))
group.setName((String) value);
}
}
});
TreeViewerColumn columnAmount = new TreeViewerColumn(deckViewer, SWT.RIGHT);
columnAmount.getColumn().setText("Amount");
columnAmount.getColumn().setWidth(60);
columnAmount.setLabelProvider( new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if(element instanceof Card) {
Card card = (Card)element;
String meta = deckLegality.getText();
boolean restricted = CardPool.instance().lookupMetaInfo(card.getName(), meta+"restricted");
return Integer.toString(((CardGroup) card.getParent()).count(card)) + (restricted ? "*": "");
}
return null;
}
@Override
public Color getForeground(Object element) {
String meta = deckLegality.getText();
if (element instanceof Card && meta.length()>0) {
Card card = (Card)element;
boolean legal = CardPool.instance().lookupMetaInfo(card.getName(), meta);
if(legal)
return darkGreen;
return red;
}
return null;
}
@Override
public Point getToolTipShift(Object object) {
return new Point(10,10);
}
@Override
public String getToolTipText(Object element) {
if (element instanceof Card)
return "<STRG> +:add a copy\n<STRG -:remove a copy\n\nTry D-n-D support. It does work :-)";
return null;
}
@Override
public int getToolTipDisplayDelayTime(Object object) {
return 1000;
}
@Override
public int getToolTipTimeDisplayed(Object object) {
return 5000;
}
});
TreeViewerColumn columnName = new TreeViewerColumn(deckViewer, SWT.LEFT);
columnName.getColumn().setText("Name");
columnName.getColumn().setWidth(300);
columnName.setLabelProvider( new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof Card)
return ((Card)element).getName();
return null;