viewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event)
{
logger.debug("viewer double-clicked");
TreeSelection selection = (TreeSelection)event.getSelection();
logger.trace("selection = " + selection.getClass().getName());
Object item = selection.getFirstElement();
if(item instanceof Campaign)
{
// TODO: open campaign properties editor
logger.debug("open properties editor");
try
{
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new CampaignEditorInput((Campaign)item), CampaignEditor.ID, true, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
}
catch(PartInitException e)
{
logger.error("unable to open campaign editor: " + e.getMessage(), e);
MessageDialog.openError(getViewSite().getShell(), res.getLocaleString("campaign.editor.error.opening"), e.getLocalizedMessage());
}
}
else if(item instanceof CampaignSection)
{
logger.debug("campaign section");
// TODO: nothing?
}
else if(item instanceof Participant)
{
logger.debug("open participant editor");
try
{
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new ParticipantEditorInput((Participant)item), ParticipantEditor.ID, true, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
}
catch(PartInitException e)
{
logger.error("unable to open participant editor: " + e.getMessage(), e);
MessageDialog.openError(getViewSite().getShell(), res.getLocaleString("participant.editor.error.opening"), e.getLocalizedMessage());
}
}
else if(item instanceof PlayerCharacter ||
item instanceof NonPlayerCharacter)
{
logger.trace("campaign item (player/npc): " + item.getClass().getName());
try
{
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new CharacterEditorInput((Creature)item), CharacterEditor.ID, true, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
}
catch(PartInitException e)
{
logger.error("unable to open character editor: " + e.getMessage(), e);
MessageDialog.openError(getViewSite().getShell(), res.getLocaleString("character.editor.error.opening"), e.getLocalizedMessage());
}
}
else if(item instanceof CampaignItem)
{
logger.trace("campaign item: " + item.getClass().getName());
// TODO: nothing?
}
}
});
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event)
{
logger.debug("viewer selection changed: " + event);
IStructuredSelection selection = (IStructuredSelection)event.getSelection();
logger.trace("selection: " + selection);
Object o = selection.getFirstElement();
logger.trace("o: " + o);
if(o instanceof CampaignSection)
{
logger.trace("selection is a campaign item");
deleteCampaignItemAction.setEnabled(false);
}
else
{
logger.trace("selection is: " + o.getClass().getName());
deleteCampaignItemAction.setEnabled(!selection.isEmpty());
((DeleteCampaignItemAction)deleteCampaignItemAction).setSelection(selection);
}
}
});