use of org.eclipse.ui.forms.events.HyperlinkEvent in project bndtools by bndtools.
the class GeneralInfoPart method createSection.
private void createSection(Section section, FormToolkit toolkit) {
section.setText("Basic Information");
KeyStroke assistKeyStroke = null;
try {
assistKeyStroke = KeyStroke.getInstance("Ctrl+Space");
} catch (ParseException x) {
// Ignore
}
FieldDecoration contentAssistDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
Composite composite = toolkit.createComposite(section);
section.setClient(composite);
toolkit.createLabel(composite, "Version:");
txtVersion = toolkit.createText(composite, "", SWT.BORDER);
ToolTips.setupMessageAndToolTipFromSyntax(txtVersion, Constants.BUNDLE_VERSION);
Hyperlink linkActivator = toolkit.createHyperlink(composite, "Activator:", SWT.NONE);
txtActivator = toolkit.createText(composite, "", SWT.BORDER);
ToolTips.setupMessageAndToolTipFromSyntax(txtActivator, Constants.BUNDLE_ACTIVATOR);
toolkit.createLabel(composite, "Declarative Services:");
cmbComponents = new Combo(composite, SWT.READ_ONLY);
// Content Proposal for the Activator field
ContentProposalAdapter activatorProposalAdapter = null;
ActivatorClassProposalProvider proposalProvider = new ActivatorClassProposalProvider();
activatorProposalAdapter = new ContentProposalAdapter(txtActivator, new TextContentAdapter(), proposalProvider, assistKeyStroke, UIConstants.autoActivationCharacters());
activatorProposalAdapter.addContentProposalListener(proposalProvider);
activatorProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
activatorProposalAdapter.setLabelProvider(new JavaContentProposalLabelProvider());
activatorProposalAdapter.setAutoActivationDelay(1000);
// Decorator for the Activator field
ControlDecoration decorActivator = new ControlDecoration(txtActivator, SWT.LEFT | SWT.CENTER, composite);
decorActivator.setImage(contentAssistDecoration.getImage());
decorActivator.setMarginWidth(3);
if (assistKeyStroke == null) {
decorActivator.setDescriptionText("Content Assist is available. Start typing to activate");
} else {
decorActivator.setDescriptionText(MessageFormat.format("Content Assist is available. Press {0} or start typing to activate", assistKeyStroke.format()));
}
decorActivator.setShowOnlyOnFocus(true);
decorActivator.setShowHover(true);
// Decorator for the Components combo
ControlDecoration decorComponents = new ControlDecoration(cmbComponents, SWT.LEFT | SWT.CENTER, composite);
decorComponents.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
decorComponents.setMarginWidth(3);
decorComponents.setDescriptionText("Use Java annotations to detect Declarative Service Components.");
decorComponents.setShowOnlyOnFocus(false);
decorComponents.setShowHover(true);
// Listeners
txtVersion.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
lock.ifNotModifying(new Runnable() {
@Override
public void run() {
addDirtyProperty(Constants.BUNDLE_VERSION);
}
});
}
});
cmbComponents.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
lock.ifNotModifying(new Runnable() {
@Override
public void run() {
ComponentChoice old = componentChoice;
int index = cmbComponents.getSelectionIndex();
if (index >= 0 && index < ComponentChoice.values().length) {
componentChoice = ComponentChoice.values()[cmbComponents.getSelectionIndex()];
if (old != componentChoice) {
addDirtyProperty(aQute.bnd.osgi.Constants.SERVICE_COMPONENT);
addDirtyProperty(aQute.bnd.osgi.Constants.DSANNOTATIONS);
if (old == null) {
cmbComponents.remove(ComponentChoice.values().length);
}
}
}
}
});
}
});
txtActivator.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent ev) {
lock.ifNotModifying(new Runnable() {
@Override
public void run() {
addDirtyProperty(Constants.BUNDLE_ACTIVATOR);
}
});
}
});
linkActivator.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent ev) {
String activatorClassName = txtActivator.getText();
if (activatorClassName != null && activatorClassName.length() > 0) {
try {
IJavaProject javaProject = getJavaProject();
if (javaProject == null)
return;
IType activatorType = javaProject.findType(activatorClassName);
if (activatorType != null) {
JavaUI.openInEditor(activatorType, true, true);
}
} catch (PartInitException e) {
ErrorDialog.openError(getManagedForm().getForm().getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening an editor for activator class '{0}'.", activatorClassName), e));
} catch (JavaModelException e) {
ErrorDialog.openError(getManagedForm().getForm().getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error searching for activator class '{0}'.", activatorClassName), e));
}
}
}
});
activatorProposalAdapter.addContentProposalListener(new IContentProposalListener() {
@Override
public void proposalAccepted(IContentProposal proposal) {
if (proposal instanceof JavaContentProposal) {
String selectedPackageName = ((JavaContentProposal) proposal).getPackageName();
if (!model.isIncludedPackage(selectedPackageName)) {
model.addPrivatePackage(selectedPackageName);
}
}
}
});
// Layout
GridLayout layout = new GridLayout(2, false);
layout.horizontalSpacing = 15;
composite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.TOP, true, false);
txtVersion.setLayoutData(gd);
txtActivator.setLayoutData(gd);
cmbComponents.setLayoutData(gd);
}
use of org.eclipse.ui.forms.events.HyperlinkEvent in project bndtools by bndtools.
the class JPMBrowserView method createPartControl.
@Override
public void createPartControl(Composite parent) {
StackLayout stack = new StackLayout();
parent.setLayout(stack);
JpmPreferences prefs = new JpmPreferences();
if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_EXTERNAL) {
external = true;
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(2, false));
new Label(composite, SWT.NONE).setText("JPM is configured to open in an external browser.");
Hyperlink linkToPrefs = new Hyperlink(composite, SWT.NONE);
linkToPrefs.setText("Open Preference Page");
linkToPrefs.setUnderlined(true);
linkToPrefs.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getViewSite().getShell(), "bndtools.prefPages.jpm", new String[] { "bndtools.prefPages.jpm" }, null);
dialog.open();
}
});
// linkToPrefs.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
stack.topControl = composite;
} else {
if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_PLATFORM_DEFAULT) {
browser = new Browser(parent, SWT.NONE);
stack.topControl = browser;
} else if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_WEBKIT) {
browser = new Browser(parent, SWT.WEBKIT);
stack.topControl = browser;
} else if (prefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_MOZILLA) {
browser = new Browser(parent, SWT.MOZILLA);
stack.topControl = browser;
}
createActions();
// Prevent navigation away from JPM4J.org, and redirect from HTTP back to HTTPS
browser.addLocationListener(new LocationAdapter() {
@Override
public void changing(LocationEvent event) {
setContentDescription(event.location);
/*
*
if (event.location.startsWith(HTTPS_URL))
return;
if (event.location.startsWith(HTTP_URL))
event.location = event.location.replaceFirst(HTTP_URL, HTTP_URL);
else
event.doit = false;
*/
}
});
}
selectionService = getViewSite().getWorkbenchWindow().getSelectionService();
selectionService.addSelectionListener(this);
handleWorkbenchSelection(selectionService.getSelection());
}
use of org.eclipse.ui.forms.events.HyperlinkEvent in project bndtools by bndtools.
the class RepositoriesView method createPartControl.
@Override
public void createPartControl(final Composite parent) {
// CREATE CONTROLS
final StackLayout stackLayout = new StackLayout();
parent.setLayout(stackLayout);
FormToolkit toolkit = new FormToolkit(parent.getDisplay());
Composite defaultParent = toolkit.createComposite(parent, SWT.NONE);
FillLayout fill = new FillLayout();
fill.marginHeight = 5;
fill.marginWidth = 5;
defaultParent.setLayout(fill);
if (!Central.hasWorkspaceDirectory()) {
FormText form = toolkit.createFormText(defaultParent, true);
form.setText("<form><p>No workspace configuration found. <a>Create a new Bnd workspace...</a></p></form>", true, false);
form.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent e) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
WorkspaceSetupWizard wizard = new WorkspaceSetupWizard();
wizard.init(workbench, StructuredSelection.EMPTY);
WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
dialog.open();
}
});
} else {
toolkit.createLabel(defaultParent, "Repositories are loading, please wait...");
}
stackLayout.topControl = defaultParent;
parent.layout();
final Composite mainPanel = new Composite(parent, SWT.NONE);
filterPanel = filterPart.createControl(mainPanel, 5, 5);
Tree tree = new Tree(mainPanel, SWT.FULL_SELECTION | SWT.MULTI);
filterPanel.setBackground(tree.getBackground());
viewer = new TreeViewer(tree);
contentProvider = new SearchableRepositoryTreeContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
super.inputChanged(viewer, oldInput, newInput);
if (newInput != null) {
stackLayout.topControl = mainPanel;
advancedSearchAction.setEnabled(true);
refreshAction.setEnabled(true);
collapseAllAction.setEnabled(true);
configureOfflineAction();
parent.layout();
}
}
};
viewer.setContentProvider(contentProvider);
ColumnViewerToolTipSupport.enableFor(viewer);
viewer.setLabelProvider(new RepositoryTreeLabelProvider(false));
getViewSite().setSelectionProvider(viewer);
Central.addRepositoriesViewer(viewer, RepositoriesView.this);
JpmPreferences jpmPrefs = new JpmPreferences();
final boolean showJpmOnClick = jpmPrefs.getBrowserSelection() != JpmPreferences.PREF_BROWSER_EXTERNAL;
// LISTENERS
filterPart.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
String filter = (String) event.getNewValue();
updatedFilter(filter);
}
});
ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
if (target == null)
return false;
if (canDrop(target, transferType))
return true;
boolean valid = false;
if (target instanceof RepositoryPlugin) {
if (((RepositoryPlugin) target).canWrite()) {
if (URLTransfer.getInstance().isSupportedType(transferType))
return true;
if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection instanceof IStructuredSelection) {
for (Iterator<?> iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
Object element = iter.next();
if (element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion) {
valid = true;
break;
}
if (element instanceof IFile) {
valid = true;
break;
}
if (element instanceof IAdaptable) {
IFile file = (IFile) ((IAdaptable) element).getAdapter(IFile.class);
if (file != null) {
valid = true;
break;
}
}
}
}
} else {
valid = true;
}
}
}
return valid;
}
@Override
public void dragEnter(DropTargetEvent event) {
super.dragEnter(event);
event.detail = DND.DROP_COPY;
}
@Override
public boolean performDrop(Object data) {
if (RepositoriesView.this.performDrop(getCurrentTarget(), getCurrentEvent().currentDataType, data)) {
viewer.refresh(getCurrentTarget(), true);
return true;
}
boolean copied = false;
if (URLTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) {
try {
URL url = new URL((String) URLTransfer.getInstance().nativeToJava(getCurrentEvent().currentDataType));
if (!url.getPath().endsWith(".jar")) {
String uris = url.toString();
if (uris.contains("#!/p/sha/")) {
MessageDialog.openWarning(null, "Dropped URL is a JPM Revision Identifier, not a JAR", "The dropped URL is a JPM identifier, can only be dropped on a JPM repository. You can also select the revision on JPM and drag the 'jar' link of the revision to any of the other repositories.");
return false;
}
}
File tmp = File.createTempFile("dwnl", ".jar");
try (HttpClient client = new HttpClient()) {
IO.copy(client.connect(url), tmp);
}
if (isJarFile(tmp)) {
copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), new File[] { tmp });
} else {
tmp.delete();
MessageDialog.openWarning(null, "Unrecognized Artifact", "The dropped URL is not recognized as a remote JAR file: " + url.toString());
}
} catch (Exception e) {
return false;
}
} else if (data instanceof String[]) {
String[] paths = (String[]) data;
File[] files = new File[paths.length];
for (int i = 0; i < paths.length; i++) {
files[i] = new File(paths[i]);
}
copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files);
} else if (data instanceof IResource[]) {
IResource[] resources = (IResource[]) data;
File[] files = new File[resources.length];
for (int i = 0; i < resources.length; i++) {
files[i] = resources[i].getLocation().toFile();
}
copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files);
} else if (data instanceof IStructuredSelection) {
File[] files = convertSelectionToFiles((IStructuredSelection) data);
if (files != null && files.length > 0)
copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files);
}
return copied;
}
};
dropAdapter.setFeedbackEnabled(false);
dropAdapter.setExpandEnabled(false);
viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { URLTransfer.getInstance(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), LocalSelectionTransfer.getTransfer() }, dropAdapter);
viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new SelectionDragAdapter(viewer));
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
boolean writableRepoSelected = false;
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
Object element = selection.getFirstElement();
if (element instanceof RepositoryPlugin) {
RepositoryPlugin repo = (RepositoryPlugin) element;
writableRepoSelected = repo.canWrite();
}
addBundlesAction.setEnabled(writableRepoSelected);
}
});
tree.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent ev) {
Object element = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
if (element instanceof ContinueSearchElement) {
try {
getViewSite().getPage().showView(Plugin.JPM_BROWSER_VIEW_ID, null, showJpmOnClick ? IWorkbenchPage.VIEW_ACTIVATE : IWorkbenchPage.VIEW_CREATE);
} catch (PartInitException e) {
Plugin.getDefault().getLog().log(e.getStatus());
}
}
}
});
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
if (!event.getSelection().isEmpty()) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
final Object element = selection.getFirstElement();
if (element instanceof IAdaptable) {
final URI uri = (URI) ((IAdaptable) element).getAdapter(URI.class);
if (uri == null && element instanceof RepositoryEntry) {
boolean download = MessageDialog.openQuestion(getSite().getShell(), "Repositories", "This repository entry is unable to be opened because it has not been downloaded. Download and open it now?");
if (download) {
final RepositoryEntry entry = (RepositoryEntry) element;
Job downloadJob = new Job("Downloading repository entry " + entry.getBsn()) {
@Override
protected IStatus run(IProgressMonitor monitor) {
final File repoFile = entry.getFile(true);
if (repoFile != null && repoFile.exists()) {
getSite().getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
openURI(repoFile.toURI());
}
});
}
return Status.OK_STATUS;
}
};
downloadJob.setUser(true);
downloadJob.schedule();
}
} else if (uri != null) {
openURI(uri);
}
} else if (element instanceof ContinueSearchElement) {
ContinueSearchElement searchElement = (ContinueSearchElement) element;
try {
JpmPreferences jpmPrefs = new JpmPreferences();
if (jpmPrefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_EXTERNAL) {
URI browseUrl = searchElement.browse();
getViewSite().getWorkbenchWindow().getWorkbench().getBrowserSupport().getExternalBrowser().openURL(browseUrl.toURL());
} else
getViewSite().getPage().showView(Plugin.JPM_BROWSER_VIEW_ID, null, IWorkbenchPage.VIEW_VISIBLE);
} catch (PartInitException e) {
Plugin.getDefault().getLog().log(e.getStatus());
} catch (Exception e) {
Plugin.getDefault().getLog().log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Failed to load repository browser view", e));
}
} else if (element instanceof RepositoryPlugin) {
viewer.setExpandedState(element, !viewer.getExpandedState(element));
}
}
}
});
createContextMenu();
// LAYOUT
GridLayout layout = new GridLayout(1, false);
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginWidth = 0;
layout.marginHeight = 0;
mainPanel.setLayout(layout);
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
filterPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
// Toolbar
createActions();
fillToolBar(getViewSite().getActionBars().getToolBarManager());
prefs.addPropertyChangeListener(workspaceOfflineListener);
// synthenic call to "refresh" so that we can get the repositories to show up in the UI
new WorkspaceJob("Load repositories") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
try {
Central.refreshPlugins();
} catch (Exception e) {
// ignore errors there may be no workspace yet
}
return Status.OK_STATUS;
}
}.schedule();
IActionBars actionBars = getViewSite().getActionBars();
actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction);
}
use of org.eclipse.ui.forms.events.HyperlinkEvent in project cubrid-manager by CUBRID.
the class NoticeDashboardPage method createFormText.
private FormText createFormText(Composite composite) {
FormText text = toolkit.createFormText(composite, true);
text.addHyperlinkListener(new IHyperlinkListener() {
public void linkExited(HyperlinkEvent e) {
}
public void linkEntered(HyperlinkEvent e) {
}
public void linkActivated(HyperlinkEvent e) {
String href = (String) e.getHref();
String url = CommonUITool.urlEncodeForSpaces(href);
try {
IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();
IWebBrowser browser = support.getExternalBrowser();
browser.openURL(new URL(url));
} catch (PartInitException e1) {
LOGGER.error("Can not initialize web browser on the application.", e1);
} catch (MalformedURLException e2) {
LOGGER.error("The url {} is invalid.", url, e2);
}
}
});
return text;
}
use of org.eclipse.ui.forms.events.HyperlinkEvent in project cubrid-manager by CUBRID.
the class NoticeDashboardPage method createActionSection.
@SuppressWarnings("unused")
private void createActionSection(Composite parent) {
Section section = createStaticSection(parent, Messages.titleCommonAction);
Composite composite = toolkit.createComposite(section);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
composite.setLayout(gridLayout);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
section.setClient(composite);
GridData data = new GridData(GridData.BEGINNING);
data.widthHint = 200;
ImageHyperlink addHost = toolkit.createImageHyperlink(composite, SWT.NONE);
addHost.setLayoutData(data);
addHost.setImage(CommonUIPlugin.getImageDescriptor("icons/action/host_add.png").createImage());
addHost.setText(Messages.titleAddHostBtn);
addHost.addHyperlinkListener(new IHyperlinkListener() {
public void linkExited(HyperlinkEvent e) {
}
public void linkEntered(HyperlinkEvent e) {
}
public void linkActivated(HyperlinkEvent e) {
ActionManager.getInstance().getAction("com.cubrid.cubridmanager.ui.host.action.AddHostAction").run();
}
});
ImageHyperlink connectHost = toolkit.createImageHyperlink(composite, SWT.NONE);
connectHost.setLayoutData(data);
connectHost.setImage(CommonUIPlugin.getImageDescriptor("icons/action/host_connect.png").createImage());
connectHost.setText(Messages.titleConHostBtn);
connectHost.addHyperlinkListener(new IHyperlinkListener() {
public void linkExited(HyperlinkEvent e) {
}
public void linkEntered(HyperlinkEvent e) {
}
public void linkActivated(HyperlinkEvent e) {
ActionManager.getInstance().getAction("com.cubrid.cubridmanager.ui.host.action.ConnectHostAction").run();
}
});
ImageHyperlink preferences = toolkit.createImageHyperlink(composite, SWT.NONE);
preferences.setLayoutData(data);
preferences.setImage(CommonUIPlugin.getImageDescriptor("icons/action/property.png").createImage());
preferences.setText(Messages.titlePreferencesBtn);
preferences.addHyperlinkListener(new IHyperlinkListener() {
public void linkExited(HyperlinkEvent e) {
}
public void linkEntered(HyperlinkEvent e) {
}
public void linkActivated(HyperlinkEvent e) {
ActionManager.getInstance().getAction("preferences").run();
}
});
ImageHyperlink help = toolkit.createImageHyperlink(composite, SWT.NONE);
help.setLayoutData(data);
help.setImage(CommonUIPlugin.getImageDescriptor("icons/action/help.png").createImage());
help.setText(Messages.titleHelpBtn);
help.addHyperlinkListener(new IHyperlinkListener() {
public void linkExited(HyperlinkEvent e) {
}
public void linkEntered(HyperlinkEvent e) {
}
public void linkActivated(HyperlinkEvent e) {
ActionManager.getInstance().getAction(HelpDocumentAction.ID).run();
}
});
}
Aggregations