use of org.eclipse.swt.events.MouseEvent in project cubrid-manager by CUBRID.
the class InformationWindow method createContents.
protected Control createContents(Composite parent) {
final Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new FillLayout());
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
infoText = new StyledText(composite, SWT.None);
infoText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
infoText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
infoText.setEditable(false);
infoText.setEnabled(false);
infoText.addMouseTrackListener(new MouseTrackListener() {
public void mouseHover(MouseEvent e) {
increaseAlpha();
}
public void mouseExit(MouseEvent e) {
reduceAlpha();
}
public void mouseEnter(MouseEvent e) {
increaseAlpha();
}
});
parentShell.addControlListener(new ControlListener() {
public void controlResized(ControlEvent e) {
updateLocation();
}
public void controlMoved(ControlEvent e) {
updateLocation();
}
});
if (Platform.getOS().equals(Platform.OS_WIN32)) {
parentShell.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
updateLocation();
}
});
}
this.getShell().setAlpha(minAlpha);
updateLocation();
return parent;
}
use of org.eclipse.swt.events.MouseEvent in project sling by apache.
the class ChooseArchetypeWizardPage method createControl.
@Override
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
container.setLayout(layout);
layout.numColumns = 3;
layout.verticalSpacing = 9;
useDefaultWorkspaceLocationButton = new Button(container, SWT.CHECK);
GridData useDefaultWorkspaceLocationButtonData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1);
useDefaultWorkspaceLocationButton.setLayoutData(useDefaultWorkspaceLocationButtonData);
useDefaultWorkspaceLocationButton.setText("Use default Workspace location");
useDefaultWorkspaceLocationButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean inWorkspace = useDefaultWorkspaceLocationButton.getSelection();
locationLabel.setEnabled(!inWorkspace);
locationCombo.setEnabled(!inWorkspace);
dialogChanged();
}
});
useDefaultWorkspaceLocationButton.setSelection(true);
locationLabel = new Label(container, SWT.NONE);
GridData locationLabelData = new GridData();
locationLabelData.horizontalIndent = 10;
locationLabel.setLayoutData(locationLabelData);
locationLabel.setText("Location:");
locationLabel.setEnabled(false);
locationCombo = new Combo(container, SWT.NONE);
GridData locationComboData = new GridData(SWT.FILL, SWT.CENTER, true, false);
locationCombo.setLayoutData(locationComboData);
locationCombo.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
dialogChanged();
}
});
locationCombo.setEnabled(false);
Button locationBrowseButton = new Button(container, SWT.NONE);
GridData locationBrowseButtonData = new GridData(SWT.FILL, SWT.CENTER, false, false);
locationBrowseButton.setLayoutData(locationBrowseButtonData);
locationBrowseButton.setText("Browse...");
locationBrowseButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dialog = new DirectoryDialog(getShell());
dialog.setText("Select Location");
String path = locationCombo.getText();
if (path.length() == 0) {
path = ResourcesPlugin.getWorkspace().getRoot().getLocation().toPortableString();
}
dialog.setFilterPath(path);
String selectedDir = dialog.open();
if (selectedDir != null) {
locationCombo.setText(selectedDir);
useDefaultWorkspaceLocationButton.setSelection(false);
dialogChanged();
}
}
});
Label label = new Label(container, SWT.NULL);
label.setText("&Archetype:");
knownArchetypes = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
knownArchetypes.setLayoutData(gd);
knownArchetypes.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
dialogChanged();
}
});
knownArchetypes.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
getContainer().showPage(getNextPage());
}
});
setPageComplete(false);
MavenPlugin.getIndexManager().addIndexListener(this);
setControl(container);
}
use of org.eclipse.swt.events.MouseEvent 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.swt.events.MouseEvent in project eclipse.platform.text by eclipse.
the class OverviewRuler method createControl.
@Override
public Control createControl(Composite parent, ITextViewer textViewer) {
fTextViewer = textViewer;
fHitDetectionCursor = parent.getDisplay().getSystemCursor(SWT.CURSOR_HAND);
fHeader = new Canvas(parent, SWT.NONE);
if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
fHeader.addMouseTrackListener(new MouseTrackAdapter() {
/*
* @see org.eclipse.swt.events.MouseTrackAdapter#mouseHover(org.eclipse.swt.events.MouseEvent)
* @since 3.3
*/
@Override
public void mouseEnter(MouseEvent e) {
updateHeaderToolTipText();
}
});
}
fCanvas = new Canvas(parent, SWT.NO_BACKGROUND);
fCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
if (fTextViewer != null)
doubleBufferPaint(event.gc);
}
});
fCanvas.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent event) {
handleDispose();
fTextViewer = null;
}
});
fCanvas.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent event) {
handleMouseDown(event);
}
});
fCanvas.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent event) {
handleMouseMove(event);
}
});
fCanvas.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseScrolled(MouseEvent e) {
handleMouseScrolled(e);
}
});
if (fTextViewer != null) {
fTextViewer.addTextListener(fInternalListener);
// on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the ruler
fTextViewer.getTextWidget().addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
if (fTextViewer == null) {
return;
}
StyledText textWidget = fTextViewer.getTextWidget();
if (textWidget != null && textWidget.getWordWrap()) {
redraw();
}
}
});
}
return fCanvas;
}
use of org.eclipse.swt.events.MouseEvent in project eclipse.platform.text by eclipse.
the class AbstractInformationControl method addMoveSupport.
/**
* Adds support to move the shell by dragging the given control.
*
* @param control the control that can be used to move the shell
*/
private void addMoveSupport(final Control control) {
MouseAdapter moveSupport = new MouseAdapter() {
private MouseMoveListener fMoveListener;
@Override
public void mouseDown(MouseEvent e) {
Point shellLoc = fShell.getLocation();
final int shellX = shellLoc.x;
final int shellY = shellLoc.y;
Point mouseLoc = control.toDisplay(e.x, e.y);
final int mouseX = mouseLoc.x;
final int mouseY = mouseLoc.y;
fMoveListener = new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e2) {
Point mouseLoc2 = control.toDisplay(e2.x, e2.y);
int dx = mouseLoc2.x - mouseX;
int dy = mouseLoc2.y - mouseY;
fShell.setLocation(shellX + dx, shellY + dy);
}
};
control.addMouseMoveListener(fMoveListener);
}
@Override
public void mouseUp(MouseEvent e) {
control.removeMouseMoveListener(fMoveListener);
fMoveListener = null;
}
};
control.addMouseListener(moveSupport);
}
Aggregations