Java Code Examples for org.eclipse.swt.widgets.Control#getShell()

The following examples show how to use org.eclipse.swt.widgets.Control#getShell() . These examples are extracted from open source projects. 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 Project: nebula   File: GridToolTip.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
   * Creates an inplace tooltip.
   *
   * @param parent parent control.
   */
  public GridToolTip(final Control parent)
  {
      super(parent, SWT.NONE);

      shell = new Shell(parent.getShell(), SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
      shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
      shell.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));

      parent.addListener(SWT.Dispose, new Listener()
      {
	public void handleEvent(Event arg0)
	{
		shell.dispose();
		dispose();
	}
});

      shell.addListener(SWT.Paint, new Listener()
      {
          public void handleEvent(Event e)
          {
              onPaint(e.gc);
          }
      });
  }
 
Example 2
/**
 * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
 */
@Override
public void mouseDown(MouseEvent e) {
  Control theControl = (Control) e.widget;

  Display display = theControl.getDisplay();
  Shell tip = new Shell(theControl.getShell(), SWT.ON_TOP | SWT.TOOL);
  tip.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
  FillLayout layout = new FillLayout();
  layout.marginHeight = 1;
  layout.marginWidth = 2;
  tip.setLayout(layout);
  Label label = new Label(tip, SWT.NONE);
  label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
  label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));

  label.setText(theControl.getToolTipText());
  label.addMouseTrackListener(this);
  Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
  Rectangle rect = theControl.getBounds();
  Point pt = theControl.getParent().toDisplay(rect.x, rect.y);
  tip.setBounds(pt.x, pt.y, size.x, size.y);
  tip.setVisible(true);
}
 
Example 3
/**
 * Installs this closer on it's viewer's text widget.
 */
protected void install()
{
	Control control = fContentAssistSubjectControlAdapter.getControl();
	fControl = control;
	if (Helper.okToUse(control))
	{

		Shell shell = control.getShell();
		fShell = shell;
		shell.addControlListener(this);

		control.addMouseListener(this);
		control.addFocusListener(this);

		/*
		 * 1GGYYWK: ITPJUI:ALL - Dismissing editor with code assist up causes lots of Internal Errors
		 */
		control.addDisposeListener(this);
	}
	if (fViewer != null)
	{
		fViewer.addViewportListener(this);
	}
}
 
Example 4
protected Control createDialogArea(Composite parent2) {
						
		Composite parent= (Composite) super.createDialogArea(parent2);

		Control c= compareEditorInput.createContents(parent);
		c.setLayoutData(new GridData(GridData.FILL_BOTH));

//		Assert.isTrue(! compareEditorInput.getCompareConfiguration().isLeftEditable());
//		Assert.isTrue(! compareEditorInput.getCompareConfiguration().isRightEditable());

		Shell shell= c.getShell();
		shell.setText(compareEditorInput.getTitle());
		shell.setImage(compareEditorInput.getTitleImage());
		PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IHelpContextIds.COMPARE_DIALOG);

		applyDialogFont(parent);
		return parent;
	}
 
Example 5
/**
   * Creates an inplace tooltip.
   *
   * @param parent parent control.
   */
  public GridToolTip(final Control parent)
  {
      super(parent, SWT.NONE);

      shell = new Shell(parent.getShell(), SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
      shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
      shell.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));

      parent.addListener(SWT.Dispose, new Listener()
      {
	public void handleEvent(Event arg0)
	{
		shell.dispose();
		dispose();
	}
});

      shell.addListener(SWT.Paint, new Listener()
      {
          public void handleEvent(Event e)
          {
              onPaint(e.gc);
          }
      });
  }
 
Example 6
String openDialogBox( Control cellEditorWindow, String oldValue )
{
	ExpressionBuilder dialog = new ExpressionBuilder( cellEditorWindow.getShell( ),
			oldValue );
	dialog.setExpressionProvier( new ExpressionProvider( itemHandle ) );

	if ( dialog.open( ) == Dialog.OK )
	{
		String newValue = dialog.getResult( );
		if ( !newValue.equals( oldValue ) )
		{
			return newValue;
		}
	}
	setFocus( );
	return null;
}
 
Example 7
@Override
protected Object openDialogBox(Control cellEditorWindow){
	ContactSelectionDialog dialog = new ContactSelectionDialog(cellEditorWindow.getShell(),
		IContact.class, title, message);
	if (getValue() instanceof IContact) {
		// TODO pre select
	}
	if (dialog.open() == Dialog.OK) {
		return dialog.getSelection();
	}
	return null;
}
 
Example 8
public ShellDocker(Control anchorControl, Shell dockedShell) {
	if (null == anchorControl || anchorControl.isDisposed()) {
		throw new NullPointerException("anchorControl cannot be null or disposed");
	}
	if (null == dockedShell || dockedShell.isDisposed()) {
		throw new NullPointerException("dockedShell cannot be null or disposed");
	}

	this.anchorControl = anchorControl;
	this.dockedShell = dockedShell;
	mainShell = anchorControl.getShell();
}
 
Example 9
@Override
public Shell getShell() {

    // Compatibility: This method should not be used outside the UI
    // thread... but since this condition
    // was not always in the JavaDoc, we still try to return our best guess
    // about the shell if it is
    // called from the wrong thread.
    final Display currentDisplay = Display.getCurrent();
    if (currentDisplay == null) {
        // Uncomment this to locate places that try to access the shell from
        // a background thread
        // WorkbenchPlugin.log(new Exception("Error:
        // IWorkbenchSite.getShell() was called outside the UI thread. Fix
        // this code.")); //$NON-NLS-1$

        final IWorkbenchWindow workbenchWindow = getWorkbenchWindow();
        if (workbenchWindow != null) {
            return workbenchWindow.getShell();
        }
        return null;
    }
    IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    MWindow window = null;
    if (activeWorkbenchWindow != null) {
        window = ((WorkbenchWindow) activeWorkbenchWindow).getModel();
        final Control control = (Control) window.getWidget();
        if (control != null && !control.isDisposed()) {
            return control.getShell();
        }
    }
    // likely means the part has been destroyed, return the parent window's
    // shell, we don't just arbitrarily return the workbench window's shell
    // because we may be in a detached window
    return window == null ? getWorkbenchWindow().getShell() : (Shell) window.getWidget();
}
 
Example 10
private void show( Control focusControl, Point location ) {
  Menu quickMenu = new Menu( focusControl.getShell() );
  OpenWithMenu openWithMenu = new OpenWithMenu( workbenchPage, file );
  openWithMenu.fill( quickMenu, 0 );
  quickMenu.setLocation( location );
  quickMenu.addListener( SWT.Hide, createMenuCloseListener( openWithMenu ) );
  quickMenu.setVisible( true );
}
 
Example 11
Source Project: EasyShell   File: Utils.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private static void showToolTipSWTwidget(Control control, int style, String title, String message) {
    ToolTip tooltip = new ToolTip(control.getShell(), /*SWT.BALLOON | */ style);
    tooltip.setAutoHide(true);
    tooltip.setLocation(control.toDisplay(control.getSize().x/2, control.getSize().y + 5));
    tooltip.setText(title);
    tooltip.setMessage(message);
    tooltip.setVisible(true);
}
 
Example 12
@Override
public Shell getShell() {
    // Compatibility: This method should not be used outside the UI
    // thread... but since this condition
    // was not always in the JavaDoc, we still try to return our best guess
    // about the shell if it is
    // called from the wrong thread.
    Display currentDisplay = Display.getCurrent();
    if (currentDisplay == null) {
        // Uncomment this to locate places that try to access the shell from
        // a background thread
        // WorkbenchPlugin.log(new Exception("Error:
        // IWorkbenchSite.getShell() was called outside the UI thread. Fix
        // this code.")); //$NON-NLS-1$

        return getWorkbenchWindow().getShell();
    }

    Control control = (Control) getMWindow().getWidget();
    if (control != null && !control.isDisposed()) {
        return control.getShell();
    }
    // likely means the part has been destroyed, return the parent window's
    // shell, we don't just arbitrarily return the workbench window's shell
    // because we may be in a detached window
    MWindow window = e4Context.get(MWindow.class);
    return window == null ? getWorkbenchWindow().getShell() : (Shell) window.getWidget();
}
 
Example 13
Source Project: olca-app   File: CommentEditor.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected Object openDialogBox(Control control) {
	Box box = new Box(control.getShell(), oldValue);
	if (box.open() != Dialog.OK)
		return null;
	String newValue = box.value;
	if (Objects.equals(oldValue, newValue))
		return null;
	exchange.description = newValue;
	updateContents(newValue);
	editor.setDirty(true);
	return null;
}
 
Example 14
/**
 * Open the dialog box for the button. 
 * 
 * @param cellEditorWindow
 * @return
 */
protected Object openDialogBox(Control cellEditorWindow) {

	FileDialog fileDialog = new FileDialog(cellEditorWindow.getShell());
	fileDialog.setText("Select a file to import into ICE workspace");
	return fileDialog.open();

}
 
Example 15
public static void
 addCopyToClipMenu(
final Control				control,
final copyToClipProvider	provider )
 {
  MouseAdapter ml = (MouseAdapter)control.getData( MOUSE_LISTENER_KEY );
  
  if ( ml != null ){
  
	  control.removeMouseListener( ml );
  }
  
  ml =
	  new MouseAdapter()
	  {
		  @Override
		  public void
		  mouseDown(
			 MouseEvent e )
		  {
			  if ( control.isDisposed()){

				  return;
			  }

			  final String	text = provider.getText();

			  if ( control.getMenu() != null || text == null || text.length() == 0 ){

				  return;
			  }

			  if (!(e.button == 3 || (e.button == 1 && e.stateMask == SWT.CONTROL))){

				  return;
			  }

			  final Menu menu = new Menu(control.getShell(),SWT.POP_UP);

			  MenuItem   item = new MenuItem( menu,SWT.NONE );

			  item.setData( MENU_ITEM_KEY, "" );

			  String	msg_text_id;

			  if ( provider instanceof copyToClipProvider2 ){

				  msg_text_id = ((copyToClipProvider2)provider).getMenuResource();

			  }else{

				  msg_text_id = "label.copy.to.clipboard";
			  }

			  item.setText( MessageText.getString( msg_text_id ));

			  item.addSelectionListener(
					  new SelectionAdapter()
					  {
						  @Override
						  public void
						  widgetSelected(
								  SelectionEvent arg0)
						  {
							  new Clipboard(control.getDisplay()).setContents(new Object[] {text}, new Transfer[] {TextTransfer.getInstance()});
						  }
					  });

			  control.setMenu( menu );

			  menu.addMenuListener(
					  new MenuAdapter()
					  {
						  @Override
						  public void
						  menuHidden(
								  MenuEvent arg0 )
						  {
							  if ( control.getMenu() == menu ){

								  control.setMenu( null );
							  }
						  }
					  });

			  menu.setVisible( true );
		  }
	  };
  
  control.setData( MOUSE_LISTENER_KEY, ml );
  
  control.addMouseListener( ml );
 }
 
Example 16
/**
 * About to start a long running operation triggered through the wizard.
 * Shows the progress monitor and disables the wizard's buttons and
 * controls.
 * 
 * @param enableCancelButton
 *            <code>true</code> if the Cancel button should be enabled,
 *            and <code>false</code> if it should be disabled
 * @return the saved UI state
 */
private Object aboutToStart(boolean enableCancelButton) {
	Map savedState = null;
	if (getShell() != null) {
		// Save focus control
		Control focusControl = getShell().getDisplay().getFocusControl();
		if (focusControl != null && focusControl.getShell() != getShell()) {
			focusControl = null;
		}
		boolean needsProgressMonitor = wizard.needsProgressMonitor();
		
		// Set the busy cursor to all shells.
		Display d = getShell().getDisplay();
		waitCursor = new Cursor(d, SWT.CURSOR_WAIT);
		setDisplayCursor(waitCursor);
		
		if (useCustomProgressMonitorPart) {
			cancelButton.removeSelectionListener(cancelListener);
			// Set the arrow cursor to the cancel component.
			arrowCursor = new Cursor(d, SWT.CURSOR_ARROW);
			cancelButton.setCursor(arrowCursor);
		}
		
		// Deactivate shell
		savedState = saveUIState(useCustomProgressMonitorPart && needsProgressMonitor && enableCancelButton);
		if (focusControl != null) {
			savedState.put(FOCUS_CONTROL, focusControl);
		}
		// Activate cancel behavior.
		if (needsProgressMonitor) {
			if (enableCancelButton || useCustomProgressMonitorPart) {
				progressMonitorPart.attachToCancelComponent(cancelButton);
			}
			progressMonitorPart.setVisible(true);
		}
		
		// Install traverse listener once in order to implement 'Enter' and 'Space' key blocking
		if (timeWhenLastJobFinished == -1) {
			timeWhenLastJobFinished= 0;
			getShell().addTraverseListener(new TraverseListener() {
				public void keyTraversed(TraverseEvent e) {
					if (e.detail == SWT.TRAVERSE_RETURN || (e.detail == SWT.TRAVERSE_MNEMONIC && e.keyCode == 32)) {
						// We want to ignore the keystroke when we detect that it has been received within the
						// delay period after the last operation has finished.  This prevents the user from accidentally
						// hitting "Enter" or "Space", intending to cancel an operation, but having it processed exactly
						// when the operation finished, thus traversing the wizard.  If there is another operation still
						// running, the UI is locked anyway so we are not in this code.  This listener should fire only
						// after the UI state is restored (which by definition means all jobs are done.
						// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=287887
						if (timeWhenLastJobFinished != 0 && System.currentTimeMillis() - timeWhenLastJobFinished < RESTORE_ENTER_DELAY) {
							e.doit= false;
							return;
						}
						timeWhenLastJobFinished= 0;
					}}
			});
		}
	}
	return savedState;
}
 
Example 17
/**
 * 运行任务的准备工作
 * @return UI状态
 */
@SuppressWarnings("rawtypes")
private Object aboutToStart(boolean enableCancelButton) {
	Map savedState = null;
	if (getShell() != null) {
		// Save focus control
		Control focusControl = getShell().getDisplay().getFocusControl();
		if (focusControl != null && focusControl.getShell() != getShell()) {
			focusControl = null;
		}
		boolean needsProgressMonitor = needsProgressMonitor();

		// 设置Shell的鼠标状态
		Display d = getShell().getDisplay();
		waitCursor = new Cursor(d, SWT.CURSOR_WAIT);
		setDisplayCursor(waitCursor);

		if (useCustomProgressMonitorPart) {
			cancelButton.removeSelectionListener(cancelListener);
			// 设置取消按钮的鼠标状态
			arrowCursor = new Cursor(d, SWT.CURSOR_ARROW);
			cancelButton.setCursor(arrowCursor);
		}

		// Deactivate shell
		savedState = saveUIState(useCustomProgressMonitorPart && needsProgressMonitor && enableCancelButton);
		if (focusControl != null) {
			savedState.put(FOCUS_CONTROL, focusControl);
		}
		// Activate cancel behavior.
		if (needsProgressMonitor) {
			if (enableCancelButton || useCustomProgressMonitorPart) {
				progressMonitorPart.attachToCancelComponent(cancelButton);
			}
			progressMonitorPart.setVisible(true);
		}

		if (timeWhenLastJobFinished == -1) {
			timeWhenLastJobFinished = 0;
			// 忽略键盘事件( enter space)在最后一个任务完成之前
			getShell().addTraverseListener(new TraverseListener() {
				public void keyTraversed(TraverseEvent e) {
					if (e.detail == SWT.TRAVERSE_RETURN || (e.detail == SWT.TRAVERSE_MNEMONIC && e.keyCode == 32)) {
						if (timeWhenLastJobFinished != 0
								&& System.currentTimeMillis() - timeWhenLastJobFinished < RESTORE_ENTER_DELAY) {
							e.doit = false;
							return;
						}
						timeWhenLastJobFinished = 0;
					}
				}
			});
		}
	}
	return savedState;
}
 
Example 18
/**
 * About to start a long running operation triggered through the wizard.
 * Shows the progress monitor and disables the wizard's buttons and
 * controls.
 * 
 * @param enableCancelButton
 *            <code>true</code> if the Cancel button should be enabled,
 *            and <code>false</code> if it should be disabled
 * @return the saved UI state
 */
private Object aboutToStart(boolean enableCancelButton) {
	Map savedState = null;
	if (getShell() != null) {
		// Save focus control
		Control focusControl = getShell().getDisplay().getFocusControl();
		if (focusControl != null && focusControl.getShell() != getShell()) {
			focusControl = null;
		}
		boolean needsProgressMonitor = wizard.needsProgressMonitor();
		
		// Set the busy cursor to all shells.
		Display d = getShell().getDisplay();
		waitCursor = new Cursor(d, SWT.CURSOR_WAIT);
		setDisplayCursor(waitCursor);
		
		if (useCustomProgressMonitorPart) {
			cancelButton.removeSelectionListener(cancelListener);
			// Set the arrow cursor to the cancel component.
			arrowCursor = new Cursor(d, SWT.CURSOR_ARROW);
			cancelButton.setCursor(arrowCursor);
		}
		
		// Deactivate shell
		savedState = saveUIState(useCustomProgressMonitorPart && needsProgressMonitor && enableCancelButton);
		if (focusControl != null) {
			savedState.put(FOCUS_CONTROL, focusControl);
		}
		// Activate cancel behavior.
		if (needsProgressMonitor) {
			if (enableCancelButton || useCustomProgressMonitorPart) {
				progressMonitorPart.attachToCancelComponent(cancelButton);
			}
			progressMonitorPart.setVisible(true);
		}
		
		// Install traverse listener once in order to implement 'Enter' and 'Space' key blocking
		if (timeWhenLastJobFinished == -1) {
			timeWhenLastJobFinished= 0;
			getShell().addTraverseListener(new TraverseListener() {
				public void keyTraversed(TraverseEvent e) {
					if (e.detail == SWT.TRAVERSE_RETURN || (e.detail == SWT.TRAVERSE_MNEMONIC && e.keyCode == 32)) {
						// We want to ignore the keystroke when we detect that it has been received within the
						// delay period after the last operation has finished.  This prevents the user from accidentally
						// hitting "Enter" or "Space", intending to cancel an operation, but having it processed exactly
						// when the operation finished, thus traversing the wizard.  If there is another operation still
						// running, the UI is locked anyway so we are not in this code.  This listener should fire only
						// after the UI state is restored (which by definition means all jobs are done.
						// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=287887
						if (timeWhenLastJobFinished != 0 && System.currentTimeMillis() - timeWhenLastJobFinished < RESTORE_ENTER_DELAY) {
							e.doit= false;
							return;
						}
						timeWhenLastJobFinished= 0;
					}}
			});
		}
	}
	return savedState;
}
 
Example 19
protected Object openDialogBox(Control cellEditorWindow) {
	DimensionBuilderDialog dialog = new DimensionBuilderDialog(
			cellEditorWindow.getShell());

	DimensionValue value;
	try {
		value = StringUtil.parseInput((String) comboBox.getText(), ULocale
				.getDefault());
	} catch (PropertyValueException e) {
		value = null;
	}

	dialog.setUnitNames(units);
	dialog.setUnitName(unitName);

	if (value != null) {
		dialog.setMeasureData(new Double(value.getMeasure()));
	}

	if (Window.OK == dialog.open()) {
		deactivate();

		String newValue = null;
		Double doubleValue = 0.0;
		if (dialog.getMeasureData() instanceof Double) {
			doubleValue = (Double) dialog.getMeasureData();
		} else if (dialog.getMeasureData() instanceof DimensionValue) {
			doubleValue = ((DimensionValue) dialog.getMeasureData())
					.getMeasure();
		}
		DimensionValue dValue = new DimensionValue(doubleValue, dialog
				.getUnitName());
		if (dValue != null) {
			newValue = dValue.toDisplayString();
		}
		return newValue;

	} else {
		comboBox.setFocus();
		return null;
	}
}
 
Example 20
protected Object openDialogBox( Control cellEditorWindow )
{
	DimensionBuilderDialog dialog = new DimensionBuilderDialog( cellEditorWindow.getShell( ) );

	DimensionValue value;
	try
	{
		value = StringUtil.parseInput( (String) this.getDefaultText( )
				.getText( ), ULocale.getDefault( ) );
	}
	catch ( PropertyValueException e )
	{
		value = null;
	}

	dialog.setUnitNames( units );
	dialog.setUnitName( unitName );

	if ( value != null )
	{
		dialog.setMeasureData( new Double( value.getMeasure( ) ) );
	}

	inProcessing = 1;
	if ( dialog.open( ) == Window.OK )
	{
		deactivate( );
		inProcessing = 0;

		String newValue = null;
		Double doubleValue = 0.0;
		if ( dialog.getMeasureData( ) instanceof Double )
		{
			doubleValue = (Double) dialog.getMeasureData( );
		}
		else if ( dialog.getMeasureData( ) instanceof DimensionValue )
		{
			doubleValue = ( (DimensionValue) dialog.getMeasureData( ) ).getMeasure( );
		}
		DimensionValue dValue = new DimensionValue( doubleValue,
				dialog.getUnitName( ) );

		if ( dValue != null )
		{
			newValue = dValue.toDisplayString( );
		}
		return newValue;
	}
	else
	{
		getDefaultText( ).setFocus( );
		getDefaultText( ).selectAll( );
	}
	inProcessing = 0;
	return null;

}