use of org.csstudio.autocomplete.proposals.Proposal in project yamcs-studio by yamcs.
the class ContentProposalList method addProposals.
public void addProposals(String provider, Proposal[] proposals, Integer count, Integer index) {
for (Proposal p : proposals) {
p.setOriginalValue(originalValue);
if (p.getValue().equals(originalValue))
hasContentMatchingProposal = true;
}
proposalMap.put(provider, proposals);
countMap.put(provider, count);
length += proposals.length;
providerMap.put(index, provider);
}
use of org.csstudio.autocomplete.proposals.Proposal in project yamcs-studio by yamcs.
the class ContentProposalPopup method getSelectedProposal.
/*
* Return the current selected proposal.
*/
private Proposal getSelectedProposal() {
if (isValid()) {
int index = proposalTable.getSelectionIndex();
if (proposalList == null || index < 0 || index >= getTableLength()) {
return null;
}
int proposalIndex = 0;
for (Proposal proposal : proposalList.getTopProposalList()) {
if (index == proposalIndex) {
return proposal;
}
proposalIndex++;
}
for (String provider : proposalList.getProviderList()) {
if (index == proposalIndex) {
return null;
}
proposalIndex++;
for (Proposal proposal : proposalList.getProposals(provider)) {
if (index == proposalIndex) {
return proposal;
}
proposalIndex++;
}
}
}
return null;
}
use of org.csstudio.autocomplete.proposals.Proposal in project yamcs-studio by yamcs.
the class ContentProposalPopup method adjustBounds.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.dialogs.PopupDialog.adjustBounds()
*/
@Override
protected void adjustBounds() {
adjustTableBounds();
// Now set up a listener to monitor any changes in size.
getShell().addListener(SWT.Resize, new Listener() {
@Override
public void handleEvent(Event e) {
popupSize = getShell().getSize();
if (infoPopup != null) {
infoPopup.close();
Proposal p = getSelectedProposal();
if (p != null) {
showProposalDescription();
}
}
}
});
}
use of org.csstudio.autocomplete.proposals.Proposal in project yamcs-studio by yamcs.
the class ContentProposalPopup method initializeTextLayouts.
private void initializeTextLayouts() {
Display display = Display.getCurrent();
FontData defaultFontData = display.getSystemFont().getFontData()[0];
String fontName = defaultFontData.getName();
int fontHeight = defaultFontData.getHeight();
Font headerFont = new Font(display, new FontData(fontName, fontHeight, SWT.ITALIC | SWT.BOLD));
Font noFont = new Font(display, new FontData(fontName, fontHeight, SWT.NORMAL));
Color black = display.getSystemColor(SWT.COLOR_BLACK);
int index = 0;
textLayouts = new SSTextLayout[getTableLength()];
for (Proposal proposal : proposalList.getTopProposalList()) {
textLayouts[index] = AutoCompleteUIPlugin.getUIHelper().newTextLayout();
String text = getString(proposal);
textLayouts[index].init(display, text);
textLayouts[index].addStyle(noFont, black, 0, text.length());
if (proposal.getStyles() != null && !proposal.getStyles().isEmpty()) {
for (ProposalStyle style : proposal.getStyles()) {
FontData newFontData = new FontData(fontName, fontHeight, style.fontStyle);
Font font = new Font(display, newFontData);
Color color = display.getSystemColor(style.fontColor);
textLayouts[index].addStyle(font, color, style.from, style.to);
}
}
index++;
}
for (String provider : proposalList.getProviderList()) {
textLayouts[index] = AutoCompleteUIPlugin.getUIHelper().newTextLayout();
int count = proposalList.getCount(provider);
String headerText = provider + " (" + count + " matching items)";
textLayouts[index].init(display, headerText);
textLayouts[index].addStyle(headerFont, black, 0, headerText.length());
index++;
for (Proposal proposal : proposalList.getProposals(provider)) {
textLayouts[index] = AutoCompleteUIPlugin.getUIHelper().newTextLayout();
String text = getString(proposal);
textLayouts[index].init(display, text);
textLayouts[index].addStyle(noFont, black, 0, text.length());
if (proposal.getStyles() != null && !proposal.getStyles().isEmpty()) {
for (ProposalStyle style : proposal.getStyles()) {
FontData newFontData = new FontData(fontName, fontHeight, style.fontStyle);
Font font = new Font(display, newFontData);
Color color = display.getSystemColor(style.fontColor);
textLayouts[index].addStyle(font, color, style.from, style.to);
}
}
index++;
}
}
for (SSTextLayout sstl : textLayouts) if (sstl != null && sstl.getBounds() != null && sstl.getBounds().width > maxItemWidth)
maxItemWidth = sstl.getBounds().width;
adjustTableBounds();
}
use of org.csstudio.autocomplete.proposals.Proposal in project yamcs-studio by yamcs.
the class ContentProposalPopup method setProposals.
/*
* Caches the specified proposals and repopulates the table if it has been created.
*/
private void setProposals(ContentProposalList newProposalList) {
if (newProposalList == null) {
newProposalList = getEmptyProposalArray();
}
this.proposalList = newProposalList;
if (!isValid())
return;
// Reset item width
maxItemWidth = 0;
nonSelectableItems.clear();
int proposalIndex = proposalList.getTopProposalList().size();
for (String provider : proposalList.getProviderList()) {
nonSelectableItems.add(proposalIndex);
proposalIndex += proposalList.getProposals(provider).length + 1;
}
// If there is a table
if (isValid()) {
if (USE_VIRTUAL) {
// Set and clear the virtual table. Data will be
// provided in the SWT.SetData event handler.
proposalTable.setItemCount(getTableLength());
proposalTable.clearAll();
initializeTextLayouts();
} else {
// Populate the table manually
proposalTable.setRedraw(false);
proposalTable.setItemCount(getTableLength());
TableItem[] items = proposalTable.getItems();
int index = 0;
for (Proposal proposal : newProposalList.getTopProposalList()) {
TableItem item = items[index];
item.setText(" " + getString(proposal));
item.setImage(getImage(proposal, false));
item.setData(proposal);
index++;
}
for (String provider : newProposalList.getProviderList()) {
TableItem item = items[index];
int count = newProposalList.getCount(provider);
String text = provider + " (" + count + " matching items)";
item.setText(text);
// Data == null => not selectable
item.setData(null);
Display display = Display.getCurrent();
Color color = display.getSystemColor(SWT.COLOR_GRAY);
FontData fontData = item.getFont().getFontData()[0];
Font font = new Font(display, new FontData(fontData.getName(), fontData.getHeight(), SWT.ITALIC | SWT.BOLD));
item.setBackground(color);
item.setFont(font);
index++;
for (Proposal proposal : newProposalList.getProposals(provider)) {
item.setText(" " + getString(proposal));
item.setImage(getImage(proposal, false));
item.setData(proposal);
index++;
}
}
proposalTable.setRedraw(true);
}
if (infoPopup != null) {
infoPopup.close();
}
}
footer.setText("");
if (handleTopProposals) {
adapter.handleTopProposals(newProposalList);
// we stop handle
if (adapter.hasSelectedTopProposal() || newProposalList.allResponded()) {
handleTopProposals = false;
}
}
// Select the top proposal that was displayed, if any
proposalTable.deselectAll();
if (adapter.hasSelectedTopProposal()) {
int index = proposalList.getTopProposalList().indexOf(adapter.getSelectedTopProposal());
if (index >= 0)
selectProposal(index);
}
}
Aggregations