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

The following examples show how to use org.eclipse.swt.widgets.Control#addDisposeListener() . 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: n4js   File: SpecComparePage.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private Control createPreviewer(Composite parent) {
	final CompareConfiguration compareConfiguration = new CompareConfiguration();
	compareConfiguration.setLeftLabel("Original " + docTypeName);
	compareConfiguration.setLeftEditable(false);
	compareConfiguration.setRightLabel("Updated " + docTypeName);
	compareConfiguration.setRightEditable(false);
	compareConfiguration.setProperty(CompareConfiguration.IGNORE_WHITESPACE, Boolean.FALSE);
	compareConfiguration.setProperty(PREFIX_SUFFIX_PROPERTY, fPrefixSuffix);

	fViewer = new TextMergeViewer(parent, SWT.NONE, compareConfiguration);
	// add initial input in order to avoid problems when disposing the viewer later:
	fViewer.setInput(new DiffNode(new TargetElementFromString(""), new TargetElementFromString("")));

	Control control = fViewer.getControl();
	control.addDisposeListener(new DisposeListener() {
		@Override
		public void widgetDisposed(DisposeEvent e) {
			compareConfiguration.dispose();
		}
	});
	return control;
}
 
Example 2
Source Project: google-cloud-eclipse   File: FontUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Converts the font of the control by adding a single style bit, unless the font already have
 * that style.
 * <p>
 * If the font is converted, it will attach a {@link DisposeListener}
 * to the <code>control</code> to dispose the font when it's not needed anymore.
 * <p>
 * <em>If converting fonts is a frequent operation, this method will create
 * several {@link DisposeListener}s that can lead to high resource allocation</em>
 *
 * @param control whose font will be changed
 * @param style e.g. SWT.BOLD or SWT.ITALIC
 */
public static void convertFont(Control control, int style) {
  for (FontData fontData : control.getFont().getFontData()) {
    if (hasStyle(fontData, style)) {
      return;
    }
  }
  FontDescriptor fontDescriptor = FontDescriptor.createFrom(control.getFont()).setStyle(style);
  final Font newFont = fontDescriptor.createFont(control.getDisplay());
  control.setFont(newFont);
  control.addDisposeListener(new DisposeListener() {
    @Override
    public void widgetDisposed(DisposeEvent event) {
      newFont.dispose();
    }
  });
}
 
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
public void addDataDefinitionText( Control text,
		IQueryExpressionManager queryManager )
{
	textCollection.put( text, queryManager );
	// update control color when switching.
	updateControlBackground( text, queryManager.getQuery( ).getDefinition( ) );
	text.addDisposeListener( new DisposeListener( ) {

		public void widgetDisposed( DisposeEvent e )
		{
			if ( e.widget instanceof Control )
			{
				removeDataDefinitionText( (Control) e.widget );
			}

		}
	} );
}
 
Example 5
Source Project: saros   File: FontUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void changeFontSizeBy(Control control, int fontSizeInc) {
  FontData[] fontData = control.getFont().getFontData();
  for (int i = 0; i < fontData.length; ++i)
    fontData[i].setHeight(fontData[i].getHeight() + fontSizeInc);

  final Font newFont = new Font(control.getDisplay(), fontData);
  control.setFont(newFont);

  // Since you created the font, you must dispose it
  control.addDisposeListener(
      new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent e) {
          newFont.dispose();
        }
      });
}
 
Example 6
private FocusHandler(Navigable navigable) {
	fIterator= new JavaWordIterator();
	fNavigable= navigable;

	Control control= navigable.getControl();
	control.addFocusListener(this);
	if (control.isFocusControl())
		activate();
	control.addDisposeListener(new DisposeListener() {
		public void widgetDisposed(DisposeEvent e) {
			deactivate();
		}
	});
}
 
Example 7
Source Project: developer-studio   File: WSO2UIToolkit.java    License: Apache License 2.0 5 votes vote down vote up
private static void propagateVisibility(final Control watchControl, final Control... controls) {
	visibilityControls.put(watchControl, controls);
	watchControl.addDisposeListener(new DisposeListener() {

		public void widgetDisposed(DisposeEvent arg0) {
			visibilityControls.remove(watchControl);
		}
	});
}
 
Example 8
/**
 * adds a DisposeListener to the given control to remove workspace listener.
 * Normally, the workspace listener will be removed when all LookupListeners are removed,
 * but this gives us another way to insure it is removed.
 * @param c
 */
public void setControl(Control c) {
    c.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent event) {
            listeners.clear();
            removeNotify();
        }
    });
    
}
 
Example 9
Source Project: JDeodorant   File: CodeSmellPackageExplorer.java    License: MIT License 5 votes vote down vote up
private void hookTooltips(PackageMapDiagram diagram) {
	// Create an information provider for our table viewer
	IInformationProvider informationProvider = new PackageMapDiagramInformationProvider(diagram);
	List<ICustomInformationControlCreator> informationControlCreators = new ArrayList<ICustomInformationControlCreator>();
	if(CODE_SMELL_TYPE != null) {
		if(CODE_SMELL_TYPE.equals(CodeSmellType.FEATURE_ENVY))
			informationControlCreators.add(new FeatureEnviedMethodInformationControlCreator());
		else if(CODE_SMELL_TYPE.equals(CodeSmellType.GOD_CLASS))
			informationControlCreators.add(new GodClassInformationControlCreator());
	}
	Control control =figureCanvas;
	final InformationControlManager informationControlManager = new InformationControlManager(informationProvider, informationControlCreators, false);
	informationControlManager.install(control);

	// MouseListener to show the information when the user hovers a table item
	control.addMouseTrackListener(new MouseTrackAdapter() {
		@Override
		public void mouseHover(MouseEvent event) {
			informationControlManager.showInformation();
		}
	});

	// DisposeListener to uninstall the information control manager

	DisposeListener listener = new DisposeListener(){
		public void widgetDisposed(DisposeEvent e) {
			informationControlManager.dispose();
		}
	};
	control.addDisposeListener(listener);
	// Install tooltips
	//Tooltips.install(diagram.getControl(), informationProvider, informationControlCreators, false);
}
 
Example 10
Source Project: saros   File: FontUtils.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void makeBold(Control control) {
  FontData[] boldFontData = modifyFontData(control.getFont().getFontData(), SWT.BOLD);

  final Font newFont = new Font(control.getDisplay(), boldFontData);
  control.setFont(newFont);

  // Since you created the font, you must dispose it
  control.addDisposeListener(
      new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent e) {
          newFont.dispose();
        }
      });
}
 
Example 11
Source Project: arx   File: SWTUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Changes a control's font
 * @param control
 * @param style
 */
public static void changeFont(Control control, int style) {
    FontDescriptor boldDescriptor = FontDescriptor.createFrom(control.getFont()).setStyle(style);
    final Font boldFont = boldDescriptor.createFont(control.getDisplay());
    control.setFont(boldFont);
    control.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(DisposeEvent arg0) {
            if (boldFont != null && !boldFont.isDisposed()) {
                boldFont.dispose();
            }
        }
        
    });
}
 
Example 12
Source Project: hop   File: BaseGuiWidgets.java    License: Apache License 2.0 4 votes vote down vote up
protected void addDeRegisterGuiPluginObjectListener(Control control) {
  control.addDisposeListener( e -> GuiRegistry.getInstance().removeGuiPluginObjects( HopGui.getId(), instanceId ) );
}
 
Example 13
public void createComposite(final Composite comp) {
	this.parent = comp;
	internalModification = true;
	titleLabel = createLeftLabel(comp, name, isSubParameter);
	titleLabel.setForeground(GamaColors.getTextColorForBackground(titleLabel.getBackground()).color());
	// IGamaColors.BLACK.color()); by default, see #2601
	try {
		setOriginalValue(getParameterValue());
	} catch (final GamaRuntimeException e1) {
		e1.addContext("Impossible to obtain the value of " + name);
		GAMA.reportError(GAMA.getRuntimeScope(), e1, false);
	}
	currentValue = getOriginalValue();
	composite = new Composite(comp, SWT.NONE);
	composite.setBackground(comp.getBackground());
	final GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
	data.minimumWidth = 150;
	composite.setLayoutData(data);

	final GridLayout layout = new GridLayout(2, false);
	layout.marginWidth = 5;

	composite.setLayout(layout);
	createEditorControl(composite);
	toolbar = createToolbar2();

	if (isEditable && !isCombo) {
		displayParameterValueAndCheckButtons();
	}
	internalModification = false;
	composite.layout();

	addToolbarHiders(composite, toolbar, titleLabel);
	for (final Button b : items) {
		addToolbarHiders(b);
	}
	for (final Control c : controlsThatShowHideToolbars) {
		c.addMouseTrackListener(hideShowToolbarListener);
		c.addDisposeListener(e -> {
			c.removeMouseTrackListener(hideShowToolbarListener);
			controlsThatShowHideToolbars.remove(c);
		});
	}
	if (GAMA.getExperiment() == null || !GAMA.getExperiment().isBatch()) {
		hideToolbar();
	}
}