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

The following examples show how to use org.eclipse.swt.widgets.Composite#requestLayout() . 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: View.java    From codeexamples-eclipse with Eclipse Public License 1.0 5 votes vote down vote up
private void addDropListener(Composite parent) {
	LocalSelectionTransfer transfer = LocalSelectionTransfer.getTransfer();

	DropTargetAdapter dragAdapter = new DropTargetAdapter() {
		@Override
		public void drop(DropTargetEvent event) {
			Control droppedObj = (Control) ((StructuredSelection) transfer.getSelection()).getFirstElement();

			// Get the existing parent of the dragged control
			Composite oldParent = droppedObj.getParent();

			if (oldParent == parent) {
				return;
			}

			if  (droppedObj instanceof Label) {
				System.out.println("Dropped");
			}
			// handle the drop
			if (droppedObj instanceof Label) {
				Label droppedLabel = (Label) droppedObj;
				droppedLabel.setParent(parent); // Change parent
			}

			if (droppedObj instanceof Button) {
				Button droppedButton = (Button) droppedObj;
				droppedButton.setParent(parent); // Change parent
			}

			// request a layout pass
			oldParent.requestLayout();
			// If you change that to layout the layout will be correct
			parent.layout();
		}
	};

	DropTarget dropTarget = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY);
	dropTarget.setTransfer(new Transfer[] { transfer });
	dropTarget.addDropListener(dragAdapter);
}
 
Example 2
Source File: ExternalLibraryPreferencePage.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected Control createContents(final Composite parent) {
	this.setSize(new Point(600, 600));

	final BuiltInLibrariesLabelProvider labelProvider = new BuiltInLibrariesLabelProvider(projectExplorerhelper);
	final Composite control = new Composite(parent, NONE);
	control.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).create());
	control.setLayoutData(fillDefaults().align(FILL, FILL).create());

	viewer = new TreeViewerBuilder(singletonList(""), contentProvider.get())
			.setVirtual(true)
			.setHeaderVisible(false)
			.setUseHashlookup(true)
			.setHasBorder(true)
			.setColumnWeights(asList(1))
			.setLabelProvider(new DelegatingStyledCellLabelProvider(labelProvider))
			.build(control);

	setViewerInput();

	final Composite subComposite = new Composite(control, NONE);
	subComposite.setLayout(GridLayoutFactory.fillDefaults().create());
	subComposite.setLayoutData(fillDefaults().align(END, TOP).create());

	final Button install = createEnabledPushButton(subComposite, "Install npm...",
			"Runs 'npm install' with the given package and version. Uses 'yarn add' in a yarn workspace.",
			new InstallNpmDependencyButtonListener(this::updateLocations,
					libManager, validatorHelper, semverHelper, statusHelper, this::getSelectedNodeModulesURI));

	final Button uninstall = createEnabledPushButton(subComposite, "Uninstall npm...",
			"Runs 'npm uninstall' with the given package and version. Uses 'yarn remove' in a yarn workspace.",
			new UninstallNpmDependencyButtonListener(this::updateLocations,
					libManager, validatorHelper, statusHelper, this::getSelectedNpm));

	createPlaceHolderLabel(subComposite);

	createPlaceHolderLabel(subComposite);

	createEnabledPushButton(subComposite, "Re-Build node_modules",
			"Cleans the type information from the IDE and then re-build the type information of all node_modules.",
			new RereigsterAllNpmsButtonListener(this::reregisterNpms, statusHelper));

	createEnabledPushButton(subComposite, "Clean node_modules",
			"Runs 'npm clean' on all node_modules folders. Uses 'yarn clean' in a yarn workspace.",
			new CleanAllNpmsButtonListener(this::cleanNpms, statusHelper));

	viewer.addSelectionChangedListener(new ISelectionChangedListener() {

		@Override
		public void selectionChanged(final /* @Nullable */ SelectionChangedEvent event) {
			install.setEnabled(false);
			uninstall.setEnabled(false);

			Object selectedItem = getSelectedItem();
			if (selectedItem instanceof SafeURI) {
				install.setEnabled(true);
			}
			if (selectedItem instanceof IN4JSProject) {
				uninstall.setEnabled(true);
			}
		}
	});

	control.requestLayout();

	return control;
}