Java Code Examples for org.eclipse.swt.custom.StyledText#addMouseListener()

The following examples show how to use org.eclipse.swt.custom.StyledText#addMouseListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DetailsView.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public void insert(Composite parent, int numberOfRow) {
	for (int i = 0; i < params.length; i++) {
		String param = params[i];
		
		new Label(parent, SWT.NONE).setText("");
						
		StyledText lbl = new StyledText(parent, SWT.FULL_SELECTION | SWT.READ_ONLY | SWT.WRAP);
		lbl.setAlwaysShowScrollBars(false);
		lbl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		if( param.matches("^[a-zA-Z0-9]+:\\/\\/.*$") ) {
			lbl.setFont(SWTResourceManager.getFont("Segoe UI", 7, SWT.UNDERLINE_LINK));
			lbl.setForeground(SWTResourceManager.getColor(SWT.COLOR_LINK_FOREGROUND));
			lbl.setCursor(SWTResourceManager.getCursor(SWT.CURSOR_HAND));
			lbl.addMouseListener(new MouseAdapter() {

				@Override
				public void mouseDown(MouseEvent e) {
					eventManager.invoke(l -> l.onOpenInBrowserRequest(param));
				}
			});
		}else {
			lbl.setFont(SWTResourceManager.getFont("Segoe UI", 7, SWT.NORMAL));
		}
		lbl.setText(param);
		
		if (numberOfRow % 2 == 0) {
			lbl.setBackground(SWTResourceManager.getColor(206, 234, 255));
		}
	}
}
 
Example 2
Source File: RenameRefactoringPopup.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void start() {
	editor.getSite().getWorkbenchWindow().getPartService().addPartListener(this);
	final ISourceViewer viewer = editor.getInternalSourceViewer();
	final StyledText textWidget = viewer.getTextWidget();
	textWidget.addControlListener(this);
	textWidget.addMouseListener(this);
	textWidget.addKeyListener(this);
	editor.getSite().getShell().addControlListener(this);
	viewer.addViewportListener(this);
	popup.addDisposeListener(new DisposeListener() {
		@Override
		public void widgetDisposed(DisposeEvent e) {
			editor.getSite().getWorkbenchWindow().getPartService()
					.removePartListener(PopupVisibilityManager.this);
			if (!textWidget.isDisposed()) {
				textWidget.removeControlListener(PopupVisibilityManager.this);
				textWidget.removeMouseListener(PopupVisibilityManager.this);
				textWidget.removeKeyListener(PopupVisibilityManager.this);
			}
			editor.getSite().getShell().removeControlListener(PopupVisibilityManager.this);
			viewer.removeViewportListener(PopupVisibilityManager.this);
			if (menuImage != null) {
				menuImage.dispose();
				menuImage = null;
			}
			if (menuManager != null) {
				menuManager.dispose();
				menuManager = null;
			}
		}
	});
}
 
Example 3
Source File: RenameInformationPopup.java    From typescript.java with MIT License 5 votes vote down vote up
public void start() {
			fEditor.getSite().getWorkbenchWindow().getPartService().addPartListener(this);
			final ISourceViewer viewer= fEditor.getViewer();
			final StyledText textWidget= viewer.getTextWidget();
			textWidget.addControlListener(this);
			textWidget.addMouseListener(this);
			textWidget.addKeyListener(this);
			fEditor.getSite().getShell().addControlListener(this);
			viewer.addTextListener(this);
			viewer.addViewportListener(this);
			fPopup.addDisposeListener(new DisposeListener() {
				@Override
				public void widgetDisposed(DisposeEvent e) {
					fEditor.getSite().getWorkbenchWindow().getPartService().removePartListener(PopupVisibilityManager.this);
					if (! textWidget.isDisposed()) {
						textWidget.removeControlListener(PopupVisibilityManager.this);
						textWidget.removeMouseListener(PopupVisibilityManager.this);
						textWidget.removeKeyListener(PopupVisibilityManager.this);
					}
					fEditor.getSite().getShell().removeControlListener(PopupVisibilityManager.this);
					viewer.removeTextListener(PopupVisibilityManager.this);
					viewer.removeViewportListener(PopupVisibilityManager.this);
//					if (fMenuImage != null) {
//						fMenuImage.dispose();
//						fMenuImage= null;
//					}
					if (fMenuManager != null) {
						fMenuManager.dispose();
						fMenuManager= null;
					}
					fRenameLinkedMode.cancel();
				}
			});
		}
 
Example 4
Source File: StyledTextActionHandler.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adapts a <code>StyledText</code> widget to the handler so that the Copy, Cut,
 * Paste and Select All actions are redirected to it when focused.
 *
 * @param textWidget
 *            the <code>StyledText</code> widget
 */
public void adaptStyledText(StyledText textWidget) {
	if (textWidget == null)
		return;

	styledText = textWidget;
	textWidget.addListener(SWT.Activate, textControlListener);
	textWidget.addListener(SWT.Deactivate, textControlListener);

	textWidget.addKeyListener(keyAdapter);
	textWidget.addMouseListener(mouseAdapter);
}
 
Example 5
Source File: RenameInformationPopup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void start() {
	fEditor.getSite().getWorkbenchWindow().getPartService().addPartListener(this);
	final ISourceViewer viewer= fEditor.getViewer();
	final StyledText textWidget= viewer.getTextWidget();
	textWidget.addControlListener(this);
	textWidget.addMouseListener(this);
	textWidget.addKeyListener(this);
	fEditor.getSite().getShell().addControlListener(this);
	viewer.addTextListener(this);
	viewer.addViewportListener(this);
	fPopup.addDisposeListener(new DisposeListener() {
		public void widgetDisposed(DisposeEvent e) {
			fEditor.getSite().getWorkbenchWindow().getPartService().removePartListener(PopupVisibilityManager.this);
			if (! textWidget.isDisposed()) {
				textWidget.removeControlListener(PopupVisibilityManager.this);
				textWidget.removeMouseListener(PopupVisibilityManager.this);
				textWidget.removeKeyListener(PopupVisibilityManager.this);
			}
			fEditor.getSite().getShell().removeControlListener(PopupVisibilityManager.this);
			viewer.removeTextListener(PopupVisibilityManager.this);
			viewer.removeViewportListener(PopupVisibilityManager.this);
			if (fMenuImage != null) {
				fMenuImage.dispose();
				fMenuImage= null;
			}
			if (fMenuManager != null) {
				fMenuManager.dispose();
				fMenuManager= null;
			}
			fRenameLinkedMode.cancel();
		}
	});
}
 
Example 6
Source File: TypingRunDetector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adds the selection listener to the text widget underlying the viewer, if
 * not already done.
 */
private void ensureSelectionListenerAdded() {
	if (fSelectionListener == null) {
		fSelectionListener= new SelectionListener();
		StyledText textWidget= fViewer.getTextWidget();
		textWidget.addFocusListener(fSelectionListener);
		textWidget.addKeyListener(fSelectionListener);
		textWidget.addMouseListener(fSelectionListener);
	}
}
 
Example 7
Source File: OfflineActionTarget.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Installs this target. I.e. adds all required listeners.
 */
private void install() {
    if (fInstalled)
        return;

    StyledText text = fTextViewer.getTextWidget();
    if (text == null)
        return;

    text.addMouseListener(this);
    text.addFocusListener(this);
    fTextViewer.addTextListener(this);

    ISelectionProvider selectionProvider = fTextViewer.getSelectionProvider();
    if (selectionProvider != null)
        selectionProvider.addSelectionChangedListener(this);

    if (fTextViewer instanceof ITextViewerExtension)
        ((ITextViewerExtension) fTextViewer).prependVerifyKeyListener(this);
    else
        text.addVerifyKeyListener(this);

    keyAssistDialog = new KeyAssistDialog(this.fEdit);
    fInstalled = true;

    //Wait a bit until showing the key assist dialog
    new UIJob("") {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            synchronized (lock) {
                if (fInstalled && keyAssistDialog != null) {
                    keyAssistDialog.open(OfflineActionTarget.this.fEdit.getOfflineActionDescriptions(),
                            OfflineActionTarget.this);
                }
            }
            return Status.OK_STATUS;
        }
    }.schedule(700);
}
 
Example 8
Source File: EditorListener.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Connects all selection listeners to the given {@linkplain IEditorPart editor part}. If an
 * editor part was already bound it will be unbound and replaced with the given editor part.
 *
 * @see #unbind()
 * @param part the editor part to observe
 * @return <code>true</code> if the selection listeners were successfully installed, <code>false
 *     </code> if the selection listeners could not be installed
 */
public boolean bind(final IEditorPart part) {

  if (this.part != null) unbind();

  final ITextViewer viewer = EditorAPI.getViewer(part);

  if (viewer == null) {
    log.warn(
        "could not attach selection listeners to editor part:"
            + part
            + " , could not retrieve text widget");
    return false;
  }

  this.part = part;
  this.viewer = viewer;

  final StyledText textWidget = viewer.getTextWidget();

  textWidget.addControlListener(controlListener);
  textWidget.addMouseListener(mouseListener);
  textWidget.addKeyListener(keyListener);

  viewer.addTextListener(textListener);
  viewer.getSelectionProvider().addSelectionChangedListener(selectionChangedListener);
  viewer.addViewportListener(viewportListener);

  return true;
}
 
Example 9
Source File: IllegalBinaryStateDialog.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates a control with some message and with link to the Binaries preference page.
 *
 * @param parent
 *            the parent composite.
 * @param dialog
 *            the container dialog that has to be closed.
 * @param binary
 *            the binary with the illegal state.
 *
 * @return a control with error message and link that can be reused in dialogs.
 */
public static Control createCustomAreaWithLink(final Composite parent, final Dialog dialog, final Binary binary) {
	final String binaryLabel = binary.getLabel();
	final String prefix = "The requested operation cannot be performed due to invalid '" + binaryLabel
			+ "' settings. Check your '" + binaryLabel
			+ "' configuration and preferences under the corresponding ";
	final String link = "preference page";
	final String suffix = ".";
	final String text = prefix + link + suffix;

	final Composite control = new Composite(parent, NONE);
	control.setLayout(GridLayoutFactory.fillDefaults().create());
	final GridData gridData = GridDataFactory.fillDefaults().align(LEFT, TOP).grab(true, true).create();
	control.setLayoutData(gridData);

	final StyleRange style = new StyleRange();
	style.underline = true;
	style.underlineStyle = UNDERLINE_LINK;

	final StyledText styledText = new StyledText(control, MULTI | READ_ONLY | WRAP);
	styledText.setWordWrap(true);
	styledText.setJustify(true);
	styledText.setText(text);
	final GridData textGridData = GridDataFactory.fillDefaults().align(FILL, FILL).grab(true, true).create();
	textGridData.widthHint = TEXT_WIDTH_HINT;
	textGridData.heightHint = TEXT_HEIGHT_HINT;
	styledText.setLayoutData(textGridData);

	styledText.setEditable(false);
	styledText.setBackground(UIUtils.getSystemColor(COLOR_WIDGET_BACKGROUND));
	final int[] ranges = { text.indexOf(link), link.length() };
	final StyleRange[] styles = { style };
	styledText.setStyleRanges(ranges, styles);

	styledText.addMouseListener(new MouseAdapter() {

		@Override
		public void mouseDown(final MouseEvent event) {
			try {
				final int offset = styledText.getOffsetAtPoint(new Point(event.x, event.y));
				final StyleRange actualStyle = offset >= 0 ? styledText.getStyleRangeAtOffset(offset) : null;
				if (null != actualStyle && actualStyle.underline
						&& UNDERLINE_LINK == actualStyle.underlineStyle) {

					dialog.close();
					final PreferenceDialog preferenceDialog = createPreferenceDialogOn(
							UIUtils.getShell(),
							BinariesPreferencePage.ID,
							FILTER_IDS,
							null);

					if (null != preferenceDialog) {
						preferenceDialog.open();
					}

				}
			} catch (final IllegalArgumentException e) {
				// We are not over the actual text.
			}
		}

	});

	return control;
}
 
Example 10
Source File: ExecutionStatisticsDialog.java    From tlaplus with MIT License 4 votes vote down vote up
@Override
  protected Control createCustomArea(Composite parent) {
final Composite c = new Composite(parent, SWT.BORDER);
c.setLayout(new GridLayout());
c.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

//NOTE: Take care of ExecutionStatisticsCollector.md when updating!!!
final String txt = String.format("%s"
		+ "* Total number of cores and cores assigned to TLC\n"
		+ "* Heap and off-heap memory allocated to TLC\n"
		+ "* TLC's version (git commit SHA)\n"
		+ "* If breadth-first search, depth-first search or simulation mode is active\n"
		+ "* TLC's implementation for the sets of seen and unseen states\n"
		+ "* If TLC has been launched from the TLA Toolbox\n"
		+ "* Name, version, and architecture of your operating system\n"
		+ "* Vendor, version, and architecture of your Java virtual machine\n"
		+ "* The current date and time\n"
		+ "* An installation identifier which allows us to group execution statistics\n\n"
		+ "The execution statistics do not contain personal information. If you wish to revoke\n"
		+ "your consent to share execution statistics at a later point, please chose \n"
		+ "\"Never Share Execution Statistics\" below by re-opening this dialog via\n"
		+ "Help > Opt In/Out Execution Statistics accessible from the Toolbox's main menu.", prettyPrintSelection2(esc));

final StyledText st = new StyledText(c, SWT.SHADOW_NONE | SWT.WRAP);
st.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

st.setEnabled(true);
st.setEditable(false);
st.setText(txt);

final StyleRange[] ranges = new StyleRange[3];
ranges[0] = new StyleRange(txt.indexOf("(TLC) execution statistics"), "(TLC) execution statistics".length(), null, null);
ranges[0].underline = true;
ranges[0].underlineStyle = SWT.UNDERLINE_LINK;
ranges[0].data = "https://exec-stats.tlapl.us";

ranges[1] = new StyleRange(txt.indexOf("publicly available"), "publicly available".length(), null, null);
ranges[1].underline = true;
ranges[1].underlineStyle = SWT.UNDERLINE_LINK;
ranges[1].data = "https://exec-stats.tlapl.us/tlaplus.csv";
		
ranges[2] = new StyleRange(txt.indexOf("git commit SHA"), "git commit SHA".length(), null, null);
ranges[2].underline = true;
ranges[2].underlineStyle = SWT.UNDERLINE_LINK;
ranges[2].data = "https://git-scm.com/book/en/v2/Git-Internals-Git-Objects";

st.setStyleRanges(ranges);
st.addMouseListener(new MouseAdapter() {
	@Override
	public void mouseUp(final MouseEvent event) {
              final int offset = st.getOffsetAtPoint(new Point(event.x, event.y));
              if (offset < 0 || offset >= st.getCharCount()) {
              	return;
              }
		final StyleRange style = st.getStyleRangeAtOffset(offset);
              if (style != null && style.underline && style.underlineStyle == SWT.UNDERLINE_LINK && style.data instanceof String) {
                  try {
				PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL((String) style.data));
			} catch (PartInitException | MalformedURLException notExpectedToHappen) {
				notExpectedToHappen.printStackTrace();
			}
              }
	}
});
	
      return c;
  }
 
Example 11
Source File: CheckForUpdates.java    From Rel with Apache License 2.0 4 votes vote down vote up
/**
 * Create the composite.
 * 
 * @param parent
 * @param style
 */
public CheckForUpdates(Composite parent, int style) {
	super(parent, style);
	GridLayout gridLayout = new GridLayout(1, false);
	gridLayout.marginHeight = 0;
	gridLayout.marginWidth = 0;
	gridLayout.verticalSpacing = 0;
	gridLayout.horizontalSpacing = 0;
	setLayout(gridLayout);
	setVisible(false);

	txtStatus = new StyledText(this, SWT.WRAP);
	txtStatus.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	txtStatus.setEditable(false);
	txtStatus.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
	txtStatus.setBackground(getBackground());
	txtStatus.setFont(FontSize.getThisFontInNewSize(txtStatus.getFont(), 10, SWT.NORMAL));
	txtStatus.addMouseListener(mouseHandler);
	txtStatus.setCaret(new Caret(txtStatus, SWT.NONE));
	setText("Rel updates?");

	updateChecker = new UpdatesCheck(parent.getDisplay()) {
		@Override
		public void completed(SendStatus sendStatus) {
			CheckForUpdates.this.completed(sendStatus);
		}
	};

	TimerTask checkForUpdates = new TimerTask() {
		@Override
		public void run() {
			if (CheckForUpdates.this.isDisposed())
				return;
			getDisplay().asyncExec(() -> {
				if (CheckForUpdates.this.isDisposed())
					return;
				setVisible(true);
				setText("Rel updates?");
				System.out.println("CheckForUpdates: check for updates.");
				updateChecker.doCancel();
				updateChecker.doSend();
			});
		}
	};

	// Check for updates after 10 seconds, then every 12 hours
	Timer checkTimer = new Timer();
	checkTimer.schedule(checkForUpdates, 1000 * 5, 1000 * 60 * 60 * 12);
}
 
Example 12
Source File: PyUnitView.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Sets the text component to be used (in tests we want to set it externally)
 */
/*default*/void setTextComponent(StyledText text) {
    this.testOutputText = text;
    onControlCreated.call(text);
    text.addMouseListener(this.activateLinkmouseListener);
}