Search in sources :

Example 91 with Display

use of org.eclipse.swt.widgets.Display in project cubrid-manager by CUBRID.

the class CubridBrokerFolderLoader method load.

/**
	 * 
	 * Load children object for parent
	 * 
	 * @param parent the parent node
	 * @param monitor the IProgressMonitor object
	 */
public void load(final ICubridNode parent, final IProgressMonitor monitor) {
    synchronized (this) {
        if (isLoaded()) {
            return;
        }
        //when refresh broker,firstly check whether this broker exist
        int ret = checkBrokerExist(parent, monitor);
        if (ret == 1 || ret == 2) {
            setLoaded(true);
            return;
        }
        if (ret != 0) {
            Display display = Display.getDefault();
            display.syncExec(new Runnable() {

                public void run() {
                    CommonUITool.openErrorBox(Messages.errBrokerNoExist);
                    CubridNavigatorView navigatorView = CubridNavigatorView.getNavigatorView(CubridHostNavigatorView.ID);
                    TreeViewer treeViewer = navigatorView == null ? null : navigatorView.getViewer();
                    if (treeViewer != null) {
                        CommonUITool.refreshNavigatorTree(treeViewer, parent.getParent());
                    }
                }
            });
            setLoaded(true);
            return;
        }
        // add sql log folder
        String sqlLogFolderId = parent.getId() + NODE_SEPARATOR + SQL_LOG_FOLDER_ID;
        ICubridNode sqlLogFolder = parent.getChild(sqlLogFolderId);
        if (sqlLogFolder == null) {
            sqlLogFolder = new DefaultCubridNode(sqlLogFolderId, SQL_LOG_FOLDER_NAME, "icons/navigator/folder.png");
            sqlLogFolder.setType(CubridNodeType.BROKER_SQL_LOG_FOLDER);
            sqlLogFolder.setContainer(true);
            parent.addChild(sqlLogFolder);
        }
        //add the children of sql log folder
        ServerInfo serverInfo = parent.getServer().getServerInfo();
        BrokerLogInfos brokerLogInfos = new BrokerLogInfos();
        final CommonQueryTask<BrokerLogInfos> task = new CommonQueryTask<BrokerLogInfos>(serverInfo, CommonSendMsg.getGetBrokerLogFileInfoMSGItems(), brokerLogInfos);
        task.setBroker(parent.getLabel());
        monitorCancel(monitor, new ITask[] { task });
        task.execute();
        final String errorMsg = task.getErrorMsg();
        if (!monitor.isCanceled() && errorMsg != null && errorMsg.trim().length() > 0) {
            sqlLogFolder.removeAllChild();
            openErrorBox(errorMsg);
            setLoaded(true);
            return;
        }
        if (monitor.isCanceled()) {
            setLoaded(true);
            return;
        }
        sqlLogFolder.removeAllChild();
        brokerLogInfos = task.getResultModel();
        List<LogInfo> logInfoList = brokerLogInfos == null ? null : brokerLogInfos.getBrokerLogInfoList().getLogFileInfoList();
        if (logInfoList != null && !logInfoList.isEmpty()) {
            for (LogInfo logInfo : logInfoList) {
                String id = sqlLogFolder.getId() + NODE_SEPARATOR + logInfo.getName();
                ICubridNode logInfoNode = new DefaultCubridNode(id, logInfo.getName(), "icons/navigator/sqllog_item.png");
                logInfoNode.setContainer(false);
                logInfoNode.setEditorId(LogEditorPart.ID);
                logInfoNode.setModelObj(logInfo);
                if (LogType.SCRIPT.getText().toLowerCase().equals(logInfo.getType())) {
                    logInfoNode.setType(CubridNodeType.BROKER_SQL_LOG);
                    sqlLogFolder.addChild(logInfoNode);
                }
            }
        }
        Collections.sort(sqlLogFolder.getChildren());
        setLoaded(true);
        CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent((ICubridNode) parent, CubridNodeChangedEventType.CONTAINER_NODE_REFRESH));
    }
}
Also used : DefaultCubridNode(com.cubrid.common.ui.spi.model.DefaultCubridNode) LogInfo(com.cubrid.cubridmanager.core.logs.model.LogInfo) BrokerLogInfos(com.cubrid.cubridmanager.core.logs.model.BrokerLogInfos) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) CommonQueryTask(com.cubrid.cubridmanager.core.common.task.CommonQueryTask) Display(org.eclipse.swt.widgets.Display)

Example 92 with Display

use of org.eclipse.swt.widgets.Display in project bndtools by bndtools.

the class PackageDecorator method updateDecoration.

public static void updateDecoration(IProject project, Project model) throws Exception {
    if (!project.isOpen()) {
        return;
    }
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject == null) {
        // project is not a java project
        return;
    }
    boolean changed = false;
    for (IClasspathEntry cpe : javaProject.getRawClasspath()) {
        if (cpe.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
            continue;
        }
        for (IPackageFragmentRoot pkgRoot : javaProject.findPackageFragmentRoots(cpe)) {
            assert pkgRoot.getKind() == IPackageFragmentRoot.K_SOURCE;
            IResource pkgRootResource = pkgRoot.getCorrespondingResource();
            if (pkgRootResource == null) {
                continue;
            }
            File pkgRootFile = pkgRootResource.getLocation().toFile();
            boolean pkgInSourcePath = model.getSourcePath().contains(pkgRootFile);
            for (IJavaElement child : pkgRoot.getChildren()) {
                IPackageFragment pkg = (IPackageFragment) child;
                assert pkg.getKind() == IPackageFragmentRoot.K_SOURCE;
                IResource pkgResource = pkg.getCorrespondingResource();
                if (pkgResource == null) {
                    continue;
                }
                String text = pkgResource.getPersistentProperty(packageDecoratorKey);
                if (pkgInSourcePath) {
                    String pkgName = pkg.getElementName();
                    // Decorate if exported package
                    Attrs pkgAttrs = model.getExports().getByFQN(pkgName);
                    if (pkgAttrs != null) {
                        StringBuilder sb = new StringBuilder(" ").append(Version.parseVersion(pkgAttrs.getVersion()));
                        pkgAttrs = model.getImports().getByFQN(pkgName);
                        if (pkgAttrs != null) {
                            String versionRange = pkgAttrs.getVersion();
                            if (versionRange != null) {
                                sb.append('↔').append(versionRange);
                            }
                        }
                        String version = sb.toString();
                        if (!version.equals(text)) {
                            pkgResource.setPersistentProperty(packageDecoratorKey, version);
                            changed = true;
                        }
                        continue;
                    }
                    // Decorate if non-empty, non-contained package
                    if (pkg.containsJavaResources() && !model.getContained().containsFQN(pkgName)) {
                        if (!excluded.equals(text)) {
                            pkgResource.setPersistentProperty(packageDecoratorKey, excluded);
                            changed = true;
                        }
                        continue;
                    }
                }
                // Clear decoration
                if (text != null) {
                    pkgResource.setPersistentProperty(packageDecoratorKey, null);
                    changed = true;
                }
            }
        }
    }
    // If decoration change, update display
    if (changed) {
        Display display = PlatformUI.getWorkbench().getDisplay();
        SWTConcurrencyUtil.execForDisplay(display, true, new Runnable() {

            @Override
            public void run() {
                PlatformUI.getWorkbench().getDecoratorManager().update(packageDecoratorId);
            }
        });
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Attrs(aQute.bnd.header.Attrs) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IJavaProject(org.eclipse.jdt.core.IJavaProject) File(java.io.File) IResource(org.eclipse.core.resources.IResource) Display(org.eclipse.swt.widgets.Display)

Example 93 with Display

use of org.eclipse.swt.widgets.Display in project bndtools by bndtools.

the class ResolutionChoiceInteractCallback method processCandidates.

public void processCandidates(final Requirement requirement, Set<Capability> wired, final List<Capability> candidates) {
    if (wired.size() > 0 || candidates.size() < 2)
        return;
    final Display display = PlatformUI.getWorkbench().getDisplay();
    final AtomicInteger resultRef = new AtomicInteger();
    Runnable runnable = new Runnable() {

        public void run() {
            Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
            if (!shell.isDisposed()) {
                ResolutionChoiceSelectionDialog dialog = new ResolutionChoiceSelectionDialog(shell, requirement, candidates);
                resultRef.set(dialog.open());
            } else {
                resultRef.set(IDialogConstants.CANCEL_ID);
            }
        }
    };
    display.syncExec(runnable);
    int result = resultRef.get();
    if (result == IDialogConstants.CANCEL_ID)
        throw new ResolveCancelledException();
}
Also used : ResolveCancelledException(org.bndtools.core.resolve.ResolveCancelledException) Shell(org.eclipse.swt.widgets.Shell) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Display(org.eclipse.swt.widgets.Display)

Example 94 with Display

use of org.eclipse.swt.widgets.Display in project bndtools by bndtools.

the class LaunchStatusHandler method handleStatus.

public Boolean handleStatus(final IStatus status, Object source) throws CoreException {
    if (status.isOK())
        return true;
    final AtomicBoolean result = new AtomicBoolean();
    Runnable uitask = new Runnable() {

        public void run() {
            LaunchStatusDialog dialog = new LaunchStatusDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), status);
            int response = dialog.open();
            result.set(response == Window.OK);
        }
    };
    Display display = PlatformUI.getWorkbench().getDisplay();
    if (display.getThread() == Thread.currentThread())
        uitask.run();
    else
        display.syncExec(uitask);
    return result.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Display(org.eclipse.swt.widgets.Display)

Example 95 with Display

use of org.eclipse.swt.widgets.Display in project bndtools by bndtools.

the class JAREntryPart method loadContent.

protected void loadContent() {
    if (displayJob != null && displayJob.getState() != Job.NONE)
        displayJob.cancel();
    if (zipEntry != null && !zipEntry.isDirectory()) {
        IEditorInput input = editor.getEditorInput();
        final Display display = text.getDisplay();
        final URI uri = URIHelper.retrieveFileURI(input);
        if (uri != null) {
            displayJob = new Job("Load zip content") {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    File ioFile = new File(uri);
                    try (ZipFile zipFile = new ZipFile(ioFile)) {
                        final StringWriter writer = new StringWriter();
                        if (showAsText)
                            readAsText(zipFile, zipEntry, charsets[selectedCharset], writer, 1024 * 20, monitor);
                        else
                            readAsHex(zipFile, zipEntry, writer, 1024 * 20, 2, monitor);
                        display.asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                setContent(writer.toString());
                            }
                        });
                        return Status.OK_STATUS;
                    } catch (IOException e) {
                        Status status = new Status(IStatus.ERROR, PluginConstants.PLUGIN_ID, 0, "I/O error reading JAR file contents", e);
                        // ErrorDialog.openError(getManagedForm().getForm().getShell(), "Error", null, status);
                        return status;
                    }
                }
            };
            displayJob.schedule();
        }
    } else {
        setContent("");
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IOException(java.io.IOException) URI(java.net.URI) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ZipFile(java.util.zip.ZipFile) StringWriter(java.io.StringWriter) Job(org.eclipse.core.runtime.jobs.Job) ZipFile(java.util.zip.ZipFile) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput) Display(org.eclipse.swt.widgets.Display)

Aggregations

Display (org.eclipse.swt.widgets.Display)485 Shell (org.eclipse.swt.widgets.Shell)184 Point (org.eclipse.swt.graphics.Point)76 Test (org.junit.Test)63 FillLayout (org.eclipse.swt.layout.FillLayout)62 Color (org.eclipse.swt.graphics.Color)52 Button (org.eclipse.swt.widgets.Button)50 Rectangle (org.eclipse.swt.graphics.Rectangle)48 GridLayout (org.eclipse.swt.layout.GridLayout)43 Composite (org.eclipse.swt.widgets.Composite)43 GridData (org.eclipse.swt.layout.GridData)39 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)32 Image (org.eclipse.swt.graphics.Image)32 Label (org.eclipse.swt.widgets.Label)32 SWT (org.eclipse.swt.SWT)29 InvocationTargetException (java.lang.reflect.InvocationTargetException)28 StyledText (org.eclipse.swt.custom.StyledText)24 Text (org.eclipse.swt.widgets.Text)24 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)23 Font (org.eclipse.swt.graphics.Font)23