assistKeyStroke = KeyStroke.getInstance("Ctrl+Space");
} catch (ParseException x) {
// Ignore
}
Section mainSection = toolkit.createSection(parent, Section.TITLE_BAR);
mainSection.setText(title);
mainComposite = toolkit.createComposite(mainSection);
mainSection.setClient(mainComposite);
toolkit.createLabel(mainComposite, "Pattern:");
txtName = toolkit.createText(mainComposite, "", SWT.BORDER);
ControlDecoration decPattern = new ControlDecoration(txtName, SWT.LEFT | SWT.TOP, mainComposite);
decPattern.setImage(assistDecor.getImage());
if (assistKeyStroke == null) {
decPattern.setDescriptionText("Content assist is available. Start typing to activate");
} else {
decPattern.setDescriptionText(MessageFormat.format("Content assist is available. Press {0} or start typing to activate", assistKeyStroke.format()));
}
decPattern.setShowHover(true);
decPattern.setShowOnlyOnFocus(true);
PkgPatternsProposalProvider proposalProvider = new PkgPatternsProposalProvider(new FormPartJavaSearchContext(this));
ContentProposalAdapter patternProposalAdapter = new ContentProposalAdapter(txtName, new TextContentAdapter(), proposalProvider, assistKeyStroke, UIConstants.autoActivationCharacters());
patternProposalAdapter.addContentProposalListener(proposalProvider);
patternProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_IGNORE);
patternProposalAdapter.setAutoActivationDelay(1000);
patternProposalAdapter.setLabelProvider(new PkgPatternProposalLabelProvider());
patternProposalAdapter.addContentProposalListener(new IContentProposalListener() {
public void proposalAccepted(IContentProposal proposal) {
PkgPatternProposal patternProposal = (PkgPatternProposal) proposal;
String toInsert = patternProposal.getContent();
int currentPos = txtName.getCaretPosition();
txtName.setSelection(patternProposal.getReplaceFromPos(), currentPos);
txtName.insert(toInsert);
txtName.setSelection(patternProposal.getCursorPosition());
}
});
toolkit.createLabel(mainComposite, "Version:");
txtVersion = toolkit.createText(mainComposite, "", SWT.BORDER);
/*
* Section attribsSection = toolkit.createSection(parent, Section.TITLE_BAR | Section.TWISTIE);
* attribsSection.setText("Extra Attributes"); Composite attribsComposite =
* toolkit.createComposite(attribsSection);
*/
// Listeners
txtName.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
if (!modifyLock.isUnderModification()) {
if (selectedClauses.size() == 1) {
selectedClauses.get(0).setName(txtName.getText());
if (listPart != null) {
listPart.updateLabels(selectedClauses);
listPart.validate();
}
markDirty();
}
}
}
});
txtVersion.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
if (!modifyLock.isUnderModification()) {
String text = txtVersion.getText();
if (text.length() == 0)
text = null;
for (HeaderClause clause : selectedClauses) {
clause.getAttribs().put(Constants.VERSION_ATTRIBUTE, text);
}
if (listPart != null) {
listPart.updateLabels(selectedClauses);
listPart.validate();
}
markDirty();
}
}
});
// Layout
GridData gd;
parent.setLayout(new GridLayout());
mainSection.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
mainComposite.setLayout(new GridLayout(2, false));
gd = new GridData(SWT.FILL, SWT.TOP, true, false);
gd.horizontalIndent = 5;
gd.widthHint = 100;