org.eclipse.jface.util.Util Java Examples

The following examples show how to use org.eclipse.jface.util.Util. 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: ProtectionFactory.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public static String getPlatform() {
	if (Util.isWindows()) {
		if ("32".equals(System.getProperty("sun.arch.data.model"))) {
			return "1";
		} else {
			return "2";
		}
	} else if (Util.isMac()) {
		return "5";
	} else {
		if ("32".equals(System.getProperty("sun.arch.data.model"))) {
			return "3";
		} else {
			return "4";
		}
	}
}
 
Example #2
Source File: ProtectionFactory.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public static String getPlatform() {
	if (Util.isWindows()) {
		if ("32".equals(System.getProperty("sun.arch.data.model"))) {
			return "1";
		} else {
			return "2";
		}
	} else if (Util.isMac()) {
		return "5";
	} else {
		if ("32".equals(System.getProperty("sun.arch.data.model"))) {
			return "3";
		} else {
			return "4";
		}
	}
}
 
Example #3
Source File: ConcordanceSearchDialog.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 构造方法
 * @param parentShell
 * @param file
 *            当前文件
 * @param strSrcLang
 *            当前文件的源语言
 * @param strTgtLang
 *            当前文件的目标语言
 * @param strSearchText
 *            搜索文本
 */
public ConcordanceSearchDialog(Shell parentShell, IFile file, String strSrcLang, String strTgtLang,
		String strSearchText) {
	super(parentShell);

	FontData fontData = JFaceResources.getDefaultFont().getFontData()[0];
	fontData.setStyle(fontData.getStyle() | SWT.BOLD);
	font = new Font(Display.getDefault(), fontData);
	style = new TextStyle(font, null, null);

	this.strSrcLang = strSrcLang;
	this.strTgtLang = strTgtLang;
	this.strSearchText = strSearchText;
	ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
	lstDatabase = projectConfig.getAllTmDbs();
	filterUnAvaliableDatabase();
	setHelpAvailable(true);
	setBlockOnOpen(false);
	lstSearchHistory = new ArrayList<String>(HISTORY_SIZE - 1);
	lstFilterHistory = new ArrayList<String>(HISTORY_SIZE - 1);
	if (!Util.isLinux()) {
		totalWidth = 910;
	}
}
 
Example #4
Source File: TBXMakerDialog.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private void displayHelp() {
	String curLang = CommonFunction.getSystemLanguage();
	StringBuffer sbHelp = new StringBuffer("help");
	if (Util.isWindows()) {
		sbHelp.append(File.separator).append("csv2tbxdoc").append(File.separator);
		if (curLang.equalsIgnoreCase("zh")) {
			sbHelp.append("tbxmaker_zh-cn.chm");
		} else {
			sbHelp.append("tbxmaker.chm");
		}
		Program.launch(PluginUtil.getConfigurationFilePath(sbHelp.toString()));
	} else {
		sbHelp.append(File.separator).append("csv2tbxdoc").append(File.separator);
		if (curLang.equalsIgnoreCase("zh")) {
			sbHelp.append("zh-cn");
		} else {
			sbHelp.append("en");
		}
		sbHelp.append(File.separator).append("toc.xml");
		PluginHelpDialog dialog = new PluginHelpDialog(getShell(), PluginUtil.getConfigurationFilePath(sbHelp.toString()),
				Messages.getString("dialog.TBXMakerDialog.helpDialogTitle"));
		dialog.open();
	}

}
 
Example #5
Source File: DBrowser.java    From Rel with Apache License 2.0 6 votes vote down vote up
private static void createMenuBar(Shell shell) {
	Menu bar = Display.getCurrent().getMenuBar();
	boolean hasAppMenuBar = (bar != null);
	
	if (bar == null)
		bar = new Menu(shell, SWT.BAR);

	// Populate the menu bar once if this is a screen menu bar.
	// Otherwise, we need to make a new menu bar for each shell.
	if (!createdScreenBar || !hasAppMenuBar) {
		
		createFileMenu(bar);
		createEditMenu(bar);
		createOutputMenu(bar);
		createDatabaseMenu(bar);
		createToolsMenu(bar);
		if (!Util.isMac())
			createHelpMenu(bar);
		
		if (!hasAppMenuBar) 
			shell.setMenuBar(bar);
		createdScreenBar = true;
	}
}
 
Example #6
Source File: BrowserNative.java    From Rel with Apache License 2.0 6 votes vote down vote up
@Override
public boolean createWidget(Composite parent) {
	if (Util.isMac())
		style = new Style(-3);
	else
		style = new Style(0);
	try {
		browser = new BrowserNativeWidget(parent, SWT.BORDER);
		browser.setJavascriptEnabled(true);
		browser.addProgressListener(new ProgressAdapter() {
			@Override
			public void completed(ProgressEvent event) {
				pumpQueue();
			}
		});
	} catch (Throwable t) {
		System.out.println("BrowserNative: Native browser not available: " + t);
		return false;
	}
	clear();
	return true;
}
 
Example #7
Source File: ConcordanceSearchDialog.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 构造方法
 * @param parentShell
 * @param file
 *            当前文件
 * @param strSrcLang
 *            当前文件的源语言
 * @param strTgtLang
 *            当前文件的目标语言
 * @param strSearchText
 *            搜索文本
 */
public ConcordanceSearchDialog(Shell parentShell, IFile file, String strSrcLang, String strTgtLang,
		String strSearchText) {
	super(parentShell);

	FontData fontData = JFaceResources.getDefaultFont().getFontData()[0];
	fontData.setStyle(fontData.getStyle() | SWT.BOLD);
	font = new Font(Display.getDefault(), fontData);
	style = new TextStyle(font, null, null);

	this.strSrcLang = strSrcLang;
	this.strTgtLang = strTgtLang;
	this.strSearchText = strSearchText;
	ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
	lstDatabase = projectConfig.getAllTmDbs();
	filterUnAvaliableDatabase();
	setHelpAvailable(true);
	setBlockOnOpen(false);
	lstSearchHistory = new ArrayList<String>(HISTORY_SIZE - 1);
	lstFilterHistory = new ArrayList<String>(HISTORY_SIZE - 1);
	if (!Util.isLinux()) {
		totalWidth = 910;
	}
}
 
Example #8
Source File: TBXMakerDialog.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
private void displayHelp() {
	String curLang = CommonFunction.getSystemLanguage();
	StringBuffer sbHelp = new StringBuffer("help");
	if (Util.isWindows()) {
		sbHelp.append(File.separator).append("csv2tbxdoc").append(File.separator);
		if (curLang.equalsIgnoreCase("zh")) {
			sbHelp.append("tbxmaker_zh-cn.chm");
		} else {
			sbHelp.append("tbxmaker.chm");
		}
		Program.launch(PluginUtil.getConfigurationFilePath(sbHelp.toString()));
	} else {
		sbHelp.append(File.separator).append("csv2tbxdoc").append(File.separator);
		if (curLang.equalsIgnoreCase("zh")) {
			sbHelp.append("zh-cn");
		} else {
			sbHelp.append("en");
		}
		sbHelp.append(File.separator).append("toc.xml");
		PluginHelpDialog dialog = new PluginHelpDialog(getShell(), PluginUtil.getConfigurationFilePath(sbHelp.toString()),
				Messages.getString("dialog.TBXMakerDialog.helpDialogTitle"));
		dialog.open();
	}

}
 
Example #9
Source File: GamaActionBarAdvisor.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates and returns the Help menu.
 */
private MenuManager createHelpMenu() {
	final MenuManager menu = new MenuManager(IDEWorkbenchMessages.Workbench_help, IWorkbenchActionConstants.M_HELP);
	addSeparatorOrGroupMarker(menu, "group.intro"); //$NON-NLS-1$
	menu.add(new GroupMarker("group.intro.ext")); //$NON-NLS-1$
	addSeparatorOrGroupMarker(menu, "group.main"); //$NON-NLS-1$
	menu.add(helpContentsAction);
	addSeparatorOrGroupMarker(menu, "group.assist"); //$NON-NLS-1$
	menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_START));
	menu.add(new GroupMarker("group.main.ext")); //$NON-NLS-1$
	addSeparatorOrGroupMarker(menu, "group.tutorials"); //$NON-NLS-1$
	addSeparatorOrGroupMarker(menu, "group.tools"); //$NON-NLS-1$
	addSeparatorOrGroupMarker(menu, "group.updates"); //$NON-NLS-1$
	menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_END));
	addSeparatorOrGroupMarker(menu, IWorkbenchActionConstants.MB_ADDITIONS);
	// about should always be at the bottom
	menu.add(new Separator("group.about")); //$NON-NLS-1$

	final ActionContributionItem aboutItem = new ActionContributionItem(aboutAction);
	aboutItem.setVisible(!Util.isMac());
	menu.add(aboutItem);
	menu.add(new GroupMarker("group.about.ext")); //$NON-NLS-1$
	menu.add(openPreferencesAction);
	return menu;
}
 
Example #10
Source File: ExampleDropTargetListener.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
private boolean dropTargetIsValid(DropTargetEvent e, boolean isDrop) {
	if (URLTransfer.getInstance().isSupportedType(e.currentDataType)) {
		// on Windows, we get the URL already during drag operations...
		// FIXME find a way to check the URL early on other platforms,
		// too...
		if (isDrop || Util.isWindows()) {
			if (e.data == null && !extractEventData(e)) {
				// ... but if we don't, it's no problem, unless this is
				// already
				// the final drop event
				return !isDrop;
			}
			final String url = getUrl(e.data);
			if (!ExampleURLHandler.isValidExample(url)) {
				return false;
			}
		}
		return true;
	}
	return false;
}
 
Example #11
Source File: ProtectionFactory.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public static String getSeries() {
	SeriesInterface s;
	if (Util.isWindows()) {
		s = new WindowsSeries();
	} else if (Util.isMac()) {
		s = new MacosxSeries();
	} else {
		s = new LinuxSeries();
	}
	
	return s.getSeries();
}
 
Example #12
Source File: XFindPanel.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private Point getToolItemLocation(ToolItem item) {
    Rectangle rect = item.getBounds();
    Point point = new Point(rect.x, rect.y + rect.height);
    point = toolBar.toDisplay(point);
    if (Util.isMac()) {
        point.y += 5;
    }
    return point;
}
 
Example #13
Source File: PreferencePageGeneral.java    From Rel with Apache License 2.0 5 votes vote down vote up
protected void createFieldEditors() {
	String reloadPrompt = "";
	if (!Util.isMac()) {
		reloadPrompt = "  Restart after changing to see the full effect. ";
		if (IconLoader.getDPIScaling() > 100)
			reloadPrompt += "\nNOTE: larger icons may not work correctly on some HiDPI displays.";
	}
	addField(new BooleanFieldEditor(LARGE_ICONS, "&Larger icons." + reloadPrompt, getFieldEditorParent()));
	
	addField(new BooleanFieldEditor(DEFAULT_CMD_MODE, "Default to command-line mode.", getFieldEditorParent()));
	
	addField(new BooleanFieldEditor(SKIP_DEFAULT_DB_LOAD, "Do not automatically load user's default database.", getFieldEditorParent()));
}
 
Example #14
Source File: DBrowser.java    From Rel with Apache License 2.0 5 votes vote down vote up
private static boolean executeSplashInteractor(Runnable splashInteraction) {
	if (SplashScreen.getSplashScreen() == null)
		return false;
	
	// Non-MacOS
	if (!Util.isMac()) {
		splashInteraction.run();
		closeSplash();
		return true;
	}

	// MacOS
	Display display = Display.getDefault();
	final Semaphore sem = new Semaphore(0);
	Thread splashInteractor = new Thread(() -> {
		splashInteraction.run();
		sem.release();
		display.asyncExec(() -> {});
		closeSplash();
	});
	splashInteractor.start();

	// Interact with splash screen
	while (!display.isDisposed() && !sem.tryAcquire())
		if (!display.readAndDispatch())
			display.sleep();
	
	return true;
}
 
Example #15
Source File: ProtectionFactory.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public static String getSeries() {
	SeriesInterface s;
	if (Util.isWindows()) {
		s = new WindowsSeries();
	} else if (Util.isMac()) {
		s = new MacosxSeries();
	} else {
		s = new LinuxSeries();
	}
	
	return s.getSeries();
}
 
Example #16
Source File: ChangeCorrectionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the change that will be executed when the proposal is applied.
 * This method calls {@link #createChange()} to compute the change.
 * 
 * @return the change for this proposal, can be <code>null</code> in rare cases if creation of
 *         the change failed
 * @throws CoreException when the change could not be created
 */
public final Change getChange() throws CoreException {
	if (Util.isGtk()) {
		// workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=293995 :
		// [Widgets] Deadlock while UI thread displaying/computing a change proposal and non-UI thread creating image
		
		// Solution is to create the change outside a 'synchronized' block.
		// Synchronization is achieved by polling fChange, using "fChange == COMPUTING_CHANGE" as barrier.
		// Timeout of 10s for safety reasons (should not be reached).
		long end= System.currentTimeMillis() + 10000;
		do {
			boolean computing;
			synchronized (this) {
				computing= fChange == COMPUTING_CHANGE;
			}
			if (computing) {
				try {
					Display display= Display.getCurrent();
					if (display != null) {
						while (! display.isDisposed() && display.readAndDispatch()) {
							// empty the display loop
						}
						display.sleep();
					} else {
						Thread.sleep(100);
					}
				} catch (InterruptedException e) {
					//continue
				}
			} else {
				synchronized (this) {
					if (fChange == COMPUTING_CHANGE) {
						continue;
					} else if (fChange != null) {
						return fChange;
					} else {
						fChange= COMPUTING_CHANGE;
					}
				}
				Change change= createChange();
				synchronized (this) {
					fChange= change;
				}
				return change;
			}
		} while (System.currentTimeMillis() < end);
		
		synchronized (this) {
			if (fChange == COMPUTING_CHANGE) {
				return null; //failed
			}
		}
		
	} else {
		synchronized (this) {
			if (fChange == null) {
				fChange= createChange();
			}
		}
	}
	return fChange;
}
 
Example #17
Source File: DBrowser.java    From Rel with Apache License 2.0 4 votes vote down vote up
private static void createEditMenu(Menu bar) {		
	MenuItem editItem = new MenuItem(bar, SWT.CASCADE);
	editItem.setText("Edit");
	
	Menu menu = new Menu(editItem);
	editItem.setMenu(menu);
	
	createEditMenuItem("undo", new AcceleratedMenuItem(menu, "Undo\tCtrl-Z", SWT.MOD1 | 'Z', "undo"));
	
	int redoAccelerator = SWT.MOD1 | (Util.isMac() ? SWT.SHIFT | 'Z' : 'Y');
	createEditMenuItem("redo", new AcceleratedMenuItem(menu, "Redo\tCtrl-Y", redoAccelerator, "redo"));
	
	new MenuItem(menu, SWT.SEPARATOR);
	
	createEditMenuItem("cut", new AcceleratedMenuItem(menu, "Cut\tCtrl-X", SWT.MOD1 | 'X', "cut"));
	createEditMenuItem("copy", new AcceleratedMenuItem(menu, "Copy\tCtrl-C", SWT.MOD1 | 'C', "copy"));
	createEditMenuItem("paste", new AcceleratedMenuItem(menu, "Paste\tCtrl-V", SWT.MOD1 | 'V', "paste") {
		public boolean canExecute() {
			return isThereSomethingToPaste();
		}
	});
	
	new MenuItem(menu, SWT.SEPARATOR);
	
	createEditMenuItem("clear", new AcceleratedMenuItem(menu, "Clear", 0, "clearIcon"));
	createEditMenuItem("delete", new AcceleratedMenuItem(menu, "Delete\tDel", SWT.DEL, "delete"));
	createEditMenuItem("selectAll", new AcceleratedMenuItem(menu, "Select All\tCtrl-A", SWT.MOD1 | 'A', "selectAll"));
	linkCommand(Commands.Do.FindReplace, new AcceleratedMenuItem(menu, "Find/Replace", 0, "edit_find_replace"));
	
	new MenuItem(menu, SWT.SEPARATOR);
	
	linkCommand(Commands.Do.SpecialCharacters, new AcceleratedMenuItem(menu, "Special characters", 0, "characters"));
	linkCommand(Commands.Do.PreviousHistory, new AcceleratedMenuItem(menu, "Previous history", 0, "previousIcon"));
	linkCommand(Commands.Do.NextHistory, new AcceleratedMenuItem(menu, "Next history", 0, "nextIcon"));
	linkCommand(Commands.Do.LoadFile, new AcceleratedMenuItem(menu, "Load file", 0, "loadIcon"));
	linkCommand(Commands.Do.InsertFile, new AcceleratedMenuItem(menu, "Insert file", 0, "loadInsertIcon"));
	linkCommand(Commands.Do.InsertFileName, new AcceleratedMenuItem(menu, "Insert file name", 0, "pathIcon"));
	linkCommand(Commands.Do.SaveFile, new AcceleratedMenuItem(menu, "Save file", 0, "saveIcon"));
	linkCommand(Commands.Do.SaveHistory, new AcceleratedMenuItem(menu, "Save history", 0, "saveHistoryIcon"));

		new MenuItem(menu, SWT.SEPARATOR);

		linkCommand(Commands.Do.CopyInputToOutput, new AcceleratedMenuItem(menu, "Copy input to output", 0, "copyToOutputIcon", SWT.CHECK));
		linkCommand(Commands.Do.WrapText, new AcceleratedMenuItem(menu, "Wrap text", 0, "wrapIcon", SWT.CHECK));
}
 
Example #18
Source File: GamaActionBarAdvisor.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates and returns the File menu.
 */
private MenuManager createFileMenu() {
	final MenuManager menu = new MenuManager(IDEWorkbenchMessages.Workbench_file, IWorkbenchActionConstants.M_FILE);
	menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_START));
	{
		// create the New submenu, using the same id for it as the New action
		final String newText = IDEWorkbenchMessages.Workbench_new;
		final String newId = ActionFactory.NEW.getId();
		final MenuManager newMenu = new MenuManager(newText, newId);
		newMenu.setActionDefinitionId("org.eclipse.ui.file.newQuickMenu"); //$NON-NLS-1$
		newMenu.setImageDescriptor(icons.desc("navigator/navigator.new2"));
		newMenu.add(new Separator(newId));
		this.newWizardMenu = new BaseNewWizardMenu(getWindow(), null) {

			@Override
			protected void addItems(final List list) {
				addShortcuts(list);
			}
		};
		newMenu.add(this.newWizardMenu);
		newMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
		menu.add(newMenu);
	}

	menu.add(new GroupMarker(IWorkbenchActionConstants.NEW_EXT));
	menu.add(new Separator());

	menu.add(closeAction);
	menu.add(closeAllAction);
	menu.add(new GroupMarker(IWorkbenchActionConstants.CLOSE_EXT));
	menu.add(new Separator());
	menu.add(saveAction);
	menu.add(saveAsAction);
	menu.add(saveAllAction);
	// menu.add(getRevertItem());
	menu.add(new Separator());
	menu.add(getMoveItem());
	menu.add(getRenameItem());
	menu.add(getRefreshItem());

	menu.add(new GroupMarker(IWorkbenchActionConstants.SAVE_EXT));
	menu.add(new Separator());
	menu.add(getPrintItem());
	menu.add(new GroupMarker(IWorkbenchActionConstants.PRINT_EXT));
	menu.add(new Separator());
	menu.add(openWorkspaceAction);
	menu.add(new GroupMarker(IWorkbenchActionConstants.OPEN_EXT));
	menu.add(new GroupMarker(IWorkbenchActionConstants.IMPORT_EXT));
	menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));

	menu.add(new Separator());
	menu.add(getPropertiesItem());

	menu.add(ContributionItemFactory.REOPEN_EDITORS.create(getWindow()));
	menu.add(new GroupMarker(IWorkbenchActionConstants.MRU));
	menu.add(new Separator());

	// If we're on OS X we shouldn't show this command in the File menu. It
	// should be invisible to the user. However, we should not remove it -
	// the carbon UI code will do a search through our menu structure
	// looking for it when Cmd-Q is invoked (or Quit is chosen from the
	// application menu.
	final ActionContributionItem quitItem = new ActionContributionItem(quitAction);
	quitItem.setVisible(!Util.isMac());
	menu.add(quitItem);
	menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_END));
	return menu;
}
 
Example #19
Source File: DBrowser.java    From Rel with Apache License 2.0 4 votes vote down vote up
private static void launch(String[] args) {
	Display.setAppName(Version.getAppName());
	Display.setAppVersion(Version.getVersion());
	final Display display = new Display();
	
	OpenDocumentEventProcessor openDocProcessor = new OpenDocumentEventProcessor();
	display.addListener(SWT.OpenDocument, openDocProcessor);
	
	openDocProcessor.addFilesToOpen(args);		

	if (Util.isMac())
		executeSplashInteractor(() -> {
			try {
				Thread.sleep(300);
			} catch (InterruptedException e1) {
			}
		});

	try {
		Class.forName("org.reldb.rel.Rel");
		localRel = true;
	} catch (ClassNotFoundException cnfe) {
		localRel = false;
	}
	
	OSSpecific.launch(Version.getAppName(),
		event -> quit(),
		event -> new AboutDialog(shell).open(),
		event -> new Preferences(shell).show()
	);

	if (!Util.isMac()) {
		SplashScreen splash = SplashScreen.getSplashScreen();
		if (splash != null && localRel && !Preferences.getPreferenceBoolean(PreferencePageGeneral.SKIP_DEFAULT_DB_LOAD)) {
			Graphics2D gc = splash.createGraphics();
			Rectangle rect = splash.getBounds();
			int barWidth = rect.width - 20;
			int barHeight = 10;
			Rectangle progressBarRect = new Rectangle(10, rect.height - 20, barWidth, barHeight);
			gc.draw3DRect(progressBarRect.x, progressBarRect.y, progressBarRect.width, progressBarRect.height, false);
			gc.setColor(Color.green);
			(new Thread(() -> {
				while (SplashScreen.getSplashScreen() != null) {
					int percent = Loading.getPercentageOfExpectedMessages();
					int drawExtent = Math.min(barWidth * percent / 100, barWidth);
					gc.fillRect(progressBarRect.x, progressBarRect.y, drawExtent, barHeight);
					splash.update();					
					try {
						Thread.sleep(250);
					} catch (InterruptedException e) {
					}
				}							
			})).start();
		}			
	}
	
	shell = createShell();
	shell.setImage(IconLoader.loadIcon("RelIcon"));
	shell.setImages(loadIcons(display));
	shell.setText(Version.getAppID());
	shell.addListener(SWT.Close, e -> {
		shell.dispose();
	});
	shell.addDisposeListener(e -> quit());
	shell.layout();

	Loading.start();
	
	Core.launch(openDocProcessor, shell);
	
	if (!Util.isMac())
		closeSplash();
	
	shell.open();		
	
	while (!display.isDisposed()) {
		try {
			if (!display.readAndDispatch())
				display.sleep();
		} catch (Throwable t) {
			System.out.println("DBrowser: Exception: " + t);
			t.printStackTrace();
		}
	}
}
 
Example #20
Source File: TimeGraphFindDialog.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected Control createContents(Composite parent) {

    Composite panel = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.makeColumnsEqualWidth = true;
    panel.setLayout(layout);
    panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Composite inputPanel = createInputPanel(panel);
    setGridData(inputPanel, SWT.FILL, true, SWT.TOP, false);

    Composite configPanel = createConfigPanel(panel);
    setGridData(configPanel, SWT.FILL, true, SWT.TOP, true);

    Composite statusBar = createStatusAndCloseButton(panel);
    setGridData(statusBar, SWT.FILL, true, SWT.BOTTOM, false);

    panel.addTraverseListener(e -> {
        if (e.detail == SWT.TRAVERSE_RETURN) {
            if (!Util.isMac()) {
                Control controlWithFocus = getShell().getDisplay().getFocusControl();
                if (controlWithFocus != null && (controlWithFocus.getStyle() & SWT.PUSH) == SWT.PUSH) {
                    return;
                }
            }
            Event event1 = new Event();
            event1.type = SWT.Selection;
            event1.stateMask = e.stateMask;
            fFindNextButton.notifyListeners(SWT.Selection, event1);
            e.doit = false;
        } else if (e.detail == SWT.TRAVERSE_MNEMONIC) {
            Character mnemonic = new Character(Character.toLowerCase(e.character));
            Button button = fMnemonicButtonMap.get(mnemonic);
            if (button != null) {
                if ((fFindField.isFocusControl() || (button.getStyle() & SWT.PUSH) != 0)
                        && button.isEnabled()) {
                    Event event2 = new Event();
                    event2.type = SWT.Selection;
                    event2.stateMask = e.stateMask;
                    if ((button.getStyle() & SWT.RADIO) != 0) {
                        Composite buttonParent = button.getParent();
                        if (buttonParent != null) {
                            Control[] children = buttonParent.getChildren();
                            for (int i = 0; i < children.length; i++) {
                                ((Button) children[i]).setSelection(false);
                            }
                        }
                        button.setSelection(true);
                    } else {
                        button.setSelection(!button.getSelection());
                    }
                    button.notifyListeners(SWT.Selection, event2);
                    e.detail = SWT.TRAVERSE_NONE;
                    e.doit = true;
                }
            }
        }
    });

    updateButtonState();

    applyDialogFont(panel);

    return panel;
}
 
Example #21
Source File: XBookmarksDialog.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
@Override
 protected Control createDialogArea(Composite parent) {
     Composite composite = (Composite) super.createDialogArea(parent);
     GridLayoutFactory.fillDefaults().extendedMargins(Util.isWindows() ? 0 : 3, 3, 2, 2).applyTo(composite);

     Composite tableComposite = new Composite(composite, SWT.NONE);
     tableComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
     tableComposite.setLayout(new GridLayout(1, false));
     
     tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
             | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
     
     table = tableViewer.getTable();
     table.setLayoutData(new GridData(GridData.FILL_BOTH));
     tableViewer.setContentProvider(new MenuTableContentProvider());
     tableViewer.setLabelProvider(new MenuTableLabelProvider());

     { // Columns:
         GC gc= new GC(table);
         try {
         	int maxW = gc.stringExtent("WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW").x; //$NON-NLS-1$
         	int gap  = gc.stringExtent("WW").x; //$NON-NLS-1$
         	int widths[] = new int[model.columns];
         	for (int i=0; i<model.columns; ++i) {
         		widths[i] = 0;
         	}
         	for (Model.Row r : model.getRows()) {
         		for (int i=0; i<model.columns; ++i) {
         			if (!r.getField(i).isEmpty()) {
         				int w     = Math.min(gc.stringExtent(r.getField(i)).x + gap, maxW);
         				widths[i] = Math.max(widths[i], w);
         			}
         		}
         	}
         	
         	for (int i=0; i<model.columns; ++i) {
         		TableColumn tc = new TableColumn(table, SWT.LEFT);
         		tc.setWidth(widths[i]);
         	}
         	table.setHeaderVisible(false);
         	table.setLinesVisible(false);
} finally {
	gc.dispose();
}
     }
     
     Listener eventListener = new Listener() {
         @Override
         public void handleEvent(Event event) {
             if (event.type == SWT.MouseDoubleClick || 
                (event.type == SWT.KeyDown && event.character == SWT.CR)) 
             {
                 doSelect();
             }
         }
         
     };
     
     addListener (SWT.KeyDown, eventListener);
     addListener (SWT.MouseDoubleClick, eventListener);
         
     tableViewer.setInput(model);
     table.select(0);

     return composite;
 }