Composite buttons_composite = new Composite(routing_table_container, SWT.NONE);
GridData g = new GridData(GridData.FILL_HORIZONTAL);
buttons_composite.setLayoutData(g);
buttons_composite.setLayout(new GridLayout(1,false));
final Button setKadStatus = new Button(buttons_composite, SWT.NONE);
try {
setKadStatus.setEnabled(_core.getConfigurationManager().isJKadAutoconnectEnabled());
} catch (ConfigurationManagerException e) {
e.printStackTrace();
setKadStatus.setEnabled(false);
}
g = new GridData();
g.widthHint = 150;
setKadStatus.setLayoutData(g);
setKadStatus.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (_core.getJKadManager().isConnected())
_core.getJKadManager().disconnect();
else
if (_core.getJKadManager().isConnecting())
_core.getJKadManager().disconnect();
else
if (_core.getJKadManager().isDisconnected()) {
setKadStatus.setEnabled(false);
Display.getDefault().asyncExec(new Runnable() {
public void run() {
_core.getJKadManager().connect();
}
});
}
}
});
if (_core.getJKadManager().isConnected())
setKadStatus.setText(_._("mainwindow.kadtab.disconnect"));
if (_core.getJKadManager().isConnecting())
setKadStatus.setText(_._("mainwindow.kadtab.stop_connecting"));
if (_core.getJKadManager().isDisconnected())
setKadStatus.setText(_._("mainwindow.kadtab.connect"));
_core.getJKadManager().addJKadListener(new JKadListener() {
public void JKadIsConnected() {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (isDisposed()) return;
setKadStatus.setEnabled(true);
setKadStatus.setText(_._("mainwindow.kadtab.disconnect"));
}
});
}
public void JKadIsConnecting() {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (isDisposed()) return;
setKadStatus.setEnabled(true);
setKadStatus.setText(_._("mainwindow.kadtab.stop_connecting"));
}
});
}
public void JKadIsDisconnected() {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (isDisposed()) return;
setKadStatus.setEnabled(true);
routing_table_container.setText(_._("mainwindow.kadtab.kad_nodes"));
setKadStatus.setText(_._("mainwindow.kadtab.connect"));
}
});
}
});
contact_list = new JMTable<KadContact>(routing_table_container,SWT.NONE){
protected int compareObjects(KadContact object1,
KadContact object2, int columnID, boolean order) {
int result = 0;
if (columnID == KAD_CLIENT_ID_COLUMN_ID)
result = object1.getContactID().toHexString().compareTo(object2.getContactID().toHexString());
if (columnID == KAD_CLIENT_DISTANCE_COLUMN_ID)
result = object1.getContactDistance().toBinaryString().compareTo(object2.getContactDistance().toBinaryString());
if (!order)
result = Misc.reverse(result);
return result;
}
protected Menu getPopUpMenu() {
return null;
}
public void updateRow(KadContact object) {
String imageName = "";
if (object.getContactType() == ContactType.Active2MoreHours) imageName="contact0.png";
if (object.getContactType() == ContactType.Active1Hour) imageName="contact1.png";
if (object.getContactType() == ContactType.Active) imageName="contact2.png";
if (object.getContactType() == ContactType.JustAdded) imageName="contact3.png";
if (object.getContactType() == ContactType.ScheduledForRemoval) imageName="contact4.png";
setRowImage(object, KAD_CLIENT_ID_COLUMN_ID, SWTImageRepository.getImage(imageName));
setRowText(object, KAD_CLIENT_ID_COLUMN_ID, object.getContactID().toHexString());
setRowText(object, KAD_CLIENT_DISTANCE_COLUMN_ID, object.getContactDistance().toBinaryString());
}
};
contact_list.setLayoutData(new GridData(GridData.FILL_BOTH));
contact_list.addColumn(SWT.LEFT, KAD_CLIENT_ID_COLUMN_ID, _._("mainwindow.kadtab.contact_list.column.contact_id"), _._("mainwindow.kadtab.contact_list.column.contact_id.desc"), swtPreferences.getColumnWidth(KAD_CLIENT_ID_COLUMN_ID));
contact_list.addColumn(SWT.LEFT, KAD_CLIENT_DISTANCE_COLUMN_ID, _._("mainwindow.kadtab.contact_list.column.contact_distance"), _._("mainwindow.kadtab.contact_list.column.contact_distance.desc"), swtPreferences.getColumnWidth(KAD_CLIENT_DISTANCE_COLUMN_ID));
_core.getJKadManager().getRoutingTable().addListener(new RoutingTableListener() {
public void contactAdded(final KadContact contact) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (isDisposed()) return;
contact_list.addRow(contact);
routing_table_container.setText(_._("mainwindow.kadtab.kad_nodes_number",contact_list.getItemCount()+""));
}
});
}
public void contactRemoved(final KadContact contact) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (isDisposed()) return;
contact_list.removeRow(contact);
routing_table_container.setText(_._("mainwindow.kadtab.kad_nodes_number",contact_list.getItemCount()+""));
}
});
}
public void contactUpdated(final KadContact contact) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (isDisposed()) return;
contact_list.updateRow(contact);
routing_table_container.setText(_._("mainwindow.kadtab.kad_nodes_number",contact_list.getItemCount()+""));
}
});
}
public void allContactsRemoved() {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (isDisposed()) return;
contact_list.clear();
}
});
}
});
for(KadContact contact : _core.getJKadManager().getRoutingTable().getContacts())
contact_list.addRow(contact);
routing_table_container.setText(_._("mainwindow.kadtab.kad_nodes_number",contact_list.getItemCount()+""));
kad_tasks_container.setLayout(new FillLayout());
kad_task_list = new JMTable<KadTask>(kad_tasks_container,SWT.NONE) {
protected int compareObjects(KadTask object1, KadTask object2,
int columnID, boolean order) {
int result = 0;
if (columnID == KAD_TASK_TYPE_COLUMN_ID)
result = object1.task_type.compareTo(object2.task_type);
if (columnID == KAD_TASK_LOOKUP_HASH_COLUMN_ID)
result = object1.task_id.compareTo(object2.task_id);
if (columnID == KAD_TASK_LOOKUP_INFO_COLUMN_ID)
result = object1.task_info.compareTo(object2.task_info);
if (!order)
result = Misc.reverse(result);
return result;
}
protected Menu getPopUpMenu() {
return null;
}
public void updateRow(KadTask object) {
setRowText(object, KAD_TASK_TYPE_COLUMN_ID, object.task_type);
setRowText(object, KAD_TASK_LOOKUP_HASH_COLUMN_ID, object.task_id);
setRowText(object, KAD_TASK_LOOKUP_INFO_COLUMN_ID, object.task_info);
}
};
kad_task_list.addColumn(SWT.LEFT, KAD_TASK_TYPE_COLUMN_ID, _._("mainwindow.kadtab.task_list.column.task_type"), _._("mainwindow.kadtab.task_list.column.task_type.desc"), swtPreferences.getColumnWidth(KAD_TASK_TYPE_COLUMN_ID));
kad_task_list.addColumn(SWT.LEFT, KAD_TASK_LOOKUP_HASH_COLUMN_ID, _._("mainwindow.kadtab.task_list.column.task_hash"), _._("mainwindow.kadtab.task_list.column.task_hash.desc"), swtPreferences.getColumnWidth(KAD_TASK_LOOKUP_HASH_COLUMN_ID));
kad_task_list.addColumn(SWT.LEFT, KAD_TASK_LOOKUP_INFO_COLUMN_ID, _._("mainwindow.kadtab.task_list.column.task_info"), _._("mainwindow.kadtab.task_list.column.task_info.desc"), swtPreferences.getColumnWidth(KAD_TASK_LOOKUP_INFO_COLUMN_ID));
kad_task_list.setLinesVisible(true);
_core.getJKadManager().getLookup().addListener(new LookupListener() {
public void taskAdded(final LookupTask task) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (isDisposed()) return;
KadTask kad_task = lookupTaskToKadTask(task);
if (kad_task != null)
if (!kad_task_list.hasObject(kad_task)) {
task_map.put(task.getTargetID(), kad_task);
kad_task_list.addRow(kad_task);
}
}
});
}
public void taskRemoved(final LookupTask task) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (isDisposed()) return;
KadTask kad_task = task_map.get(task.getTargetID());
if (kad_task == null)
return;
kad_task_list.removeRow(kad_task);
}
});
}
public void taskStarted(final LookupTask task) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (isDisposed()) return;
KadTask kad_task = lookupTaskToKadTask(task);
if (kad_task != null)
if (!kad_task_list.hasObject(kad_task)) {
task_map.remove(task.getTargetID());
task_map.put(task.getTargetID(), kad_task);
kad_task_list.updateRow(kad_task);
}
}
});
}
});
Map<Int128,LookupTask> list = _core.getJKadManager().getLookup().getLookupTasks();
for(LookupTask task : list.values()) {
KadTask kad_task = lookupTaskToKadTask(task);
if (kad_task!=null)
if (!kad_task_list.hasObject(kad_task)) {
task_map.put(task.getTargetID(), kad_task);
kad_task_list.addRow(kad_task);
}
}
_core.getConfigurationManager().addConfigurationListener(new ConfigurationAdapter() {
public void jkadStatusChanged(boolean newStatus) {
if (newStatus == false) {
setKadStatus.setEnabled(false);
} else
setKadStatus.setEnabled(true);
}
});
}