use of org.eclipse.jface.layout.TableColumnLayout in project egit by eclipse.
the class MultiPullResultDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite main = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().applyTo(main);
GridDataFactory.fillDefaults().grab(true, true).applyTo(main);
tv = new TableViewer(main, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
tv.setContentProvider(ArrayContentProvider.getInstance());
TableColumnLayout layout = new TableColumnLayout();
main.setLayout(layout);
tv.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = (IStructuredSelection) event.getSelection();
boolean enabled = false;
for (Object obj : sel.toList()) {
@SuppressWarnings("unchecked") Entry<Repository, Object> entry = (Entry<Repository, Object>) obj;
enabled |= entry.getValue() instanceof PullResult;
}
getButton(DETAIL_BUTTON).setEnabled(enabled);
}
});
tv.addOpenListener(new IOpenListener() {
@Override
public void open(OpenEvent event) {
buttonPressed(DETAIL_BUTTON);
}
});
Table table = tv.getTable();
int linesToShow = Math.min(Math.max(results.size(), 5), 15);
int heightHint = table.getItemHeight() * linesToShow;
GridDataFactory.fillDefaults().grab(true, true).hint(800, heightHint).applyTo(table);
// repository
TableViewerColumn tc = new TableViewerColumn(tv, SWT.NONE);
TableColumn col = tc.getColumn();
tc.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
@SuppressWarnings("unchecked") Entry<Repository, Object> item = (Entry<Repository, Object>) element;
return utils.getRepositoryName(item.getKey());
}
});
col.setText(UIText.MultiPullResultDialog_RepositoryColumnHeader);
layout.setColumnData(col, new ColumnWeightData(200, 200));
createComparator(col, 0);
// fetch status
tc = new TableViewerColumn(tv, SWT.NONE);
col = tc.getColumn();
tc.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
@SuppressWarnings("unchecked") Entry<Repository, Object> item = (Entry<Repository, Object>) element;
if (item.getValue() instanceof IStatus)
return UIText.MultiPullResultDialog_UnknownStatus;
PullResult pullRes = (PullResult) item.getValue();
if (pullRes.getFetchResult() == null) {
return UIText.MultiPullResultDialog_NothingFetchedStatus;
} else if (pullRes.getFetchResult().getTrackingRefUpdates().isEmpty()) {
return UIText.MultiPullResultDialog_NothingUpdatedStatus;
} else {
int updated = pullRes.getFetchResult().getTrackingRefUpdates().size();
if (updated == 1) {
return UIText.MultiPullResultDialog_UpdatedOneMessage;
}
return NLS.bind(UIText.MultiPullResultDialog_UpdatedMessage, Integer.valueOf(updated));
}
}
});
col.setText(UIText.MultiPullResultDialog_FetchStatusColumnHeader);
layout.setColumnData(col, new ColumnWeightData(200, 200));
createComparator(col, 1);
// update status
tc = new TableViewerColumn(tv, SWT.NONE);
col = tc.getColumn();
tc.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
@SuppressWarnings("unchecked") Entry<Repository, Object> item = (Entry<Repository, Object>) element;
if (item.getValue() instanceof IStatus) {
return UIText.MultiPullResultDialog_UnknownStatus;
}
PullResult pullRes = (PullResult) item.getValue();
if (pullRes.getMergeResult() != null) {
return NLS.bind(UIText.MultiPullResultDialog_MergeResultMessage, MergeResultDialog.getStatusText(pullRes.getMergeResult().getMergeStatus()));
} else if (pullRes.getRebaseResult() != null) {
RebaseResult res = pullRes.getRebaseResult();
return NLS.bind(UIText.MultiPullResultDialog_RebaseResultMessage, RebaseResultDialog.getStatusText(res.getStatus()));
} else {
return UIText.MultiPullResultDialog_NothingUpdatedStatus;
}
}
});
col.setText(UIText.MultiPullResultDialog_UpdateStatusColumnHeader);
layout.setColumnData(col, new ColumnWeightData(200, 200));
createComparator(col, 2);
// overall status
tc = new TableViewerColumn(tv, SWT.NONE);
col = tc.getColumn();
tc.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
@SuppressWarnings("unchecked") Entry<Repository, Object> item = (Entry<Repository, Object>) element;
Object resultOrError = item.getValue();
if (resultOrError instanceof IStatus) {
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_STOP);
}
PullResult res = (PullResult) item.getValue();
boolean success = res.isSuccessful();
if (!success) {
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ELCL_STOP);
}
return null;
}
@Override
public String getText(Object element) {
@SuppressWarnings("unchecked") Entry<Repository, Object> item = (Entry<Repository, Object>) element;
if (item.getValue() instanceof IStatus) {
IStatus status = (IStatus) item.getValue();
return status.getMessage();
}
PullResult res = (PullResult) item.getValue();
if (res.isSuccessful()) {
return UIText.MultiPullResultDialog_OkStatus;
} else {
return UIText.MultiPullResultDialog_FailedStatus;
}
}
});
col.setText(UIText.MultiPullResultDialog_OverallStatusColumnHeader);
layout.setColumnData(col, new ColumnWeightData(200, 200));
createComparator(col, 3);
table.setHeaderVisible(true);
table.setLinesVisible(true);
tv.setInput(results.entrySet());
return main;
}
use of org.eclipse.jface.layout.TableColumnLayout in project portfolio by buchen.
the class AccountListView method createTopTable.
// //////////////////////////////////////////////////////////////
// top table: accounts
// //////////////////////////////////////////////////////////////
@Override
protected void createTopTable(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
accounts = new TableViewer(container, SWT.FULL_SELECTION);
ColumnEditingSupport.prepare(accounts);
accountColumns = new // $NON-NLS-1$
ShowHideColumnHelper(// $NON-NLS-1$
AccountListView.class.getSimpleName() + "@top2", getPreferenceStore(), accounts, layout);
// $NON-NLS-1$
Column column = new NameColumn("0", Messages.ColumnAccount, SWT.None, 150);
column.setLabelProvider(new // NOSONAR
NameColumnLabelProvider() {
@Override
public Color getForeground(Object e) {
boolean isRetired = ((Account) e).isRetired();
return isRetired ? Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY) : null;
}
});
column.getEditingSupport().addListener(this);
accountColumns.addColumn(column);
column = new Column(Messages.ColumnBalance, SWT.RIGHT, 80);
column.setDescription(Messages.ColumnBalance_Description);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
return Values.Amount.format(((Account) e).getCurrentAmount(LocalDateTime.now().with(LocalTime.MAX)));
}
});
ColumnViewerSorter.create(o -> ((Account) o).getCurrentAmount(LocalDateTime.now().with(LocalTime.MAX))).attachTo(column);
accountColumns.addColumn(column);
column = new CurrencyColumn();
column.setEditingSupport(new CurrencyEditingSupport() {
@Override
public boolean canEdit(Object element) {
return ((Account) element).getTransactions().isEmpty();
}
});
accountColumns.addColumn(column);
column = new NoteColumn();
column.getEditingSupport().addListener(this);
accountColumns.addColumn(column);
accountColumns.createColumns();
accounts.getTable().setHeaderVisible(true);
accounts.getTable().setLinesVisible(true);
accounts.setContentProvider(ArrayContentProvider.getInstance());
resetInput();
accounts.refresh();
accounts.addSelectionChangedListener(event -> {
Account account = (Account) ((IStructuredSelection) event.getSelection()).getFirstElement();
updateOnAccountSelected(account);
transactions.setData(Account.class.toString(), account);
transactions.setInput(account != null ? account.getTransactions() : new ArrayList<AccountTransaction>(0));
transactions.refresh();
});
hookContextMenu(accounts.getTable(), this::fillAccountsContextMenu);
}
use of org.eclipse.jface.layout.TableColumnLayout in project portfolio by buchen.
the class AccountListView method createTransactionTable.
protected Control createTransactionTable(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
transactions = new TableViewer(container, SWT.FULL_SELECTION | SWT.MULTI);
ColumnViewerToolTipSupport.enableFor(transactions, ToolTip.NO_RECREATE);
ColumnEditingSupport.prepare(transactions);
transactionsColumns = new // $NON-NLS-1$
ShowHideColumnHelper(// $NON-NLS-1$
AccountListView.class.getSimpleName() + "@bottom5", getPreferenceStore(), transactions, layout);
Column column = new Column(Messages.ColumnDate, SWT.None, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
return Values.DateTime.format(((AccountTransaction) e).getDateTime());
}
@Override
public Color getForeground(Object element) {
return colorFor((AccountTransaction) element);
}
});
ColumnViewerSorter.create(new AccountTransaction.ByDateAmountTypeAndHashCode()).attachTo(column, SWT.DOWN);
// $NON-NLS-1$
new DateTimeEditingSupport(AccountTransaction.class, "dateTime").addListener(this).attachTo(column);
transactionsColumns.addColumn(column);
column = new Column(Messages.ColumnTransactionType, SWT.None, 100);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
AccountTransaction t = (AccountTransaction) e;
return t.getType().toString();
}
@Override
public Color getForeground(Object element) {
return colorFor((AccountTransaction) element);
}
});
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(AccountTransaction.class, "type"));
transactionsColumns.addColumn(column);
column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
AccountTransaction t = (AccountTransaction) e;
long v = t.getAmount();
if (t.getType().isDebit())
v = -v;
return Values.Money.format(Money.of(t.getCurrencyCode(), v), getClient().getBaseCurrency());
}
@Override
public Color getForeground(Object element) {
return colorFor((AccountTransaction) element);
}
});
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(AccountTransaction.class, "amount"));
transactionsColumns.addColumn(column);
column = new Column(Messages.Balance, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Money balance = transaction2balance.get(e);
return balance != null ? Values.Money.format(balance, getClient().getBaseCurrency()) : null;
}
});
column.setSorter(ColumnViewerSorter.create(new AccountTransaction.ByDateAmountTypeAndHashCode()));
transactionsColumns.addColumn(column);
column = new Column(Messages.ColumnSecurity, SWT.None, 250);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
AccountTransaction t = (AccountTransaction) e;
return t.getSecurity() != null ? String.valueOf(t.getSecurity()) : null;
}
@Override
public Color getForeground(Object element) {
return colorFor((AccountTransaction) element);
}
});
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(AccountTransaction.class, "security"));
transactionsColumns.addColumn(column);
column = new Column(Messages.ColumnShares, SWT.RIGHT, 80);
column.setLabelProvider(new SharesLabelProvider() {
@Override
public Long getValue(Object e) {
AccountTransaction t = (AccountTransaction) e;
if (t.getCrossEntry() instanceof BuySellEntry) {
return ((BuySellEntry) t.getCrossEntry()).getPortfolioTransaction().getShares();
} else if (t.getType() == Type.DIVIDENDS && t.getShares() != 0) {
return t.getShares();
} else {
return null;
}
}
@Override
public Color getForeground(Object element) {
return colorFor((AccountTransaction) element);
}
});
new // $NON-NLS-1$
ValueEditingSupport(// $NON-NLS-1$
AccountTransaction.class, // $NON-NLS-1$
"shares", // $NON-NLS-1$
Values.Share) {
@Override
public boolean canEdit(Object element) {
AccountTransaction t = (AccountTransaction) element;
return t.getType() == AccountTransaction.Type.DIVIDENDS;
}
}.addListener(this).attachTo(column);
transactionsColumns.addColumn(column);
column = new Column(Messages.ColumnPerShare, SWT.RIGHT, 80);
column.setDescription(Messages.ColumnPerShare_Description);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
AccountTransaction t = (AccountTransaction) e;
if (t.getCrossEntry() instanceof BuySellEntry) {
PortfolioTransaction pt = ((BuySellEntry) t.getCrossEntry()).getPortfolioTransaction();
return Values.Quote.format(pt.getGrossPricePerShare(), getClient().getBaseCurrency());
} else if (t.getType() == Type.DIVIDENDS && t.getShares() != 0) {
long dividendPerShare = Math.round(t.getAmount() * Values.Share.divider() * Values.Quote.factorToMoney() / t.getShares());
return Values.Quote.format(Quote.of(t.getCurrencyCode(), dividendPerShare), getClient().getBaseCurrency());
} else {
return null;
}
}
@Override
public Color getForeground(Object element) {
return colorFor((AccountTransaction) element);
}
});
transactionsColumns.addColumn(column);
column = new Column(Messages.ColumnOffsetAccount, SWT.None, 120);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
AccountTransaction t = (AccountTransaction) e;
return t.getCrossEntry() != null ? t.getCrossEntry().getCrossOwner(t).toString() : null;
}
@Override
public Color getForeground(Object element) {
return colorFor((AccountTransaction) element);
}
});
transactionsColumns.addColumn(column);
column = new Column(Messages.ColumnNote, SWT.None, 200);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
return ((AccountTransaction) e).getNote();
}
@Override
public Color getForeground(Object element) {
return colorFor((AccountTransaction) element);
}
@Override
public Image getImage(Object e) {
String note = ((AccountTransaction) e).getNote();
return note != null && note.length() > 0 ? Images.NOTE.image() : null;
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(AccountTransaction.class, "note").attachTo(column);
// $NON-NLS-1$
new StringEditingSupport(AccountTransaction.class, "note").addListener(this).attachTo(column);
transactionsColumns.addColumn(column);
transactionsColumns.createColumns();
transactions.getTable().setHeaderVisible(true);
transactions.getTable().setLinesVisible(true);
transactions.setContentProvider(ArrayContentProvider.getInstance());
hookContextMenu(transactions.getTable(), this::fillTransactionsContextMenu);
hookKeyListener();
return container;
}
use of org.eclipse.jface.layout.TableColumnLayout in project portfolio by buchen.
the class EditReportingPeriodsDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
Composite tableArea = new Composite(container, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, true).minSize(SWT.DEFAULT, 200).applyTo(tableArea);
TableColumnLayout layout = new TableColumnLayout();
tableArea.setLayout(layout);
tableViewer = new TableViewer(tableArea, SWT.BORDER | SWT.MULTI | SWT.MULTI);
final Table table = tableViewer.getTable();
table.setHeaderVisible(false);
table.setLinesVisible(false);
TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.None);
layout.setColumnData(column.getColumn(), new ColumnWeightData(100));
tableViewer.setLabelProvider(new LabelProvider() {
@Override
public Image getImage(Object element) {
return Images.TEXT.image();
}
});
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
tableViewer.setInput(periods);
new ContextMenu(tableViewer.getTable(), m -> fillContextMenu(m)).hook();
return container;
}
use of org.eclipse.jface.layout.TableColumnLayout in project portfolio by buchen.
the class FilePickerDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
Composite container = new Composite(composite, SWT.None);
GridDataFactory.fillDefaults().grab(true, true).hint(400, 300).applyTo(container);
GridLayoutFactory.fillDefaults().numColumns(1).applyTo(container);
Label label = new Label(container, SWT.None);
label.setText(Messages.SaveHandlerTitle);
GridDataFactory.fillDefaults().grab(true, false).applyTo(label);
Composite tableArea = new Composite(container, SWT.NONE);
GridDataFactory.fillDefaults().grab(false, true).applyTo(tableArea);
tableArea.setLayout(new FillLayout());
TableColumnLayout layout = new TableColumnLayout();
tableArea.setLayout(layout);
Table table = new Table(tableArea, SWT.BORDER | SWT.CHECK | SWT.MULTI);
tableViewer = new CheckboxTableViewer(table);
table.setHeaderVisible(false);
table.setLinesVisible(false);
TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.None);
layout.setColumnData(column.getColumn(), new ColumnWeightData(100));
tableViewer.setLabelProvider(labelProvider);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
tableViewer.setInput(elements);
tableViewer.setCheckedElements(elements);
tableViewer.setComparator(new ViewerComparator());
hookListener();
return composite;
}
Aggregations