/* | |
* Copyright (c) Robert Bosch GmbH. All rights reserved. | |
*/ | |
package org.eclipse.blockchain.ui.views; | |
import java.util.Set; | |
import org.eclipse.blockchain.core.Web3jHandler; | |
import org.eclipse.swt.SWT; | |
import org.eclipse.swt.events.SelectionAdapter; | |
import org.eclipse.swt.events.SelectionEvent; | |
import org.eclipse.swt.layout.GridData; | |
import org.eclipse.swt.layout.GridLayout; | |
import org.eclipse.swt.widgets.Combo; | |
import org.eclipse.swt.widgets.Composite; | |
import org.eclipse.swt.widgets.Label; | |
import org.eclipse.ui.part.ViewPart; | |
/** | |
* @author ADG5COB | |
*/ | |
public class AccountsView extends ViewPart { | |
static Combo accountsCombo; | |
static Label balance; | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public void createPartControl(final Composite parent) { | |
Composite container = new Composite(parent, SWT.None); | |
container.setLayout(new GridLayout(2, false)); | |
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); | |
Label accountLabel = new Label(container, SWT.None); | |
accountLabel.setText("Accounts"); | |
accountLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); | |
AccountsView.accountsCombo = new Combo(container, SWT.READ_ONLY); | |
accountsCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); | |
Set<String> accounts = Web3jHandler.getInstance().getAccount().getAccounts().keySet(); | |
accountsCombo.setItems(accounts.toArray(new String[accounts.size()])); | |
accountsCombo.select(0); | |
// Ether Balance | |
Label etherBalance = new Label(container, SWT.None); | |
etherBalance.setText("Balance"); | |
etherBalance.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); | |
balance = new Label(container, SWT.BORDER); | |
balance.setText(!(accounts.isEmpty()) | |
? Web3jHandler.getInstance().getAccount().getAccountBalance().get(accountsCombo.getText()) : "0.0"); | |
balance.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); | |
accountsCombo.addSelectionListener(new SelectionAdapter() { | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public void widgetSelected(final SelectionEvent e) { | |
balance.setText(Web3jHandler.getInstance().getAccount().getAccountBalance().get(((Combo) e.widget).getText())); | |
balance.getParent().layout(); | |
} | |
}); | |
} | |
/** | |
* @param items - Set the accounts | |
*/ | |
public static void setAccountsCombo(final String[] items) { | |
if (accountsCombo != null) { | |
accountsCombo.setItems(items); | |
accountsCombo.getAccessible().getControl().update(); | |
accountsCombo.select(0); | |
balance.setText(Web3jHandler.getInstance().getAccount().getAccountBalance().get(accountsCombo.getText())); | |
} | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
protected void setPartName(final String partName) { | |
super.setPartName("Geth Accounts"); | |
} | |
/** | |
* {@inheritDoc} | |
*/ | |
@Override | |
public void setFocus() { | |
} | |
} |