//get the image and text for each completion
@Override
public Image getImage(Object element) {
CtxInsensitiveImportComplProposal comp = ((CtxInsensitiveImportComplProposal) element);
return comp.getImage();
}
@Override
public String getText(Object element) {
CtxInsensitiveImportComplProposal comp = ((CtxInsensitiveImportComplProposal) element);
return comp.getDisplayString();
}
}) {
//override things to return the last position of the dialog correctly
/**
* @see org.eclipse.ui.dialogs.SelectionDialog#getDialogBoundsSettings()
*/
protected IDialogSettings getDialogBoundsSettings() {
IDialogSettings section = dialogSettings.getSection(DIALOG_SETTINGS);
if (section == null) {
section = dialogSettings.addNewSection(DIALOG_SETTINGS);
}
return section;
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#getInitialSize()
*/
protected Point getInitialSize() {
IDialogSettings settings = getDialogBoundsSettings();
if (settings != null) {
try {
int width = settings.getInt("DIALOG_WIDTH"); //$NON-NLS-1$
int height = settings.getInt("DIALOG_HEIGHT"); //$NON-NLS-1$
if (width > 0 & height > 0) {
return new Point(width, height);
}
} catch (NumberFormatException nfe) {
//make the default return
}
}
return new Point(300, 300);
}
};
dialog.setTitle("Choose import");
dialog.setMessage("Which import should be added?");
dialog.setElements(props.toArray());
int returnCode = dialog.open();
if (returnCode == Window.OK) {
ICompletionProposalExtension2 firstResult = (ICompletionProposalExtension2) dialog
.getFirstResult();
completionsToApply.add(firstResult);
} else if (returnCode == Window.CANCEL) {
keepGoing[0] = false;
continue;
}
}
} catch (Exception e) {
Log.log(e);
}
}
} catch (Exception e) {
Log.log(e);
}
}
for (ICompletionProposalExtension2 comp : completionsToApply) {
int offset = 0; //the offset is not used in this case, because the actual completion does nothing,
//we'll only add the import.
comp.apply(edit.getPySourceViewer(), ' ', 0, offset);
}
return true;
}