List of usage examples for org.eclipse.swt.widgets Label Label
public Label(Composite parent, int style)
From source file:edu.isistan.carcha.plugin.editors.TraceabilityEditor.java
/** * Creates the impact list page./*from w w w . j a v a 2 s. co m*/ */ void impactListPage() { final Composite composite = new Composite(getContainer(), SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1)); composite.setLayout(new GridLayout()); Label concernLabel = new Label(composite, SWT.BORDER); concernLabel.setText("Crosccuting Concerns(CCC)"); concernLabel.setToolTipText("This are the concern detected on the requierement document."); GridData gridData = new GridData(SWT.LEFT, SWT.TOP, false, false); concernLabel.setLayoutData(gridData); ///////////////////// ScrolledComposite sc = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL); Composite parent = new Composite(sc, SWT.NONE); parent.setLayout(new GridLayout()); topViewLink = new TableViewer(parent, SWT.BORDER); createColumns(parent, topViewLink); final Table table = topViewLink.getTable(); table.setHeaderVisible(true); table.setLinesVisible(true); topViewLink.setContentProvider(new ArrayContentProvider()); getSite().setSelectionProvider(topViewLink); GridData data = new GridData(SWT.FILL, SWT.FILL, true, false); data.heightHint = 10 * table.getItemHeight(); table.setLayoutData(data); sc.setContent(parent); sc.setExpandHorizontal(true); sc.setExpandVertical(true); sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT)); ///////////////////// Button button = new Button(composite, SWT.PUSH); button.setText("Remove"); button.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent event) { } public void widgetSelected(SelectionEvent event) { IStructuredSelection topSelection = (IStructuredSelection) topViewLink.getSelection(); IStructuredSelection bottomSelection = (IStructuredSelection) bottomViewLink.getSelection(); String[] crosscuttingConcern = (String[]) topSelection.getFirstElement(); String[] designDecision = (String[]) bottomSelection.getFirstElement(); if (topSelection.size() > 1) { MessageDialog.openError(composite.getShell(), "Error", "Please select one crosscutting concern"); } else { if ((crosscuttingConcern != null) && (designDecision != null)) { // create dialog with ok and cancel button and info icon MessageBox dialog = new MessageBox(composite.getShell(), SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL); dialog.setText("Link confirmation"); dialog.setMessage("Do you want to remove the link between the selected items?"); // open dialog and await user selection int response = dialog.open(); if (response == SWT.OK) { PluginUtil.removeLink(crosscuttingConcern, designDecision, cp); dirty = true; firePropertyChange(IEditorPart.PROP_DIRTY); // update the list after the remove generateLinkViewData(); bottomViewLink.getTable().clearAll(); } } else { MessageDialog.openError(composite.getShell(), "Error", "Please select a crosscutting concern and a design decision to remove a traceability link"); } } } }); gridData = new GridData(SWT.CENTER, SWT.TOP, false, false, 2, 1); button.setLayoutData(gridData); Label ddsLabel = new Label(composite, SWT.BORDER); ddsLabel.setText("Architectural design decisions"); ddsLabel.setToolTipText("This are the design decisions detected on the architectural document"); gridData = new GridData(SWT.LEFT, SWT.TOP, false, false); ddsLabel.setLayoutData(gridData); bottomViewLink = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); createColumns(composite, bottomViewLink); Table table2 = bottomViewLink.getTable(); table2.setHeaderVisible(true); table2.setLinesVisible(true); bottomViewLink.setContentProvider(new ArrayContentProvider()); topViewLink.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (!selection.isEmpty()) { String[] cccs = (String[]) selection.getFirstElement(); List<DesignDecision> dds = PluginUtil.getDesignDecisionsForCrossCuttingConcern(cp, cccs[1], cccs[0]); logger.info("Impact List for CCC (" + dds.size() + " DDD): " + cccs[0] + " - " + cccs[1]); List<String[]> designDecisions = new ArrayList<String[]>(); for (DesignDecision dd : dds) { String[] designDecision = { dd.getKind(), dd.getName() }; designDecisions.add(designDecision); } bottomViewLink.setInput(designDecisions); } } }); getSite().setSelectionProvider(bottomViewLink); gridData = new GridData(SWT.FILL, SWT.FILL, true, true); bottomViewLink.getControl().setLayoutData(gridData); int index = addPage(composite); setPageText(index, "Links"); }
From source file:org.eclipse.swt.examples.clipboard.ClipboardExample.java
void createImageTransfer(Composite copyParent, Composite pasteParent) { final Image[] copyImage = new Image[] { null }; Label l = new Label(copyParent, SWT.NONE); l.setText("ImageTransfer:"); //$NON-NLS-1$ GridData data = new GridData(); data.verticalSpan = 2;/* w ww.j a v a 2 s . co m*/ l.setLayoutData(data); final Canvas copyImageCanvas = new Canvas(copyParent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); data = new GridData(GridData.FILL_BOTH); data.verticalSpan = 2; data.widthHint = HSIZE; data.heightHint = VSIZE; copyImageCanvas.setLayoutData(data); final Point copyOrigin = new Point(0, 0); final ScrollBar copyHBar = copyImageCanvas.getHorizontalBar(); copyHBar.setEnabled(false); copyHBar.addListener(SWT.Selection, e -> { if (copyImage[0] != null) { int hSelection = copyHBar.getSelection(); int destX = -hSelection - copyOrigin.x; Rectangle rect = copyImage[0].getBounds(); copyImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); copyOrigin.x = -hSelection; } }); final ScrollBar copyVBar = copyImageCanvas.getVerticalBar(); copyVBar.setEnabled(false); copyVBar.addListener(SWT.Selection, e -> { if (copyImage[0] != null) { int vSelection = copyVBar.getSelection(); int destY = -vSelection - copyOrigin.y; Rectangle rect = copyImage[0].getBounds(); copyImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false); copyOrigin.y = -vSelection; } }); copyImageCanvas.addListener(SWT.Paint, e -> { if (copyImage[0] != null) { GC gc = e.gc; gc.drawImage(copyImage[0], copyOrigin.x, copyOrigin.y); Rectangle rect = copyImage[0].getBounds(); Rectangle client = copyImageCanvas.getClientArea(); int marginWidth = client.width - rect.width; if (marginWidth > 0) { gc.fillRectangle(rect.width, 0, marginWidth, client.height); } int marginHeight = client.height - rect.height; if (marginHeight > 0) { gc.fillRectangle(0, rect.height, client.width, marginHeight); } gc.dispose(); } }); Button openButton = new Button(copyParent, SWT.PUSH); openButton.setText("Open Image"); openButton.addSelectionListener(widgetSelectedAdapter(e -> { FileDialog dialog = new FileDialog(shell, SWT.OPEN); dialog.setText("Open an image file or cancel"); String string = dialog.open(); if (string != null) { if (copyImage[0] != null) { System.out.println("CopyImage"); copyImage[0].dispose(); } copyImage[0] = new Image(e.display, string); copyVBar.setEnabled(true); copyHBar.setEnabled(true); copyOrigin.x = 0; copyOrigin.y = 0; Rectangle rect = copyImage[0].getBounds(); Rectangle client = copyImageCanvas.getClientArea(); copyHBar.setMaximum(rect.width); copyVBar.setMaximum(rect.height); copyHBar.setThumb(Math.min(rect.width, client.width)); copyVBar.setThumb(Math.min(rect.height, client.height)); copyImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true); copyVBar.setSelection(0); copyHBar.setSelection(0); copyImageCanvas.redraw(); } })); Button b = new Button(copyParent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(widgetSelectedAdapter(e -> { if (copyImage[0] != null) { status.setText(""); // Fetch ImageData at current zoom and save in the clip-board. clipboard.setContents(new Object[] { copyImage[0].getImageDataAtCurrentZoom() }, new Transfer[] { ImageTransfer.getInstance() }); } else { status.setText("No image to copy"); } })); final Image[] pasteImage = new Image[] { null }; l = new Label(pasteParent, SWT.NONE); l.setText("ImageTransfer:"); final Canvas pasteImageCanvas = new Canvas(pasteParent, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); data = new GridData(GridData.FILL_BOTH); data.widthHint = HSIZE; data.heightHint = VSIZE; pasteImageCanvas.setLayoutData(data); final Point pasteOrigin = new Point(0, 0); final ScrollBar pasteHBar = pasteImageCanvas.getHorizontalBar(); pasteHBar.setEnabled(false); pasteHBar.addListener(SWT.Selection, e -> { if (pasteImage[0] != null) { int hSelection = pasteHBar.getSelection(); int destX = -hSelection - pasteOrigin.x; Rectangle rect = pasteImage[0].getBounds(); pasteImageCanvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false); pasteOrigin.x = -hSelection; } }); final ScrollBar pasteVBar = pasteImageCanvas.getVerticalBar(); pasteVBar.setEnabled(false); pasteVBar.addListener(SWT.Selection, e -> { if (pasteImage[0] != null) { int vSelection = pasteVBar.getSelection(); int destY = -vSelection - pasteOrigin.y; Rectangle rect = pasteImage[0].getBounds(); pasteImageCanvas.scroll(0, destY, 0, 0, rect.width, rect.height, false); pasteOrigin.y = -vSelection; } }); pasteImageCanvas.addListener(SWT.Paint, e -> { if (pasteImage[0] != null) { GC gc = e.gc; gc.drawImage(pasteImage[0], pasteOrigin.x, pasteOrigin.y); Rectangle rect = pasteImage[0].getBounds(); Rectangle client = pasteImageCanvas.getClientArea(); int marginWidth = client.width - rect.width; if (marginWidth > 0) { gc.fillRectangle(rect.width, 0, marginWidth, client.height); } int marginHeight = client.height - rect.height; if (marginHeight > 0) { gc.fillRectangle(0, rect.height, client.width, marginHeight); } } }); b = new Button(pasteParent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(widgetSelectedAdapter(e -> { ImageData imageData = (ImageData) clipboard.getContents(ImageTransfer.getInstance()); if (imageData != null) { if (pasteImage[0] != null) { System.out.println("PasteImage"); pasteImage[0].dispose(); } status.setText(""); // Consume the ImageData at current zoom as-is. pasteImage[0] = new Image(e.display, new AutoScaleImageDataProvider(imageData)); pasteVBar.setEnabled(true); pasteHBar.setEnabled(true); pasteOrigin.x = 0; pasteOrigin.y = 0; Rectangle rect = pasteImage[0].getBounds(); Rectangle client = pasteImageCanvas.getClientArea(); pasteHBar.setMaximum(rect.width); pasteVBar.setMaximum(rect.height); pasteHBar.setThumb(Math.min(rect.width, client.width)); pasteVBar.setThumb(Math.min(rect.height, client.height)); pasteImageCanvas.scroll(0, 0, 0, 0, rect.width, rect.height, true); pasteVBar.setSelection(0); pasteHBar.setSelection(0); pasteImageCanvas.redraw(); } else { status.setText("No image to paste"); } })); }
From source file:fr.inria.soctrace.framesoc.ui.histogram.view.HistogramView.java
@Override public void createFramesocPartControl(Composite parent) { statusLineManager = getViewSite().getActionBars().getStatusLineManager(); // parent layout GridLayout gl_parent = new GridLayout(1, false); gl_parent.verticalSpacing = 2;/*w w w .jav a 2s.c om*/ gl_parent.marginWidth = 0; gl_parent.horizontalSpacing = 0; gl_parent.marginHeight = 0; parent.setLayout(gl_parent); // Sash SashForm sashForm = new SashForm(parent, SWT.NONE); sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); // Chart Composite compositeChart = new Composite(sashForm, SWT.BORDER); FillLayout fl_compositeChart = new FillLayout(SWT.HORIZONTAL); compositeChart.setLayout(fl_compositeChart); compositeChart.addControlListener(new ControlAdapter() { @Override public void controlResized(ControlEvent e) { int width = Math.max(compositeChart.getSize().x - 40, 1); numberOfTicks = Math.max(width / TIMESTAMP_MAX_SIZE, 1); refresh(false, false, true); } }); // Configuration Composite compositeConf = new Composite(sashForm, SWT.NONE); GridLayout gl_compositeConf = new GridLayout(1, false); gl_compositeConf.marginHeight = 1; gl_compositeConf.verticalSpacing = 0; gl_compositeConf.marginWidth = 0; compositeConf.setLayout(gl_compositeConf); compositeConf.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); // Tab folder TabFolder tabFolder = new TabFolder(compositeConf, SWT.NONE); tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); PatternFilter filter = new TreePatternFilter(); TreeContentProvider contentProvider = new TreeContentProvider(); ViewerComparator treeComparator = new ViewerComparator(); SelectionChangedListener selectionChangeListener = new SelectionChangedListener(); CheckStateListener checkStateListener = new CheckStateListener(); SquareIconLabelProvider p = null; // Tab item types TabItem tbtmEventTypes = new TabItem(tabFolder, SWT.NONE); tbtmEventTypes.setData(ConfigurationDimension.TYPE); tbtmEventTypes.setText(ConfigurationDimension.TYPE.getName()); filter.setIncludeLeadingWildcard(true); FilteredCheckboxTree typeTree = new FilteredCheckboxTree(tabFolder, SWT.BORDER, filter, true); configurationMap.get(ConfigurationDimension.TYPE).tree = typeTree; typeTree.getViewer().setContentProvider(contentProvider); p = new EventTypeTreeLabelProvider(); labelProviders.add(p); typeTree.getViewer().setLabelProvider(p); typeTree.getViewer().setComparator(treeComparator); typeTree.addCheckStateListener(checkStateListener); typeTree.getViewer().addSelectionChangedListener(selectionChangeListener); tbtmEventTypes.setControl(typeTree); // Tab item producers TabItem tbtmEventProducers = new TabItem(tabFolder, SWT.NONE); tbtmEventProducers.setData(ConfigurationDimension.PRODUCERS); tbtmEventProducers.setText(ConfigurationDimension.PRODUCERS.getName()); FilteredCheckboxTree prodTree = new FilteredCheckboxTree(tabFolder, SWT.BORDER, filter, true); configurationMap.get(ConfigurationDimension.PRODUCERS).tree = prodTree; prodTree.getViewer().setContentProvider(contentProvider); p = new EventProducerTreeLabelProvider(); labelProviders.add(p); prodTree.getViewer().setLabelProvider(p); prodTree.getViewer().setComparator(treeComparator); prodTree.addCheckStateListener(checkStateListener); prodTree.getViewer().addSelectionChangedListener(selectionChangeListener); tbtmEventProducers.setControl(prodTree); // sash weights sashForm.setWeights(new int[] { 80, 20 }); // tab switch tabFolder.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { currentDimension = (ConfigurationDimension) event.item.getData(); enableTreeButtons(); enableSubTreeButtons(); } }); // Buttons Composite compositeBtn = new Composite(compositeConf, SWT.BORDER); GridLayout gl_compositeBtn = new GridLayout(10, false); gl_compositeBtn.marginWidth = 1; gl_compositeBtn.horizontalSpacing = 1; compositeBtn.setLayout(gl_compositeBtn); compositeBtn.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false, 1, 1)); btnCheckall = new Button(compositeBtn, SWT.NONE); btnCheckall.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1)); btnCheckall.setToolTipText("Check all"); btnCheckall.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/check_all.png")); btnCheckall.setEnabled(false); btnCheckall.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (configurationMap.get(currentDimension).roots != null) { FilteredCheckboxTree tree = configurationMap.get(currentDimension).tree; TreeContentProvider provider = (TreeContentProvider) tree.getViewer().getContentProvider(); Object[] roots = provider.getElements(tree.getViewer().getInput()); for (Object root : roots) { checkElementAndSubtree(root); } selectionChanged(); } } }); btnUncheckall = new Button(compositeBtn, SWT.NONE); btnUncheckall.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); btnUncheckall.setToolTipText("Uncheck all"); btnUncheckall.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/uncheck_all.png")); btnUncheckall.setEnabled(false); btnUncheckall.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { configurationMap.get(currentDimension).tree.setCheckedElements(EMPTY_ARRAY); selectionChanged(); } }); Label separator = new Label(compositeBtn, SWT.SEPARATOR | SWT.VERTICAL); GridData gd_separator = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1); gd_separator.horizontalIndent = 2; gd_separator.widthHint = 5; gd_separator.heightHint = 20; separator.setLayoutData(gd_separator); btnCheckSubtree = new Button(compositeBtn, SWT.NONE); btnCheckSubtree.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); btnCheckSubtree.setToolTipText("Check subtree"); btnCheckSubtree.setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/check_subtree.png")); btnCheckSubtree.setEnabled(false); btnCheckSubtree.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (configurationMap.get(currentDimension).roots != null) { ITreeNode node = getCurrentSelection(configurationMap.get(currentDimension).tree); if (node == null) return; checkElementAndSubtree(node); selectionChanged(); } } }); btnUncheckSubtree = new Button(compositeBtn, SWT.NONE); btnUncheckSubtree.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1)); btnUncheckSubtree.setToolTipText("Uncheck subtree"); btnUncheckSubtree .setImage(ResourceManager.getPluginImage(Activator.PLUGIN_ID, "icons/uncheck_subtree.png")); btnUncheckSubtree.setEnabled(false); btnUncheckSubtree.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (configurationMap.get(currentDimension).roots != null) { ITreeNode node = getCurrentSelection(configurationMap.get(currentDimension).tree); if (node == null) return; uncheckElement(node); uncheckAncestors(node); selectionChanged(); } } }); // Time management bar Composite timeComposite = new Composite(parent, SWT.BORDER); timeComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); GridLayout gl_timeComposite = new GridLayout(1, false); gl_timeComposite.horizontalSpacing = 0; timeComposite.setLayout(gl_timeComposite); // time manager timeBar = new TimeBar(timeComposite, SWT.NONE, true, true); timeBar.setEnabled(false); IStatusLineManager statusLineManager = getViewSite().getActionBars().getStatusLineManager(); timeBar.setStatusLineManager(statusLineManager); timeBar.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { TimeInterval barInterval = timeBar.getSelection(); if (marker == null) { addNewMarker(barInterval.startTimestamp, barInterval.endTimestamp); } else { marker.setStartValue(barInterval.startTimestamp); marker.setEndValue(barInterval.endTimestamp); } selectedTs0 = barInterval.startTimestamp; selectedTs1 = barInterval.endTimestamp; timeChanged = !barInterval.equals(loadedInterval); } }); // button to synch the timebar, producers and type with the current loaded data timeBar.getSynchButton().setToolTipText("Reset Timebar, Types and Producers"); timeBar.getSynchButton().addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (loadedInterval != null) { timeBar.setSelection(loadedInterval); if (marker != null && plot != null) { plot.removeDomainMarker(marker); marker = null; } } for (ConfigurationData data : configurationMap.values()) { data.tree.setCheckedElements(data.checked); } timeChanged = false; enableTreeButtons(); enableSubTreeButtons(); } }); // load button timeBar.getLoadButton().addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (timeChanged || configurationChanged) { loadHistogram(currentShownTrace, timeBar.getSelection()); } } }); // build toolbar IActionBars actionBars = getViewSite().getActionBars(); IToolBarManager toolBar = actionBars.getToolBarManager(); TableTraceIntervalAction.add(toolBar, createTableAction()); GanttTraceIntervalAction.add(toolBar, createGanttAction()); PieTraceIntervalAction.add(toolBar, createPieAction()); enableActions(false); }
From source file:org.eclipse.swt.examples.fileviewer.FileViewer.java
/** * Creates the file tree view./*w w w.j a v a 2 s. co m*/ * * @param parent the parent control */ private void createTreeView(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 1; gridLayout.marginHeight = gridLayout.marginWidth = 2; gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0; composite.setLayout(gridLayout); treeScopeLabel = new Label(composite, SWT.BORDER); treeScopeLabel.setText(FileViewer.getResourceString("details.AllFolders.text")); treeScopeLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL)); tree = new Tree(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE); tree.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); tree.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent event) { final TreeItem[] selection = tree.getSelection(); if (selection != null && selection.length != 0) { TreeItem item = selection[0]; File file = (File) item.getData(TREEITEMDATA_FILE); notifySelectedDirectory(file); } } @Override public void widgetDefaultSelected(SelectionEvent event) { final TreeItem[] selection = tree.getSelection(); if (selection != null && selection.length != 0) { TreeItem item = selection[0]; item.setExpanded(true); treeExpandItem(item); } } }); tree.addTreeListener(new TreeAdapter() { @Override public void treeExpanded(TreeEvent event) { final TreeItem item = (TreeItem) event.item; final Image image = (Image) item.getData(TREEITEMDATA_IMAGEEXPANDED); if (image != null) item.setImage(image); treeExpandItem(item); } @Override public void treeCollapsed(TreeEvent event) { final TreeItem item = (TreeItem) event.item; final Image image = (Image) item.getData(TREEITEMDATA_IMAGECOLLAPSED); if (image != null) item.setImage(image); } }); createTreeDragSource(tree); createTreeDropTarget(tree); }
From source file:SWTFileViewerDemo.java
/** * Creates the file tree view./*from ww w . ja v a2 s. c o m*/ * * @param parent * the parent control */ private void createTreeView(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 1; gridLayout.marginHeight = gridLayout.marginWidth = 2; gridLayout.horizontalSpacing = gridLayout.verticalSpacing = 0; composite.setLayout(gridLayout); treeScopeLabel = new Label(composite, SWT.BORDER); treeScopeLabel.setText(SWTFileViewerDemo.getResourceString("details.AllFolders.text")); treeScopeLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL)); tree = new Tree(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE); tree.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); tree.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent event) { final TreeItem[] selection = tree.getSelection(); if (selection != null && selection.length != 0) { TreeItem item = selection[0]; File file = (File) item.getData(TREEITEMDATA_FILE); notifySelectedDirectory(file); } } public void widgetDefaultSelected(SelectionEvent event) { final TreeItem[] selection = tree.getSelection(); if (selection != null && selection.length != 0) { TreeItem item = selection[0]; item.setExpanded(true); treeExpandItem(item); } } }); tree.addTreeListener(new TreeAdapter() { public void treeExpanded(TreeEvent event) { final TreeItem item = (TreeItem) event.item; final Image image = (Image) item.getData(TREEITEMDATA_IMAGEEXPANDED); if (image != null) item.setImage(image); treeExpandItem(item); } public void treeCollapsed(TreeEvent event) { final TreeItem item = (TreeItem) event.item; final Image image = (Image) item.getData(TREEITEMDATA_IMAGECOLLAPSED); if (image != null) item.setImage(image); } }); createTreeDragSource(tree); createTreeDropTarget(tree); }
From source file:com.tocea.scertify.eclipse.scertifycode.ui.stats.views.GraphStatsView.java
/** * {@inheritDoc}// ww w . ja va 2s .c om * * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ public void createPartControl(final Composite parent) { super.createPartControl(parent); // set up the main layout final GridLayout layout = new GridLayout(1, false); layout.marginWidth = 0; layout.marginHeight = 0; parent.setLayout(layout); // the label this.mLabelDesc = new Label(parent, SWT.NONE); final GridData gridData = new GridData(); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; this.mLabelDesc.setLayoutData(gridData); // the main section this.mMainSection = new Composite(parent, SWT.NONE); this.mStackLayout = new StackLayout(); this.mStackLayout.marginHeight = 0; this.mStackLayout.marginWidth = 0; this.mMainSection.setLayout(this.mStackLayout); this.mMainSection.setLayoutData(new GridData(GridData.FILL_BOTH)); // create the master viewer this.mMasterComposite = createMasterView(this.mMainSection); // create the detail viewer this.mDetailViewer = createDetailView(this.mMainSection); this.mStackLayout.topControl = this.mMasterComposite; updateActions(); // initialize the view data refresh(Job.DECORATE); }
From source file:ConnectionInfo.java
protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NULL); composite.setLayout(new FillLayout()); // the vertical sashform. SashForm verticalForm = new SashForm(composite, SWT.VERTICAL); // the horizontal sashform. SashForm horizontalForm = new SashForm(verticalForm, SWT.HORIZONTAL); // Local dir browser. Composite compositeLocalDir = new Composite(horizontalForm, SWT.NULL); GridLayout gridLayout = new GridLayout(); gridLayout.horizontalSpacing = 1;// w w w . ja v a 2s . c om gridLayout.verticalSpacing = 1; compositeLocalDir.setLayout(gridLayout); Group compositeLocalDirTop = new Group(compositeLocalDir, SWT.NULL); compositeLocalDirTop.setText("Local"); GridLayout gridLayout2 = new GridLayout(3, false); gridLayout2.marginHeight = 0; compositeLocalDirTop.setLayout(gridLayout2); compositeLocalDirTop.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); labelPathLocal = new Label(compositeLocalDirTop, SWT.NULL); labelPathLocal.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); labelPathLocal.setText("Path: "); Button buttonUpLocalDir = new Button(compositeLocalDirTop, SWT.PUSH); buttonUpLocalDir.setText(actionUpLocalDir.getText()); buttonUpLocalDir.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { actionUpLocalDir.run(); } }); Button buttonBrowseLocalDir = new Button(compositeLocalDirTop, SWT.PUSH); buttonBrowseLocalDir.setText(actionBrowseLocalDir.getText()); buttonBrowseLocalDir.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { actionBrowseLocalDir.run(); } }); Table table = new Table(compositeLocalDir, SWT.BORDER); TableColumn tcFile = new TableColumn(table, SWT.LEFT); tcFile.setText("Name"); TableColumn tcSize = new TableColumn(table, SWT.NULL); tcSize.setText("Size"); TableColumn tcDate = new TableColumn(table, SWT.NULL); tcDate.setText("Date"); tcFile.setWidth(200); tcSize.setWidth(100); tcDate.setWidth(100); table.setHeaderVisible(true); table.setLayoutData(new GridData(GridData.FILL_BOTH)); localDirBrowser = new LocalDirectoryBrowser(table); table.addListener(SWT.MouseDoubleClick, new Listener() { public void handleEvent(Event event) { IStructuredSelection selection = (IStructuredSelection) localDirBrowser.getSelection(); File file = (File) selection.getFirstElement(); if (file != null && file.isDirectory()) { localDirBrowser.setInput(file); labelPathLocal.setText("Path: " + file); } } }); // Remote directory browser. Composite compositeRemoteDir = new Composite(horizontalForm, SWT.NULL); gridLayout = new GridLayout(); gridLayout.horizontalSpacing = 1; gridLayout.verticalSpacing = 1; compositeRemoteDir.setLayout(gridLayout); Group compositeRemoteDirTop = new Group(compositeRemoteDir, SWT.NULL); compositeRemoteDirTop.setText("Remote"); gridLayout2 = new GridLayout(2, false); gridLayout2.marginHeight = 0; compositeRemoteDirTop.setLayout(gridLayout2); compositeRemoteDirTop.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); labelPathRemote = new Label(compositeRemoteDirTop, SWT.NULL); labelPathRemote.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); labelPathRemote.setText("Path: "); Button buttonUpRemoteDir = new Button(compositeRemoteDirTop, SWT.PUSH); buttonUpRemoteDir.setText(actionUpLocalDir.getText()); buttonUpRemoteDir.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { actionUpRemoteDir.run(); } }); Table tableRemote = new Table(compositeRemoteDir, SWT.BORDER); TableColumn tcFileRemote = new TableColumn(tableRemote, SWT.LEFT); tcFileRemote.setText("Name"); TableColumn tcSizeRemote = new TableColumn(tableRemote, SWT.NULL); tcSizeRemote.setText("Size"); TableColumn tcDateRemote = new TableColumn(tableRemote, SWT.NULL); tcDateRemote.setText("Date"); tcFileRemote.setWidth(200); tcSizeRemote.setWidth(100); tcDateRemote.setWidth(100); tableRemote.setHeaderVisible(true); tableRemote.setLayoutData(new GridData(GridData.FILL_BOTH)); remoteDirBrowser = new RemoteDirectoryBrowser(tableRemote); tableRemote.addListener(SWT.MouseDoubleClick, new Listener() { public void handleEvent(Event event) { IStructuredSelection selection = (IStructuredSelection) remoteDirBrowser.getSelection(); FTPFile file = (FTPFile) selection.getFirstElement(); if (file != null && file.isDirectory()) { try { ftp.changeWorkingDirectory(file.getName()); labelPathRemote.setText("Path: " + ftp.printWorkingDirectory()); remoteDirBrowser.setInput(ftp.listFiles()); } catch (IOException e) { logError(e.toString()); } } } }); // the log box. textLog = new StyledText(verticalForm, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); localDirBrowser.setInput(File.listRoots()[0]); labelPathLocal.setText("Path: " + File.listRoots()[0]); // resize sashform children. verticalForm.setWeights(new int[] { 4, 1 }); // adding drag and drop support. dragNDropSupport(); getToolBarControl().setBackground(new Color(getShell().getDisplay(), 230, 230, 230)); getShell().setImage(new Image(getShell().getDisplay(), "icons/ftp/ftp.gif")); getShell().setText("FTP Client v1.0"); return composite; }
From source file:com.planetmayo.debrief.satc_rcp.views.MaintainContributionsView.java
private void initPreferencesGroup(Composite parent) { GridData gridData = new GridData(); gridData.horizontalAlignment = SWT.FILL; gridData.grabExcessHorizontalSpace = true; Group group = new Group(parent, SWT.SHADOW_ETCHED_IN); GridLayout layout = new GridLayout(1, false); group.setLayoutData(gridData);/*w w w .j a v a2 s .co m*/ group.setLayout(layout); group.setText("Preferences"); final ScrolledComposite scrolled = new ScrolledComposite(group, SWT.H_SCROLL); scrolled.setLayoutData(new GridData(GridData.FILL_BOTH)); final Composite preferencesComposite = UIUtils.createScrolledBody(scrolled, SWT.NONE); preferencesComposite.setLayout(new GridLayout(6, false)); scrolled.addListener(SWT.Resize, new Listener() { @Override public void handleEvent(Event e) { scrolled.setMinSize(preferencesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); } }); scrolled.setAlwaysShowScrollBars(true); scrolled.setContent(preferencesComposite); scrolled.setMinSize(preferencesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); scrolled.setExpandHorizontal(true); scrolled.setExpandVertical(true); liveConstraints = new Button(preferencesComposite, SWT.TOGGLE); liveConstraints.setText("Auto-Recalc of Constraints"); liveConstraints.setEnabled(false); liveConstraints .setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_CENTER)); recalculate = new Button(preferencesComposite, SWT.DEFAULT); recalculate.setText("Calculate Solution"); recalculate.setEnabled(false); recalculate.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (activeSolver != null) { // ok - make sure the performance tab is open graphTabs.setSelection(performanceTab); activeSolver.run(true, true); main.setSize(0, 0); main.getParent().layout(true, true); } } }); recalculate.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_CENTER)); cancelGeneration = new Button(preferencesComposite, SWT.PUSH); cancelGeneration.setText("Cancel"); cancelGeneration.setVisible(false); cancelGeneration.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (activeSolver != null) { activeSolver.cancel(); } } }); suppressCuts = new Button(preferencesComposite, SWT.CHECK); suppressCuts.setText("Suppress Cuts"); suppressCuts.setVisible(true); suppressCuts.setEnabled(false); suppressCuts.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (activeSolver != null) { boolean doSuppress = suppressCuts.getSelection(); activeSolver.setAutoSuppress(doSuppress); } } }); showOSCourse = new Button(preferencesComposite, SWT.CHECK); showOSCourse.setText("Plot O/S Course"); showOSCourse.setVisible(true); showOSCourse.setEnabled(false); showOSCourse.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (activeSolver != null) { redoOwnshipStates(); } } }); Composite precisionPanel = new Composite(preferencesComposite, SWT.NONE); precisionPanel.setLayoutData(new GridData( GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER)); GridLayout precisionLayout = new GridLayout(2, false); precisionLayout.horizontalSpacing = 5; precisionPanel.setLayout(precisionLayout); Label precisionLabel = new Label(precisionPanel, SWT.NONE); precisionLabel.setText("Precision:"); precisionLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER)); precisionsCombo = new ComboViewer(precisionPanel); precisionsCombo.getCombo().setEnabled(false); precisionsCombo.setContentProvider(new ArrayContentProvider()); precisionsCombo.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { return ((Precision) element).getLabel(); } }); precisionsCombo.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { ISelection sel = precisionsCombo.getSelection(); IStructuredSelection cSel = (IStructuredSelection) sel; Precision precision = (Precision) cSel.getFirstElement(); if (activeSolver != null) { activeSolver.setPrecision(precision); } } }); }
From source file:GraphicsExample.java
public void createControlPanel(Composite parent) { new Label(parent, SWT.NONE).setText(GraphicsExample.getResourceString("FillRule")); //$NON-NLS-1$ fillRuleCb = new Combo(parent, SWT.DROP_DOWN); fillRuleCb.add("FILL_EVEN_ODD"); fillRuleCb.add("FILL_WINDING"); fillRuleCb.select(0);// w w w.j av a2s . com fillRuleCb.addListener(SWT.Selection, example.getRedrawListener()); }
From source file:org.eclipse.swt.examples.clipboard.ClipboardExample.java
void createControlTransfer(Composite parent) { // TODO: CCombo and Spinner also have cut(), copy() and paste() API Label l = new Label(parent, SWT.NONE); l.setText("Text:"); Button b = new Button(parent, SWT.PUSH); b.setText("Cut"); b.addSelectionListener(widgetSelectedAdapter(e -> text.cut())); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(widgetSelectedAdapter(e -> text.copy())); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(widgetSelectedAdapter(e -> text.paste())); text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.widthHint = HSIZE;/*from ww w.ja v a2 s . com*/ data.heightHint = VSIZE; text.setLayoutData(data); l = new Label(parent, SWT.NONE); l.setText("Combo:"); b = new Button(parent, SWT.PUSH); b.setText("Cut"); b.addSelectionListener(widgetSelectedAdapter(e -> combo.cut())); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(widgetSelectedAdapter(e -> combo.copy())); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(widgetSelectedAdapter(e -> combo.paste())); combo = new Combo(parent, SWT.NONE); combo.setItems("Item 1", "Item 2", "Item 3", "A longer Item"); combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); l = new Label(parent, SWT.NONE); l.setText("StyledText:"); b = new Button(parent, SWT.PUSH); b.setText("Cut"); b.addSelectionListener(widgetSelectedAdapter(e -> styledText.cut())); b = new Button(parent, SWT.PUSH); b.setText("Copy"); b.addSelectionListener(widgetSelectedAdapter(e -> styledText.copy())); b = new Button(parent, SWT.PUSH); b.setText("Paste"); b.addSelectionListener(widgetSelectedAdapter(e -> styledText.paste())); styledText = new StyledText(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); data = new GridData(GridData.FILL_HORIZONTAL); data.widthHint = HSIZE; data.heightHint = VSIZE; styledText.setLayoutData(data); }