下面列出了怎么用org.eclipse.ui.forms.events.HyperlinkEvent的API类实例代码及写法,或者点击链接到github查看源代码。
public LinkEntry(Composite composite, FormToolkit toolkit, String name, LinkAction action) {
Label label = new Label(composite, SWT.NONE);
label.setFont(boldFont);
label.setText(name);
// If not available then use a text field
text = new Text(composite, SWT.WRAP | SWT.MULTI | SWT.READ_ONLY);
text.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.FALSE);
text.setText(Messages.AppOverviewEditorNotAvailable);
text.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false));
IDEUtil.paintBackgroundToMatch(text, composite);
link = toolkit.createHyperlink(composite, "", SWT.WRAP);
link.setVisible(false);
GridData data = new GridData(GridData.BEGINNING, GridData.BEGINNING, true, false);
data.horizontalIndent = 2;
data.exclude = true;
link.setLayoutData(data);
link.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(org.eclipse.ui.forms.events.HyperlinkEvent e) {
action.execute(linkUrl);
}
});
}
public void createStandardLinkText ( final Composite parent, final String linkFactory, final String attributeName, final String label, final String textMessage, final ConfigurationEditorInput input, final Object valueType )
{
this.toolkit.createLabel ( parent, label + ":" );
final Text text = this.toolkit.createText ( parent, "" );
text.setMessage ( textMessage );
text.setLayoutData ( new GridData ( GridData.FILL, GridData.BEGINNING, true, true ) );
text.setToolTipText ( textMessage );
final IObservableValue value = Observables.observeMapEntry ( input.getDataMap (), attributeName, valueType );
this.dbc.bindValue ( WidgetProperties.text ( SWT.Modify ).observe ( text ), value );
final Hyperlink link = this.toolkit.createHyperlink ( parent, "link", SWT.NONE );
link.setLayoutData ( new GridData ( GridData.FILL, GridData.BEGINNING, false, false ) );
link.addHyperlinkListener ( new HyperlinkAdapter () {
@Override
public void linkActivated ( final HyperlinkEvent e )
{
EditorHelper.handleOpen ( PlatformUI.getWorkbench ().getActiveWorkbenchWindow ().getActivePage (), input.getConnectionUri (), linkFactory, text.getText () );
}
} );
}
private void createControls() {
Composite cloudForgeComposite = new Composite(this, SWT.NULL);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
cloudForgeComposite.setLayout(layout);
GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
cloudForgeComposite.setLayoutData(data);
ImageHyperlink cloudForgeLink = new ImageHyperlink(cloudForgeComposite, SWT.NONE);
cloudForgeLink.setImage(SVNUIPlugin.getPlugin().getImageDescriptor(ISVNUIConstants.IMG_CLOUDFORGE).createImage());
cloudForgeLink.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent evt) {
try {
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(SIGNUP_URL));
} catch (Exception e) {
MessageDialog.openError(getShell(), "Sign-up for CloudForge", e.getMessage());
}
}
});
cloudForgeLink.setToolTipText(SIGNUP_URL);
}
/**
* Create a label with a hyperlink and a picture.
*
* @param parent the parent widget of the label
* @param text the text of the label
* @param action the action to be executed if the hyperlink is activated
*/
private void createLabel(Composite parent, String text, final BuildpathModifierAction action) {
FormText formText= createFormText(parent, text);
Image image= fImageMap.get(action.getId());
if (image == null) {
image= action.getImageDescriptor().createImage();
fImageMap.put(action.getId(), image);
}
formText.setImage("defaultImage", image); //$NON-NLS-1$
formText.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
action.run();
}
});
}
@Override
public void linkActivated(HyperlinkEvent e) {
String href = (String) e.getHref();
Action action = null;
if ("export.app".equals(href)) {
action = new NativeArtifactExportAction(getConfigEditor());
} else if ("plugin.folder".equals(href)) {
action = new LaunchCordovaPluginWizardAction(getConfigEditor(),
CordovaPluginSelectionPage.PLUGIN_SOURCE_DIRECTORY);
} else if ("plugin.git".equals(href)) {
action = new LaunchCordovaPluginWizardAction(getConfigEditor(),
CordovaPluginSelectionPage.PLUGIN_SOURCE_GIT);
} else if ("plugin.registry".equals(href)) {
action = new LaunchCordovaPluginWizardAction(getConfigEditor(),
CordovaPluginSelectionPage.PLUGIN_SOURCE_REGISTRY);
}
Assert.isNotNull(action);
action.run();
}
public void loadErrorPage() {
if (scrolledForm != null) {
Stream.of(toolBarManager.getItems()).forEach(IContributionItem::update);
disposePageContent();
final Composite composite = toolkit.createComposite(scrolledForm.getBody());
composite.setLayout(GridLayoutFactory.fillDefaults().create());
composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).align(SWT.CENTER, SWT.CENTER).create());
final ImageHyperlink imageHyperlink = toolkit.createImageHyperlink(composite, SWT.NONE);
imageHyperlink.setLayoutData(GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).create());
imageHyperlink.setImage(UIPlugin.getImage("icons/error.png"));
imageHyperlink.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
getEditor().setActiveEditor(getSourceEditor());
}
});
final Label label = toolkit.createLabel(composite, Messages.parseError);
label.setLayoutData(GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).create());
label.setFont(BonitaStudioFontRegistry.getPreferenceTitleFont());
scrolledForm.getParent().layout(true, true);
}
}
/**
* Return a Label that acts as a hyperlink
*
* @param parent
* parent control
* @param text
* text to display
* @param lis
* hyperlink listener that is called on Mouse click
* @return a Label
*/
public static Label createHyperlink(final Composite parent, final String text,
final IHyperlinkListener lis){
final Label ret = new Label(parent, SWT.NONE);
ret.setText(text);
ret.setForeground(UiDesk.getColorRegistry().get(Messages.SWTHelper_blue)); //$NON-NLS-1$
ret.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(final MouseEvent e){
if (lis != null) {
lis.linkActivated(new HyperlinkEvent(ret, ret, text, e.stateMask));
}
}
});
return ret;
}
private void populateInnerComposite(){
for (String l : fields) {
Hyperlink hl = tk.createHyperlink(inner, l, SWT.NONE);
hl.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(final HyperlinkEvent e){
Hyperlink h = (Hyperlink) e.getSource();
String dbField = getDbFieldForField(h.getText());
fireSortEvent(dbField);
}
});
hl.setBackground(inner.getBackground());
}
createSelectors(fields.length);
for (int i = 0; i < selectors.length; i++) {
selectors[i] = new ElexisText(tk.createText(inner, "", SWT.BORDER)); //$NON-NLS-1$
selectors[i].addModifyListener(ml);
selectors[i].addSelectionListener(sl);
selectors[i].setToolTipText(Messages.DefaultControlFieldProvider_enterFilter); //$NON-NLS-1$
selectors[i].setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
SWTHelper.setSelectOnFocus((Text) selectors[i].getWidget());
}
}
private void createConfigViewer(Composite container, FormToolkit toolkit) {
UI.formLabel(container, toolkit, M.ServerUrl);
configViewer = new ConfigViewer(container);
configViewer.setInput(CloudConfigurations.get());
Hyperlink editConfig = UI.formLink(container, toolkit, M.Edit);
editConfig.setForeground(Colors.linkBlue());
editConfig.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(null, CloudPreferencePage.ID,
null, null);
dialog.setBlockOnOpen(true);
dialog.open();
configViewer.setInput(CloudConfigurations.get());
configViewer.select(CloudConfigurations.getDefault());
}
});
}
private void deleteFile(HyperlinkEvent e) {
if (getModel().externalFile == null)
return;
File file = getDatabaseFile();
boolean doIt = Question.ask(M.DeleteFile,
M.SourceFileDeleteQuestion);
if (!doIt)
return;
try {
if (file.exists())
file.delete();
getModel().externalFile = null;
updateFileLink();
getEditor().setDirty(true);
} catch (Exception ex) {
log.error("failed to delete file", ex);
}
}
private void setHyperlinkAction(Hyperlink link, LinkAction action) {
link.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent arg0) {
action.execute();
}
});
}
@Override
protected void addModifyImageHandler(Hyperlink modifyImageLink) {
modifyImageLink.addHyperlinkListener(new HyperlinkAdapter() {
public void linkActivated(HyperlinkEvent e) {
handleModifyImage();
}
});
}
@Override
protected void addDeleteImageHandler(Hyperlink deleteImageLink) {
deleteImageLink.addHyperlinkListener(new HyperlinkAdapter() {
public void linkActivated(HyperlinkEvent e) {
handleDeleteImage();
}
});
}
private Composite createEmptyBDMComposite(Composite parent) {
Composite client = widgetFactory.createComposite(parent);
client.setLayout(GridLayoutFactory.fillDefaults().create());
client.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
Composite emptyBDMComposite = widgetFactory.createComposite(client);
emptyBDMComposite.setLayout(GridLayoutFactory.fillDefaults().create());
emptyBDMComposite
.setLayoutData(GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).grab(true, true).create());
final ImageHyperlink imageHyperlink = widgetFactory.createImageHyperlink(emptyBDMComposite, SWT.NO_FOCUS);
imageHyperlink.setLayoutData(GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.FILL).create());
imageHyperlink.setImage(Pics.getImage("defineBdm_60.png", DataPlugin.getDefault()));
imageHyperlink.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
commandExecutor.executeCommand(DEFINE_BDM_COMMAND, null);
}
});
Link labelLink = new Link(emptyBDMComposite, SWT.NO_FOCUS);
widgetFactory.adapt(labelLink, false, false);
labelLink.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.CENTER).create());
labelLink.setText(Messages.defineBdmTooltip);
labelLink.addListener(SWT.Selection, e -> commandExecutor.executeCommand(DEFINE_BDM_COMMAND, null));
return client;
}
@Override
public Composite createControl(final Composite parent){
// Form form=tk.createForm(parent);
// form.setLayoutData(SWTHelper.getFillGridData(1,true,1,false));
// Composite ret=form.getBody();
Composite ret = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
layout.marginWidth = 0;
ret.setLayout(layout);
ret.setBackground(parent.getBackground());
ImageHyperlink hClr = tk.createImageHyperlink(ret, SWT.NONE); //$NON-NLS-1$
hClr.setImage(Images.IMG_CLEAR.getImage());
hClr.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(final HyperlinkEvent e){
clearValues();
}
});
hClr.setBackground(parent.getBackground());
inner = new Composite(ret, SWT.NONE);
GridLayout lRet = new GridLayout(fields.length, true);
inner.setLayout(lRet);
inner.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
populateInnerComposite();
return ret;
}
@Override
@SuppressWarnings("synthetic-access")
public void linkActivated(final HyperlinkEvent e){
if (actPatient != null) {
AnschriftEingabeDialog aed =
new AnschriftEingabeDialog(form.getShell(), actPatient);
aed.open();
inpAdresse.setText(actPatient.getPostAnschrift(false), false, false);
}
}
@Override
public void linkActivated(HyperlinkEvent e) {
ImageHyperlink link = (ImageHyperlink) e.widget;
Object data = link.getData();
if (data instanceof CategoryDescriptor) {
CategoryDescriptor d = (CategoryDescriptor) data;
Category c = Cache.getEntityCache().get(Category.class, d.id);
Navigator.select(c);
} else if (data instanceof CategorizedDescriptor) {
App.openEditor((CategorizedDescriptor) data);
}
}
@Override
public void linkActivated(HyperlinkEvent e) {
if (model instanceof CategorizedEntity)
App.openEditor((CategorizedEntity) model);
else if (model instanceof CategorizedDescriptor)
App.openEditor((CategorizedDescriptor) model);
}
@Override
public void linkActivated(HyperlinkEvent e) {
if (entity == null || versionLabel == null)
return;
Version version = new Version(entity.version);
if (type == MAJOR)
version.incMajor();
else
version.incMinor();
entity.version = version.getValue();
versionLabel.setText(version.toString());
editor.setDirty(true);
}
private void openFile(HyperlinkEvent evt) {
File file = getDatabaseFile();
if (file == null)
return;
if (file.exists()) {
log.trace("open file {}", file);
Desktop.browse(file.toURI().toString());
} else {
MsgBox.info(M.FileDoesNotExist);
}
}
public static void onClick(Hyperlink link, Consumer<HyperlinkEvent> fn) {
if (link == null || fn == null)
return;
link.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
fn.accept(e);
}
});
}
public ProjectLinkSection(Composite parent, FormToolkit toolkit, int hSpan, int vSpan) {
Section section = toolkit.createSection(parent, ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR);
section.setText(Messages.AppOverviewEditorProjectLinksSection);
section.setLayoutData(new GridData(SWT.FILL,SWT.FILL, true, false, hSpan, vSpan));
section.setExpanded(true);
Composite composite = toolkit.createComposite(section);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 5;
layout.marginWidth = 10;
layout.verticalSpacing = 10;
layout.horizontalSpacing = 10;
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
toolkit.paintBordersFor(composite);
section.setClient(composite);
// Link description and manage link
toLinkDescriptionText = new Text(composite, SWT.WRAP | SWT.MULTI | SWT.READ_ONLY);
toLinkDescriptionText.setText(Messages.AppOverviewEditorProjectLinksNoLinks);
toLinkDescriptionText.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.FALSE);
toLinkDescriptionText.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, true, false));
IDEUtil.paintBackgroundToMatch(toLinkDescriptionText, composite);
Hyperlink manageLink = toolkit.createHyperlink(composite, Messages.AppOverviewEditorProjectLinksManageLinks, SWT.WRAP);
GridData data = new GridData(GridData.END, GridData.BEGINNING, false, false);
manageLink.setLayoutData(data);
manageLink.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(org.eclipse.ui.forms.events.HyperlinkEvent e) {
final CodewindConnection conn = getConn();
final CodewindApplication app = getApp(conn);
ManageLinksAction.openManageLinksDialog(app);
}
});
// Link table
toLinkTable = new LinkTable(composite, toolkit, Messages.LinkMgmtProjectColumn);
// From link description
fromLinkDescriptionText = new Text(composite, SWT.WRAP | SWT.MULTI | SWT.READ_ONLY);
fromLinkDescriptionText.setText(Messages.AppOverviewEditorProjectLinksNoFromLinks);
fromLinkDescriptionText.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.FALSE);
fromLinkDescriptionText.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, true, false, 2, 1));
IDEUtil.paintBackgroundToMatch(fromLinkDescriptionText, composite);
// From link table
fromLinkTable = new LinkTable(composite, toolkit, Messages.AppOverviewEditorProjectLinksSourceProject);
// Initialize
toLinkTable.tableComp.setVisible(false);
((GridData) toLinkTable.tableComp.getLayoutData()).exclude = true;
fromLinkTable.tableComp.setVisible(false);
((GridData) fromLinkTable.tableComp.getLayoutData()).exclude = true;
}
public void linkActivated(final HyperlinkEvent he) {
getModelEditor().addOrShowAdvancedModelPage();
}
public void linkActivated(final HyperlinkEvent he) {
getModelEditor().addOrShowAdvancedTLCOptionsPage();
}
public void linkActivated(final HyperlinkEvent he) {
getModelEditor().addOrShowResultsPage();
}
public void linkActivated(final HyperlinkEvent e) {
if (getModel() != null) {
getModel().setOriginalTraceShown(true);
TLCErrorView.updateErrorView(getModelEditor());
}
}
public void createControl(Composite parent) {
Composite outerContainer = new Composite(parent,SWT.NONE);
outerContainer.setLayout(new GridLayout());
outerContainer.setLayoutData(
new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
Composite treeGroup = new Composite(outerContainer, SWT.NONE);
GridLayout treeLayout = new GridLayout();
treeLayout.numColumns = 1;
treeGroup.setLayout(treeLayout);
treeGroup.setLayoutData(
new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
treeViewer = new TreeViewer(treeGroup, SWT.BORDER | SWT.SINGLE);
treeViewer.setLabelProvider(new RepositorySourceLabelProvider());
treeViewer.setContentProvider(new RepositorySourceContentProvider());
treeViewer.setUseHashlookup(true);
GridData layoutData = new GridData();
layoutData.grabExcessHorizontalSpace = true;
layoutData.grabExcessVerticalSpace = true;
layoutData.horizontalAlignment = GridData.FILL;
layoutData.verticalAlignment = GridData.FILL;
layoutData.minimumHeight = 300;
layoutData.minimumWidth = 300;
treeViewer.getControl().setLayoutData(layoutData);
treeViewer.setInput(this);
treeViewer.setSelection(new StructuredSelection("URL"));
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
Object selectedObject = ((IStructuredSelection)treeViewer.getSelection()).getFirstElement();
if (selectedObject instanceof ISVNRepositorySourceProvider) {
selectedRepositorySourceProvider = (ISVNRepositorySourceProvider)selectedObject;
}
else {
selectedRepositorySourceProvider = null;
}
setPageComplete(!treeViewer.getSelection().isEmpty());
}
});
Hyperlink repositoryProviderLink = new Hyperlink(treeGroup, SWT.NONE);
repositoryProviderLink.setUnderlined(true);
repositoryProviderLink.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
repositoryProviderLink.setText("Click here to see the list of available providers.");
repositoryProviderLink.setToolTipText(REPOSITORY_PROVIDERS_WIKI_URL);
repositoryProviderLink.addHyperlinkListener(new HyperlinkAdapter() {
public void linkActivated(HyperlinkEvent evt) {
showAvailableProviders();
}
});
Composite cloudForgeComposite = new CloudForgeComposite(outerContainer, SWT.NONE);
GridData data = new GridData(GridData.VERTICAL_ALIGN_END | GridData.GRAB_VERTICAL | GridData.FILL_VERTICAL);
cloudForgeComposite.setLayoutData(data);
setControl(outerContainer);
}
@Override
public void linkEntered(HyperlinkEvent e) {
}
@Override
public void linkExited(HyperlinkEvent e) {
}
public KontaktBlatt(Composite parent, int style, IViewSite vs){
super(parent, style);
site = vs;
tk = UiDesk.getToolkit();
setLayout(new FillLayout());
form = tk.createScrolledForm(this);
Composite body = form.getBody();
body.setLayout(new GridLayout());
Composite cTypes = tk.createComposite(body, SWT.BORDER);
for (int i = 0; i < types.length; i++) {
bTypes[i] = tk.createButton(cTypes, typLabels[i], SWT.CHECK);
bTypes[i].addSelectionListener(tba);
bTypes[i].setData(types[i]);
if (types[i].equalsIgnoreCase(IS_USER)) {
bTypes[i].setEnabled(false);
}
}
cTypes.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
cTypes.setLayout(new FillLayout());
Composite bottom = tk.createComposite(body);
bottom.setLayout(new FillLayout());
bottom.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
actKontakt = (Kontakt) ElexisEventDispatcher.getSelected(Kontakt.class);
afDetails = new AutoForm(bottom, def);
Composite cAnschrift = tk.createComposite(body);
cAnschrift.setLayout(new GridLayout(2, false));
cAnschrift.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
Hyperlink hAnschrift =
tk.createHyperlink(cAnschrift, Messages.KontaktBlatt_Postal, SWT.NONE); //$NON-NLS-1$
hAnschrift.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e){
if (actKontakt != null) {
new AnschriftEingabeDialog(getShell(), actKontakt).open();
ElexisEventDispatcher.fireSelectionEvent(actKontakt);
}
}
});
lbAnschrift = tk.createLabel(cAnschrift, StringConstants.EMPTY, SWT.WRAP);
lbAnschrift.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
setOrganisationFieldsVisible(false);
def[19].getWidget().setVisible(false); //field is only added for UI presentation reasons
GlobalEventDispatcher.addActivationListener(this, site.getPart());
setUnlocked(false);
}