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

The following examples show how to use org.eclipse.swt.widgets.Composite#getShell() . 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: ExecutionStatisticsDialog.java    From tlaplus with MIT License 6 votes vote down vote up
protected Button createButton(Composite parent, int id, String label, boolean defaultButton) {
	// increment the number of columns in the button bar
	((GridLayout) parent.getLayout()).numColumns++;
	Button button = new Button(parent, SWT.PUSH | SWT.WRAP); // Need wrap here contrary to Dialog#createButton to wrap button label on Windows and macOS(?).
	button.setText(label);
	button.setFont(JFaceResources.getDialogFont());
	button.setData(Integer.valueOf(id));
	button.addSelectionListener(widgetSelectedAdapter(event -> buttonPressed(((Integer) event.widget.getData()).intValue())));
	if (defaultButton) {
		Shell shell = parent.getShell();
		if (shell != null) {
			shell.setDefaultButton(button);
		}
	}
	setButtonLayoutData(button);
	return button;
}
 
Example 2
Source File: XYGraphConfigDialog.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void createButtonsForButtonBar(Composite parent) {
	((GridLayout) parent.getLayout()).numColumns++;
	Button button = new Button(parent, SWT.PUSH);
	button.setText("Apply");
	GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
	int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
	Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
	data.widthHint = Math.max(widthHint, minSize.x);
	button.setLayoutData(data);
	button.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e) {
			applyChanges();
		}
	});
	super.createButtonsForButtonBar(parent);
	Shell shell = parent.getShell();
	if (shell != null) {
		shell.setDefaultButton(button);
	}
}
 
Example 3
Source File: AbstractChartView.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void createPartControl ( final Composite parent )
{
    parent.setLayout ( new FillLayout () );

    this.wrapper = new Composite ( parent, SWT.NONE );
    this.wrapper.setLayout ( GridLayoutFactory.slimStack () );

    this.shell = parent.getShell ();

    PlatformUI.getWorkbench ().getHelpSystem ().setHelp ( this.wrapper, "org.eclipse.scada.ui.chart.view.chartView" ); //$NON-NLS-1$

    fillMenu ( getViewSite ().getActionBars ().getMenuManager () );
    fillToolbar ( getViewSite ().getActionBars ().getToolBarManager () );

    createChartControl ( parent );
}
 
Example 4
Source File: FindingsUiUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns all actions from the main toolbar
 * 
 * @param c
 * @param iObservation
 * @param horizontalGrap
 * @return
 */
public static List<Action> createToolbarMainComponent(Composite c, IObservation iObservation,
	int horizontalGrap){
	
	Composite toolbarComposite = new Composite(c, SWT.NONE);
	toolbarComposite.setLayout(SWTHelper.createGridLayout(true, 2));
	toolbarComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, true, false));
	
	List<Action> actions = new ArrayList<>();
	LocalDateTime currentDate = iObservation.getEffectiveTime().orElse(LocalDateTime.now());
	
	ToolBarManager menuManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
	
	Action action = new DateAction(c.getShell(), currentDate, toolbarComposite);
	menuManager.add(action);
	menuManager.createControl(toolbarComposite)
		.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, horizontalGrap, 1));
	actions.add(action);
	
	return actions;
}
 
Example 5
Source File: BundledResourcesSelectionBlock.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public void doFillIntoGrid(Composite parent, int columns) {
  // Cache this for later
  this.shell = parent.getShell();

  resourcesField.doFillIntoGrid(parent, columns);

  GridData modulesFieldGridData = (GridData) resourcesField.getListControl(
      parent).getLayoutData();
  modulesFieldGridData.grabExcessHorizontalSpace = true;
  modulesFieldGridData.grabExcessVerticalSpace = true;
  resourcesField.getListControl(parent).setLayoutData(modulesFieldGridData);
}
 
Example 6
Source File: SootConfigManagerDialog.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
protected Button createSpecialButton(
	Composite parent,
	int id,
	String label,
	boolean defaultButton, boolean enabled) {


	Button button = new Button(parent, SWT.PUSH);
	button.setText(label);

	button.setData(new Integer(id));
	button.addSelectionListener(new SelectionAdapter() {
	public void widgetSelected(SelectionEvent event) {
		buttonPressed(((Integer) event.widget.getData()).intValue());
	}
	});
	if (defaultButton) {
		Shell shell = parent.getShell();
		if (shell != null) {
			shell.setDefaultButton(button);
		}
	}
	button.setFont(parent.getFont());
	if (!enabled){
		button.setEnabled(false);
	}

	setButtonLayoutData(button);
	specialButtonList.add(button);
	return button;
}
 
Example 7
Source File: PageSupport.java    From slr-toolkit with Eclipse Public License 1.0 5 votes vote down vote up
protected static RGB openAndGetColor(Composite parent, Label label) {
	
	ColorDialog dlg = new ColorDialog(parent.getShell());
	dlg.setRGB(label.getBackground().getRGB());
	dlg.setText("Choose a Color");
	RGB rgb = dlg.open();
       label.setBackground(new Color(parent.getShell().getDisplay(), rgb));
       
	return rgb;
}
 
Example 8
Source File: INSDComponentPage.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new button
 * <p>
 * The <code>Dialog</code> implementation of this framework method creates a standard push
 * button, registers for selection events including button presses and registers default buttons
 * with its shell. The button id is stored as the buttons client data. Note that the parent's
 * layout is assumed to be a GridLayout and the number of columns in this layout is incremented.
 * Subclasses may override.
 * </p>
 *
 * @param parent          the parent composite
 * @param label          the label from the button
 * @param defaultButton          <code>true</code> if the button is to be the default button, and <code>false</code>
 *          otherwise
 * @param text the text
 * @return the button
 */
protected Button addButton(Composite parent, String label, boolean defaultButton, final Text text) {

  Button button = new Button(parent, SWT.PUSH);
  button.setText(label);

  if (defaultButton) {
    Shell shell = parent.getShell();
    if (shell != null) {
      shell.setDefaultButton(button);
    }
    button.setFocus();
  }
  button.setFont(parent.getFont());

  SelectionListener listener = new SelectionAdapter() {
    @Override
    public void widgetSelected(SelectionEvent e) {

      ResourceSelectionDialog dialog = new ResourceSelectionDialog(getShell(), currentContainer,
              "Selection Dialog");
      dialog.setTitle("Selection Dialog");
      dialog.setMessage("Please select a file:");
      dialog.open();
      Object[] result = dialog.getResult();
      if (result[0] != null) {
        IResource res = (IResource) result[0];
        text.setText(res.getProjectRelativePath().toOSString());
      }

    }
  };
  button.addSelectionListener(listener);

  return button;
}
 
Example 9
Source File: BaseDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return
 */
private IDialogSettings loadDialogSettings( )
{
	if ( !needRememberLastSize( ) )
	{
		return null;
	}
	IDialogSettings dialogSettings = ReportPlugin.getDefault( )
			.getDialogSettings( );
	StringBuffer buf = new StringBuffer( );
	Shell curShell = getShell( );
	while ( curShell != null )
	{
		buf.append( curShell.toString( ) + '/' );
		Composite parent = curShell.getParent( );
		if ( parent != null )
		{
			curShell = parent.getShell( );
		}
		else
		{
			curShell = null;
		}
	}
	if ( buf.length( ) > 0 )
	{
		buf.deleteCharAt( buf.length( ) - 1 );
		String sectionName = buf.toString( );
		IDialogSettings setting = dialogSettings.getSection( sectionName );
		if ( setting == null )
		{
			setting = dialogSettings.addNewSection( sectionName );
		}
		return setting;
	}
	else
	{
		return dialogSettings;
	}
}
 
Example 10
Source File: SourceFirstPackageSelectionDialogField.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void createControl(Composite parent, int nOfColumns, int textWidth) {
	fShell= parent.getShell();
	PixelConverter converter= new PixelConverter(parent);
	fSourceFolderSelection.doFillIntoGrid(parent, nOfColumns, textWidth);
	LayoutUtil.setWidthHint(fSourceFolderSelection.getTextControl(null), converter.convertWidthInCharsToPixels(60));

	fPackageSelection.doFillIntoGrid(parent, nOfColumns, textWidth);
	LayoutUtil.setWidthHint(fPackageSelection.getTextControl(null), converter.convertWidthInCharsToPixels(60));
}
 
Example 11
Source File: ChartPrintJob.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/** 
 * Prints the specified element.
 * 
 * @param elementToPrint  the {@link Composite} to be printed.
 */
public void print(Composite elementToPrint) {
    PrintDialog dialog = new PrintDialog(elementToPrint.getShell());
    PrinterData printerData = dialog.open();
    if (printerData == null) {
        return; // Anwender hat abgebrochen.
    }
    startPrintJob(elementToPrint, printerData);
}
 
Example 12
Source File: ChartPrintJob.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/** 
 * Prints the specified element.
 * 
 * @param elementToPrint  the {@link Composite} to be printed.
 */
public void print(Composite elementToPrint) {
    PrintDialog dialog = new PrintDialog(elementToPrint.getShell());
    PrinterData printerData = dialog.open();
    if (printerData == null) {
        return; // Anwender hat abgebrochen.
    }
    startPrintJob(elementToPrint, printerData);
}
 
Example 13
Source File: MainView.java    From mappwidget with Apache License 2.0 5 votes vote down vote up
protected void getTiles(final Composite parent, final Composite banner, final String imgPath, final String saveDirPath, final String name, final Combo combo,
		final Cutter cutter, final PointVO pointTopLeft, final PointVO pointBottomRight)
{
	MessageBox dialog = new MessageBox(parent.getShell());

	if (name == null || name.contentEquals(""))
	{
		dialog.setMessage(ENTER_NAME_FIRST);
		dialog.open();
		return;
	}

	else if (imgPath == null || imgPath.contentEquals(""))
	{
		dialog.setMessage(CHOOSE_IMAGE_FIRST);
		dialog.open();
		return;
	}

	else if (saveDirPath == null || saveDirPath.contentEquals(""))
	{
		dialog.setMessage(CHOOSE_SAVE_DIR_FIRST);
		dialog.open();
		return;
	}

	File f = new File(imgPath);

	if (f.exists())
	{
		cutter.startCuttingAndroid(imgPath, saveDirPath, name, Integer.parseInt(combo.getItem(combo.getSelectionIndex())), pointTopLeft, pointBottomRight);
	}
	else
	{
		dialog.setMessage(INCORECT_FILE_NAME);
		dialog.open();
		return;
	}

}
 
Example 14
Source File: NewItemWizardPage.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * This operation creates the view that shows the list of Items that can be
 * created by the user.
 */
@Override
public void createControl(Composite parent) {

	// Set the parent reference
	parentComposite = parent;

	// Create the composite for file selection pieces
	Composite itemSelectionComposite = new Composite(parentComposite,
			SWT.NONE);
	// Set its layout
	GridLayout layout = new GridLayout(1, true);
	itemSelectionComposite.setLayout(layout);
	// Set its layout data
	GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
	itemSelectionComposite.setLayoutData(data);

	// Get the extension registry and retrieve the client.
	IExtensionRegistry registry = Platform.getExtensionRegistry();
	IExtensionPoint point = registry
			.getExtensionPoint("org.eclipse.ice.client.clientInstance");
	IExtension[] extensions = point.getExtensions();
	// Get the configuration element. The extension point can only have one
	// extension by default, so no need for a loop or check.
	IConfigurationElement[] elements = extensions[0]
			.getConfigurationElements();
	IConfigurationElement element = elements[0];

	// Get the client
	try {
		IClient client = (IClient) element
				.createExecutableExtension("class");
		// Draw the list of Items and present the selection wizard.
		drawWizard(itemSelectionComposite, client);
	} catch (CoreException e) {
		// Otherwise throw an error
		MessageBox errorMessage = new MessageBox(parent.getShell(), ERROR);
		errorMessage.setMessage("The ICE Client is not available. "
				+ "Please file a bug report.");
		errorMessage.open();
		// Log the error
		logger.error("ICEClient Extension not found.",e);
	}

	// Set the control
	setControl(itemSelectionComposite);
	// Disable the finished condition to start
	setPageComplete(false);

	return;

}
 
Example 15
Source File: CopyTableWizardPage2.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void createControl( Composite parent ) {
  shell = parent.getShell();

  // create the composite to hold the widgets
  Composite composite = new Composite( parent, SWT.NONE );
  props.setLook( composite );

  FormLayout compLayout = new FormLayout();
  compLayout.marginHeight = Const.FORM_MARGIN;
  compLayout.marginWidth = Const.FORM_MARGIN;
  composite.setLayout( compLayout );

  // Source list to the left...
  wlListSource = new Label( composite, SWT.NONE );
  wlListSource.setText( BaseMessages.getString( PKG, "CopyTableWizardPage2.Dialog.TableList.Label" ) );
  props.setLook( wlListSource );
  FormData fdlListSource = new FormData();
  fdlListSource.left = new FormAttachment( 0, 0 );
  fdlListSource.top = new FormAttachment( 0, 0 );
  wlListSource.setLayoutData( fdlListSource );

  wListSource = new List( composite, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL );
  props.setLook( wListSource );
  wListSource.addSelectionListener( new SelectionAdapter() {
    public void widgetSelected( SelectionEvent arg0 ) {
      setPageComplete( canFlipToNextPage() );
    }
  } );

  FormData fdListSource = new FormData();
  fdListSource.left = new FormAttachment( 0, 0 );
  fdListSource.top = new FormAttachment( wlListSource, 0 );
  fdListSource.right = new FormAttachment( 100, 0 );
  fdListSource.bottom = new FormAttachment( 100, 0 );
  wListSource.setLayoutData( fdListSource );

  // Double click adds to destination.
  wListSource.addSelectionListener( new SelectionAdapter() {
    public void widgetDefaultSelected( SelectionEvent e ) {
      if ( canFinish() ) {
        getWizard().performFinish();
        shell.dispose();
      }
    }
  } );

  // set the composite as the control for this page
  setControl( composite );
}
 
Example 16
Source File: ConfigSectionSecuritySWT.java    From BiglyBT with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void configSectionCreate(Composite parent, Map<ParameterImpl, BaseSwtParameter> mapParamToSwtParam) {
	shell = parent.getShell();
}
 
Example 17
Source File: BaseStepDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static final void positionBottomButtons( Composite composite, Button[] buttons, int margin, int alignment,
                                                 Control lastControl ) {
  // Determine the largest button in the array
  Rectangle largest = null;
  for ( int i = 0; i < buttons.length; i++ ) {
    buttons[ i ].pack( true );
    Rectangle r = buttons[ i ].getBounds();
    if ( largest == null || r.width > largest.width ) {
      largest = r;
    }

    // Also, set the tooltip the same as the name if we don't have one...
    if ( buttons[ i ].getToolTipText() == null ) {
      buttons[ i ].setToolTipText( Const.replace( buttons[ i ].getText(), "&", "" ) );
    }
  }

  // Make buttons a bit larger... (nicer)
  largest.width += 10;
  if ( ( largest.width % 2 ) == 1 ) {
    largest.width++;
  }

  // Compute the left side of the 1st button
  switch ( alignment ) {
    case BUTTON_ALIGNMENT_CENTER:
      centerButtons( buttons, largest.width, margin, lastControl );
      break;
    case BUTTON_ALIGNMENT_LEFT:
      leftAlignButtons( buttons, largest.width, margin, lastControl );
      break;
    case BUTTON_ALIGNMENT_RIGHT:
      rightAlignButtons( buttons, largest.width, margin, lastControl );
      break;
    default:
      break;
  }
  if ( Const.isOSX() ) {
    Shell parentShell = composite.getShell();
    final List<TableView> tableViews = new ArrayList<TableView>();
    getTableViews( parentShell, tableViews );
    for ( final Button button : buttons ) {
      // We know the table views
      // We also know that if a button is hit, the table loses focus
      // In that case, we can apply the content of an open text editor...
      //
      button.addSelectionListener( new SelectionAdapter() {

        public void widgetSelected( SelectionEvent e ) {
          for ( TableView view : tableViews ) {
            view.applyOSXChanges();
          }
        }
      } );
    }
  }
}
 
Example 18
Source File: QuestionsPage.java    From CogniCrypt with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void createControl(final Composite parent) {
	final Composite container = new Composite(parent, SWT.NONE);
	setControl(container);

	// make the page layout two-column
	container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	container.setLayout(new GridLayout(2, false));

	setCompositeToHoldGranularUIElements(new CompositeToHoldGranularUIElements(container, getName()));
	// fill the available space on the with the big composite
	getCompositeToHoldGranularUIElements().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

	TaskIntegrationWizard tiWizard = null;

	if (TaskIntegrationWizard.class.isInstance(getWizard())) {
		tiWizard = (TaskIntegrationWizard) getWizard();
	} else {
		Activator.getDefault().logError("PageForTaskIntegratorWizard was instantiated by a wizard other than TaskIntegrationWizard");
	}

	final PageForTaskIntegratorWizard claferPage = tiWizard.getTIPageByName(Constants.PAGE_NAME_FOR_CLAFER_FILE_CREATION);
	final CompositeToHoldGranularUIElements claferPageComposite = claferPage.getCompositeToHoldGranularUIElements();

	final QuestionDialog questionDialog = new QuestionDialog(parent.getShell());
	final Button qstnDialog = new Button(container, SWT.NONE);
	qstnDialog.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
	qstnDialog.setText("Add Question");

	qstnDialog.addSelectionListener(new SelectionAdapter() {

		@Override
		public void widgetSelected(final SelectionEvent e) {
			final int response = questionDialog.open();
			final int qID = QuestionsPage.this.compositeToHoldGranularUIElements.getListOfAllQuestions().size();
			if (response == Window.OK) {
				QuestionsPage.this.counter++;
				// Question questionDetails = getDummyQuestion(questionDialog.getQuestionText(),questionDialog.getquestionType(),questionDialog.getAnswerValue());
				final Question questionDetails = questionDialog.getQuestionDetails();
				questionDetails.setId(qID);

				// Update the array list.
				QuestionsPage.this.compositeToHoldGranularUIElements.getListOfAllQuestions().add(questionDetails);
				QuestionsPage.this.compositeToHoldGranularUIElements.addQuestionUIElements(questionDetails, claferPageComposite.getClaferModel(), false);
				// rebuild the UI
				QuestionsPage.this.compositeToHoldGranularUIElements.updateQuestionContainer();
			}
		}
	});
}
 
Example 19
Source File: ExcelFileSelectionWizardPage.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void createControl( Composite parent )
{
	shell = parent.getShell( );
	super.createControl( parent );
}
 
Example 20
Source File: LaborView.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void createPartControl(final Composite parent){
	setTitleImage(Images.IMG_VIEW_LABORATORY.getImage());
	
	tabFolder = new CTabFolder(parent, SWT.TOP);
	tabFolder.setLayout(new FillLayout());
	
	final CTabItem resultsTabItem = new CTabItem(tabFolder, SWT.NULL);
	resultsTabItem.setText("Resultate");
	resultsComposite = new LaborResultsComposite(tabFolder, SWT.NONE);
	resultsTabItem.setControl(resultsComposite);
	
	final CTabItem ordersTabItem = new CTabItem(tabFolder, SWT.NULL);
	ordersTabItem.setText("Verordnungen");
	ordersComposite = new LaborOrdersComposite(tabFolder, SWT.NONE);
	ordersTabItem.setControl(ordersComposite);
	
	tabFolder.setSelection(0);
	tabFolder.addSelectionListener(new SelectionAdapter() {
		@Override
		public void widgetSelected(SelectionEvent e){
			resultsComposite.reload();
			ordersComposite.reload();
		}
	});
	makeActions();
	menu = new ViewMenus(getViewSite());
	menu.createMenu(newAction, backAction, fwdAction, printAction, importAction, xmlAction);
	// Orders
	final LaborOrderPulldownMenuCreator menuCreator =
		new LaborOrderPulldownMenuCreator(parent.getShell());
	if (menuCreator.getSelected() != null) {
		IAction dropDownAction = menuCreator.getAction();
		
		IActionBars actionBars = getViewSite().getActionBars();
		IToolBarManager toolbar = actionBars.getToolBarManager();
		
		toolbar.add(dropDownAction);
		
		// Set data
		dropDownAction.setText(menuCreator.getSelected().getText());
		dropDownAction.setToolTipText(menuCreator.getSelected().getToolTipText());
		dropDownAction.setImageDescriptor(menuCreator.getSelected().getImageDescriptor());
	}
	// Importers
	IToolBarManager tm = getViewSite().getActionBars().getToolBarManager();
	List<IAction> importers =
		Extensions.getClasses(
			Extensions.getExtensions(ExtensionPointConstantsUi.LABORDATENIMPORT),
			"ToolbarAction", //$NON-NLS-1$ //$NON-NLS-2$
			false);
	for (IAction ac : importers) {
		tm.add(ac);
	}
	if (importers.size() > 0) {
		tm.add(new Separator());
	}
	tm.add(refreshAction);
	tm.add(newColumnAction);
	tm.add(newAction);
	tm.add(backAction);
	tm.add(fwdAction);
	tm.add(expandAllAction);
	tm.add(collapseAllAction);
	tm.add(printAction);
	
	// register event listeners
	ElexisEventDispatcher.getInstance().addListeners(eeli_labitem, eeli_laborder,
		eeli_labresult, eeli_pat);
	Patient act = (Patient) ElexisEventDispatcher.getSelected(Patient.class);
	if ((act != null && act != resultsComposite.getPatient())) {
		resultsComposite.selectPatient(act);
	}
	getSite().getPage().addPartListener(udpateOnVisible);
}