Author: snjeza
Date: 2011-09-26 10:17:45 -0400 (Mon, 26 Sep 2011)
New Revision: 35043
Added:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/xpl/TextSearchControl.java
Removed:
trunk/central/plugins/org.jboss.tools.central/icons/Thumbs.db
trunk/central/plugins/org.jboss.tools.central/icons/arrow-left-orange-9x8.gif
trunk/central/plugins/org.jboss.tools.central/icons/jive-icon-accept-16x16.gif
trunk/central/plugins/org.jboss.tools.central/icons/jive-icon-working-16x16.gif
Modified:
trunk/central/plugins/org.jboss.tools.central/META-INF/MANIFEST.MF
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/JBossCentralActivator.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/ShowJBossCentral.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/FavoriteAtEclipseMarketplaceHandler.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/NewProjectExamplesWizardHandler.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/OpenJBossNewsHandler.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/OpenJBossToolsHomeHandler.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/OpenJBossToolsTwitterHandler.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshDiscoveryHandler.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossNewsHandler.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossTutorialsHandler.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossTwitterHandler.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/AbstractJBossCentralPage.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/DescriptionToolTip.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/JBossCentralEditor.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/NewsToolTip.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/RefreshIndicator.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/SoftwarePage.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/xpl/DiscoveryViewer.java
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/xpl/OverviewToolTip.java
Log:
JBIDE-9368 Dashboard(s) for easy news aggregation, twitter and easy additional/3rd party
plugin installation and project template/creation
Modified: trunk/central/plugins/org.jboss.tools.central/META-INF/MANIFEST.MF
===================================================================
--- trunk/central/plugins/org.jboss.tools.central/META-INF/MANIFEST.MF 2011-09-26 14:16:40
UTC (rev 35042)
+++ trunk/central/plugins/org.jboss.tools.central/META-INF/MANIFEST.MF 2011-09-26 14:17:45
UTC (rev 35043)
@@ -22,7 +22,9 @@
org.eclipse.mylyn.discovery.ui;bundle-version="3.6.0",
org.eclipse.mylyn.discovery.core;bundle-version="3.6.0",
org.eclipse.mylyn.commons.ui;bundle-version="3.6.1",
- org.eclipse.equinox.p2.ui.sdk;bundle-version="1.0.200"
+ org.eclipse.equinox.p2.ui.sdk;bundle-version="1.0.200",
+ org.eclipse.equinox.p2.core;bundle-version="2.1.0",
+ org.eclipse.equinox.p2.engine;bundle-version="2.1.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Localization: plugin
Deleted: trunk/central/plugins/org.jboss.tools.central/icons/Thumbs.db
===================================================================
(Binary files differ)
Deleted: trunk/central/plugins/org.jboss.tools.central/icons/arrow-left-orange-9x8.gif
===================================================================
(Binary files differ)
Deleted: trunk/central/plugins/org.jboss.tools.central/icons/jive-icon-accept-16x16.gif
===================================================================
(Binary files differ)
Deleted: trunk/central/plugins/org.jboss.tools.central/icons/jive-icon-working-16x16.gif
===================================================================
(Binary files differ)
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/JBossCentralActivator.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/JBossCentralActivator.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/JBossCentralActivator.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -13,15 +13,11 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
@@ -55,9 +51,9 @@
import org.jboss.tools.central.model.Tutorial;
import org.jboss.tools.central.model.TutorialCategory;
import org.jboss.tools.project.examples.model.Project;
-import org.jboss.tools.runtime.core.model.DownloadRuntime;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
import org.osgi.service.prefs.BackingStoreException;
@@ -96,7 +92,11 @@
public static final String SHOW_JBOSS_CENTRAL_ON_STARTUP =
"showJBossCentralOnStartup";
public static final boolean SHOW_JBOSS_CENTRAL_ON_STARTUP_DEFAULT_VALUE = true;
+
+ public static final String PROFILE_ID = "profileId";
+ public static final String PROFILE_TIMESTAMP = "profileTimestamp";
+
public static final String JBDS_PRODUCT_PLUGIN_ID = "com.jboss.jbds.product";
public static final String NEW_PROJECT_EXAMPLES_WIZARD_ID =
"org.jboss.tools.project.examples.wizard.NewProjectExamplesWizard";
@@ -112,7 +112,15 @@
public static final String TUTORIALS_EXTENSION_ID =
"org.jboss.tools.central.tutorials";
+ public static final String SEARCH_PROJECT_PAGES = "Search Project Pages";
+
+ public static final String SEARCH_THE_COMMUNITY = "Search the Community";
+
+ public static final String SEARCH_COMMUNITY_PORTAL = "Search Community
Portal";
+
public Map<String, TutorialCategory> tutorialCategories;
+
+ private BundleContext bundleContext;
public static final int MAX_FEEDS = 100;
@@ -131,6 +139,7 @@
*/
public void start(BundleContext context) throws Exception {
super.start(context);
+ this.bundleContext = context;
plugin = this;
}
@@ -140,6 +149,7 @@
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
+ bundleContext = null;
tutorialCategories = null;
super.stop(context);
}
@@ -402,5 +412,20 @@
environment.put("org.jboss.tools.central.version.micro", version.getMicro());
//$NON-NLS-1$
return environment;
}
+
+ public Object getService(String name) {
+ if (bundleContext == null)
+ return null;
+ ServiceReference<?> reference = bundleContext.getServiceReference(name);
+ if (reference == null)
+ return null;
+ Object result = bundleContext.getService(reference);
+ bundleContext.ungetService(reference);
+ return result;
+ }
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
}
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/ShowJBossCentral.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/ShowJBossCentral.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/ShowJBossCentral.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -10,6 +10,10 @@
************************************************************************************/
package org.jboss.tools.central;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IStartup;
@@ -23,6 +27,27 @@
@Override
public void earlyStartup() {
boolean showJBossCentral =
JBossCentralActivator.getDefault().showJBossCentralOnStartup();
+ IProvisioningAgent agent = (IProvisioningAgent)
JBossCentralActivator.getDefault().getService(IProvisioningAgent.SERVICE_NAME);
+ IProfileRegistry profileRegistry = (IProfileRegistry)
agent.getService(IProfileRegistry.SERVICE_NAME);
+ if (profileRegistry == null) {
+ showJBossCentral = true;
+ } else {
+ IProfile profile = profileRegistry
+ .getProfile(IProfileRegistry.SELF);
+ String profileId = profile.getProfileId();
+ IEclipsePreferences prefs = JBossCentralActivator.getDefault().getPreferences();
+ String savedId = prefs.get(JBossCentralActivator.PROFILE_ID, null);
+ if (savedId == null || !savedId.equals(profileId)) {
+ prefs.put(JBossCentralActivator.PROFILE_ID, profileId);
+ showJBossCentral = true;
+ }
+ long timestamp = profile.getTimestamp();
+ long savedTimestamp = prefs.getLong(JBossCentralActivator.PROFILE_TIMESTAMP, -1);
+ if (timestamp != savedTimestamp) {
+ prefs.putLong(JBossCentralActivator.PROFILE_TIMESTAMP, timestamp);
+ showJBossCentral = true;
+ }
+ }
if (!showJBossCentral) {
return;
}
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/FavoriteAtEclipseMarketplaceHandler.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/FavoriteAtEclipseMarketplaceHandler.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/FavoriteAtEclipseMarketplaceHandler.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,5 +1,21 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+
package org.jboss.tools.central.actions;
+/**
+ *
+ * @author snjeza
+ *
+ */
public class FavoriteAtEclipseMarketplaceHandler extends OpenWithBrowserHandler {
@Override
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/NewProjectExamplesWizardHandler.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/NewProjectExamplesWizardHandler.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/NewProjectExamplesWizardHandler.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,5 +1,17 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+
package org.jboss.tools.central.actions;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
@@ -18,6 +30,11 @@
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.jboss.tools.central.JBossCentralActivator;
+/**
+ *
+ * @author snjeza
+ *
+ */
public class NewProjectExamplesWizardHandler extends AbstractHandler {
@Override
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/OpenJBossNewsHandler.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/OpenJBossNewsHandler.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/OpenJBossNewsHandler.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,3 +1,14 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+
package org.jboss.tools.central.actions;
import org.jboss.tools.central.JBossCentralActivator;
@@ -2,2 +13,7 @@
+/**
+ *
+ * @author snjeza
+ *
+ */
public class OpenJBossNewsHandler extends OpenWithBrowserHandler {
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/OpenJBossToolsHomeHandler.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/OpenJBossToolsHomeHandler.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/OpenJBossToolsHomeHandler.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,5 +1,21 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+
package org.jboss.tools.central.actions;
+/**
+ *
+ * @author snjeza
+ *
+ */
public class OpenJBossToolsHomeHandler extends OpenWithBrowserHandler {
@Override
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/OpenJBossToolsTwitterHandler.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/OpenJBossToolsTwitterHandler.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/OpenJBossToolsTwitterHandler.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,5 +1,21 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+
package org.jboss.tools.central.actions;
+/**
+ *
+ * @author snjeza
+ *
+ */
public class OpenJBossToolsTwitterHandler extends OpenWithBrowserHandler {
@Override
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshDiscoveryHandler.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshDiscoveryHandler.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshDiscoveryHandler.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,3 +1,14 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+
package org.jboss.tools.central.actions;
import org.eclipse.core.commands.AbstractHandler;
@@ -6,6 +17,11 @@
import org.eclipse.core.runtime.jobs.Job;
import org.jboss.tools.central.jobs.RefreshDiscoveryJob;
+/**
+ *
+ * @author snjeza
+ *
+ */
public class RefreshDiscoveryHandler extends AbstractHandler {
@Override
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossNewsHandler.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossNewsHandler.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossNewsHandler.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,3 +1,14 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+
package org.jboss.tools.central.actions;
import org.eclipse.core.commands.AbstractHandler;
@@ -6,6 +17,11 @@
import org.eclipse.core.runtime.jobs.Job;
import org.jboss.tools.central.jobs.RefreshNewsJob;
+/**
+ *
+ * @author snjeza
+ *
+ */
public class RefreshJBossNewsHandler extends AbstractHandler {
@Override
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossTutorialsHandler.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossTutorialsHandler.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossTutorialsHandler.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,3 +1,14 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+
package org.jboss.tools.central.actions;
import org.eclipse.core.commands.AbstractHandler;
@@ -7,6 +18,11 @@
import org.jboss.tools.central.JBossCentralActivator;
import org.jboss.tools.central.jobs.RefreshTutorialsJob;
+/**
+ *
+ * @author snjeza
+ *
+ */
public class RefreshJBossTutorialsHandler extends AbstractHandler {
@Override
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossTwitterHandler.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossTwitterHandler.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/actions/RefreshJBossTwitterHandler.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,3 +1,14 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+
package org.jboss.tools.central.actions;
import org.eclipse.core.commands.AbstractHandler;
@@ -4,6 +15,11 @@
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+/**
+ *
+ * @author snjeza
+ *
+ */
public class RefreshJBossTwitterHandler extends AbstractHandler {
@Override
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/AbstractJBossCentralPage.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/AbstractJBossCentralPage.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/AbstractJBossCentralPage.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,3 +1,14 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+
package org.jboss.tools.central.editors;
import java.io.IOException;
@@ -2,3 +13,2 @@
-import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
@@ -12,12 +22,16 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.forms.editor.FormPage;
-import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.FormText;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;
import org.jboss.tools.central.JBossCentralActivator;
+/**
+ *
+ * @author snjeza
+ *
+ */
public class AbstractJBossCentralPage extends FormPage {
public static final String ID_PREFIX = "org.jboss.tools.central.editors.";
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/DescriptionToolTip.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/DescriptionToolTip.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/DescriptionToolTip.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,3 +1,13 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
package org.jboss.tools.central.editors;
import org.eclipse.jface.window.ToolTip;
@@ -9,14 +19,17 @@
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Text;
+/**
+ *
+ * @author snjeza
+ *
+ */
public class DescriptionToolTip extends ToolTip {
- private Control control;
private String description;
public DescriptionToolTip(Control control, String description) {
super(control);
- this.control = control;
this.description = description;
setHideOnMouseDown(true);
setPopupDelay(400);
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/GettingStartedPage.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,3 +1,14 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+
package org.jboss.tools.central.editors;
import java.util.ArrayList;
@@ -6,6 +17,7 @@
import java.util.List;
import java.util.Map;
+import org.apache.commons.lang.StringEscapeUtils;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IContributor;
@@ -83,6 +95,11 @@
import org.jboss.tools.project.examples.model.Project;
import org.osgi.framework.Bundle;
+/**
+ *
+ * @author snjeza
+ *
+ */
public class GettingStartedPage extends AbstractJBossCentralPage {
private static final String CLASS_ATTRIBUTE = "class";
@@ -134,8 +151,8 @@
toolkit.paintBordersFor(body);
Composite left = createComposite(toolkit, body);
+ createProjectsSection(toolkit, left);
createTutorialsSection(toolkit, left);
- createProjectsSection(toolkit, left);
createDocumentationSection(toolkit, left);
toolkit.paintBordersFor(left);
@@ -280,7 +297,7 @@
}
private void createTutorialsSection(FormToolkit toolkit, Composite parent) {
- tutorialsSection = createSection(toolkit, parent, "Project Examples",
ExpandableComposite.TITLE_BAR|ExpandableComposite.TWISTIE|ExpandableComposite.EXPANDED);
+ tutorialsSection = createSection(toolkit, parent, "Project Examples",
ExpandableComposite.TITLE_BAR|ExpandableComposite.TWISTIE);
GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
//gd.widthHint = 350;
//gd.heightHint = 100;
@@ -370,7 +387,7 @@
}
public void createProjectsSection(FormToolkit toolkit, Composite parent) {
- projectsSection = createSection(toolkit, parent, "Create Projects",
ExpandableComposite.TITLE_BAR|ExpandableComposite.TWISTIE);
+ projectsSection = createSection(toolkit, parent, "Create Projects",
ExpandableComposite.TITLE_BAR|ExpandableComposite.TWISTIE|ExpandableComposite.EXPANDED);
projectsSection.setText("Create Projects");
projectsSection.setLayout(new GridLayout());
GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
@@ -633,9 +650,10 @@
private void showException(PageBook pageBook, FormText exceptionText, Exception e) {
JBossCentralActivator.log(e);
+ String message = StringEscapeUtils.escapeXml(e.getMessage());
String text = JBossCentralActivator.FORM_START_TAG +
"<img href=\"image\"/> " +
- e.getMessage() +
+ message +
JBossCentralActivator.FORM_END_TAG;
exceptionText.setText(text, true, false);
Image image = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/JBossCentralEditor.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/JBossCentralEditor.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/JBossCentralEditor.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -10,10 +10,19 @@
************************************************************************************/
package org.jboss.tools.central.editors;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
@@ -21,14 +30,19 @@
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.SharedHeaderFormEditor;
+import org.eclipse.ui.forms.widgets.ImageHyperlink;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.menus.CommandContributionItem;
import org.jboss.tools.central.JBossCentralActivator;
+import org.jboss.tools.central.actions.OpenJBossNewsHandler;
+import org.jboss.tools.central.editors.xpl.TextSearchControl;
import org.jboss.tools.central.jobs.RefreshNewsJob;
/**
@@ -38,6 +52,8 @@
*/
public class JBossCentralEditor extends SharedHeaderFormEditor {
+ private static final String UTF_8_ENCODING = "UTF-8";
+
private static final String JBOSS_TOOLS_CENTRAL = "JBoss Tools Central";
public static final String ID =
"org.jboss.tools.central.editors.JBossCentralEditor";
@@ -144,18 +160,11 @@
getToolkit().decorateFormHeading(form.getForm());
Composite headerComposite = getToolkit().createComposite(form.getForm().getHead(),
SWT.NONE);
- headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
+ headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
headerComposite.setLayout(new GridLayout(2, false));
headerComposite.setBackground(null);
Button showOnStartup = getToolkit().createButton(headerComposite, "Show on
Startup", SWT.CHECK);
-
-// Text searchControl = getToolkit().createText(headerComposite, "",
SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL);
-// searchControl.setMessage("Search");
-// GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
-// gd.widthHint = 150;
-// searchControl.setLayoutData(gd);
-
showOnStartup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
showOnStartup.setBackground(null);
showOnStartup.setSelection(JBossCentralActivator.getDefault().showJBossCentralOnStartup());
@@ -170,7 +179,134 @@
}
});
+
+ Composite searchComposite = getToolkit().createComposite(headerComposite);
+ GridData gd = new GridData(SWT.END, SWT.FILL, true, true);
+ gd.widthHint = 200;
+ searchComposite.setLayoutData(gd);
+ searchComposite.setBackground(null);
+ searchComposite.setLayout(new GridLayout(2, false));
+ ImageHyperlink menuLink = getToolkit().createImageHyperlink(searchComposite,
SWT.NONE);
+ gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ menuLink.setLayoutData(gd);
+ menuLink.setBackground(null);
+ menuLink.setImage(CommonImages.getImage(CommonImages.TOOLBAR_ARROW_DOWN));
+ menuLink.setToolTipText("Search Menu");
+ final TextSearchControl searchControl = new TextSearchControl(searchComposite, false);
+ gd = new GridData(SWT.END, SWT.FILL, true, true);
+ gd.widthHint = 200;
+ searchControl.setLayoutData(gd);
+ searchControl.setBackground(null);
+ getToolkit().adapt(searchControl);
+ searchControl.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ if (e.detail == SWT.CANCEL) {
+ searchControl.getTextControl().setText("");
+ searchControl.setInitialMessage(searchControl.getInitialMessage());
+ } else {
+ try {
+ StringBuffer url = new StringBuffer();
+ String initialMessage = searchControl.getInitialMessage();
+ if (JBossCentralActivator.SEARCH_COMMUNITY_PORTAL.equals(initialMessage)) {
+
url.append("https://access.redhat.com/knowledge/searchResults?col=av...;
+ url.append(URLEncoder.encode(searchControl.getText(), UTF_8_ENCODING));
+ } else {
+
url.append("http://community.jboss.org/search.jspa?searchArea=");
+ url.append(URLEncoder.encode(initialMessage, UTF_8_ENCODING));
+ url.append("&as_sitesearch=jboss.org&q=");
+ url.append(URLEncoder.encode(searchControl.getText(), UTF_8_ENCODING));
+ }
+ final String location = url.toString();
+ AbstractHandler handler = new OpenJBossNewsHandler() {
+
+ @Override
+ public String getLocation() {
+ return location;
+ }
+
+ };
+ handler.execute(new ExecutionEvent());
+ } catch (UnsupportedEncodingException e1) {
+ JBossCentralActivator.log(e1);
+ } catch (ExecutionException e1) {
+ JBossCentralActivator.log(e1);
+ }
+ }
+ }
+ });
+
+ final Menu menu = new Menu(menuLink);
+ final MenuItem searchCommunity = new MenuItem(menu, SWT.CHECK);
+ searchCommunity.setText(JBossCentralActivator.SEARCH_THE_COMMUNITY);
+ final MenuItem searchProjectPages = new MenuItem(menu, SWT.CHECK);
+ searchProjectPages.setText(JBossCentralActivator.SEARCH_PROJECT_PAGES);
+ final MenuItem searchCommunityPortal = new MenuItem(menu, SWT.CHECK);
+ searchCommunityPortal.setText(JBossCentralActivator.SEARCH_COMMUNITY_PORTAL);
+
+ String initialMessage = searchControl.getInitialMessage();
+ if (JBossCentralActivator.SEARCH_COMMUNITY_PORTAL.equals(initialMessage)) {
+ searchCommunityPortal.setSelection(true);
+ } else if (JBossCentralActivator.SEARCH_PROJECT_PAGES.equals(initialMessage)) {
+ searchProjectPages.setSelection(true);
+ } else {
+ searchCommunity.setSelection(true);
+ }
+ searchCommunity.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ searchCommunity.setSelection(true);
+ searchProjectPages.setSelection(false);
+ searchCommunityPortal.setSelection(false);
+ searchControl.setInitialMessage(JBossCentralActivator.SEARCH_THE_COMMUNITY);
+ }
+
+ });
+ searchProjectPages.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ searchProjectPages.setSelection(true);
+ searchCommunity.setSelection(false);
+ searchCommunityPortal.setSelection(false);
+ searchControl.setInitialMessage(JBossCentralActivator.SEARCH_PROJECT_PAGES);
+ }
+
+ });
+
+ searchCommunityPortal.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ searchProjectPages.setSelection(false);
+ searchCommunity.setSelection(false);
+ searchCommunityPortal.setSelection(true);
+ searchControl.setInitialMessage(JBossCentralActivator.SEARCH_COMMUNITY_PORTAL);
+ }
+
+ });
+
+ menuLink.addMouseListener(new MouseListener() {
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ menu.setVisible(false);
+ }
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ menu.setVisible(true);
+ }
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+
+ }
+ });
+
form.getForm().setHeadClient(headerComposite);
IToolBarManager toolbar = form.getToolBarManager();
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/NewsToolTip.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/NewsToolTip.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/NewsToolTip.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,3 +1,14 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+
package org.jboss.tools.central.editors;
import org.eclipse.jface.window.ToolTip;
@@ -23,6 +34,11 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.widgets.FormText;
+/**
+ *
+ * @author snjeza
+ *
+ */
public class NewsToolTip extends ToolTip {
private String toolText;
@@ -90,7 +106,7 @@
"h1, h2, h3, h4, h5, h6 { font-size: 14px;font-weight:bold;font-family: Arial,
Helvetica, sans-serif; }" +
"</style>" +
"</head>" +
- "<body" +
+ "<body>" +
toolText +
"</body>" +
"</html>";
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/RefreshIndicator.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/RefreshIndicator.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/RefreshIndicator.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,6 +1,16 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
+
package org.jboss.tools.central.editors;
-import java.awt.image.ImageProducer;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -18,6 +28,12 @@
import org.eclipse.swt.widgets.Display;
import org.jboss.tools.central.JBossCentralActivator;
import org.osgi.framework.Bundle;
+
+/**
+ *
+ * @author snjeza
+ *
+ */
public class RefreshIndicator extends Canvas {
protected Image[] images;
protected Image image;
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/SoftwarePage.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/SoftwarePage.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/SoftwarePage.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,3 +1,13 @@
+/*************************************************************************************
+ * Copyright (c) 2008-2011 Red Hat, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * JBoss by Red Hat - Initial implementation.
+ ************************************************************************************/
package org.jboss.tools.central.editors;
import java.lang.reflect.InvocationTargetException;
@@ -2,6 +12,4 @@
import java.util.Dictionary;
-import java.util.Hashtable;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
@@ -43,9 +51,12 @@
import org.jboss.tools.central.JBossCentralActivator;
import org.jboss.tools.central.editors.xpl.DiscoveryViewer;
import org.jboss.tools.central.jobs.RefreshDiscoveryJob;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Version;
+/**
+ *
+ * @author snjeza
+ *
+ */
public class SoftwarePage extends AbstractJBossCentralPage implements IRunnableContext {
public static final String ID = ID_PREFIX + "SoftwarePage";
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/xpl/DiscoveryViewer.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/xpl/DiscoveryViewer.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/xpl/DiscoveryViewer.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementationO
+ *******************************************************************************/
package org.jboss.tools.central.editors.xpl;
import java.beans.PropertyChangeEvent;
Modified:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/xpl/OverviewToolTip.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/xpl/OverviewToolTip.java 2011-09-26
14:16:40 UTC (rev 35042)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/xpl/OverviewToolTip.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
package org.jboss.tools.central.editors.xpl;
import java.net.URL;
Added:
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/xpl/TextSearchControl.java
===================================================================
---
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/xpl/TextSearchControl.java
(rev 0)
+++
trunk/central/plugins/org.jboss.tools.central/src/org/jboss/tools/central/editors/xpl/TextSearchControl.java 2011-09-26
14:17:45 UTC (rev 35043)
@@ -0,0 +1,563 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ *
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ * JBoss by Red Hat
+ *******************************************************************************/
+package org.jboss.tools.central.editors.xpl;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.jface.bindings.keys.KeyStroke;
+import org.eclipse.jface.bindings.keys.ParseException;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.fieldassist.ContentProposal;
+import org.eclipse.jface.fieldassist.ContentProposalAdapter;
+import org.eclipse.jface.fieldassist.ControlDecoration;
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.fieldassist.IContentProposal;
+import org.eclipse.jface.fieldassist.IContentProposalProvider;
+import org.eclipse.jface.fieldassist.TextContentAdapter;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.mylyn.internal.commons.ui.CommonsUiPlugin;
+import org.eclipse.mylyn.internal.provisional.commons.ui.Messages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.accessibility.ACC;
+import org.eclipse.swt.accessibility.AccessibleAdapter;
+import org.eclipse.swt.accessibility.AccessibleControlAdapter;
+import org.eclipse.swt.accessibility.AccessibleControlEvent;
+import org.eclipse.swt.accessibility.AccessibleEvent;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseMoveListener;
+import org.eclipse.swt.events.MouseTrackListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.events.TraverseListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.WorkbenchMessages;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.jboss.tools.central.JBossCentralActivator;
+
+/**
+ * @author Shawn Minto
+ * @author snjeza
+ */
+public class TextSearchControl extends Composite {
+
+ private static final int MAX_PROPOSAL_ITEMS = 50;
+
+ /**
+ * Image descriptor for enabled clear button.
+ */
+ private static final String CLEAR_ICON =
"org.eclipse.ui.internal.dialogs.CLEAR_ICON"; //$NON-NLS-1$
+
+ /**
+ * Image descriptor for enabled clear button.
+ */
+ private static final String FIND_ICON =
"org.eclipse.ui.internal.dialogs.FIND_ICON"; //$NON-NLS-1$
+
+ private static final String SEARCH_SECTION = "searchSection";
+
+ private static final String SEARCH_KEY = "searchKey";
+
+ /* SWT STYLE BIT AVAILABLE ON 3.5 AND HIGHER */
+ public static final int ICON_SEARCH = 1 << 9;
+
+ /* SWT STYLE BIT AVAILABLE ON 3.5 AND HIGHER */
+ public static final int ICON_CANCEL = 1 << 8;
+
+ private static final String INITIAL_MESSAGE = "initialMessage";
+
+ /**
+ * Get image descriptors for the clear button.
+ */
+ static {
+ ImageDescriptor descriptor =
AbstractUIPlugin.imageDescriptorFromPlugin(PlatformUI.PLUGIN_ID,
+ "$nl$/icons/full/etool16/clear_co.gif"); //$NON-NLS-1$
+ if (descriptor != null) {
+ JFaceResources.getImageRegistry().put(CLEAR_ICON, descriptor);
+ }
+
+ descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(CommonsUiPlugin.ID_PLUGIN,
+ "$nl$/icons/etool16/find.png"); //$NON-NLS-1$
+ if (descriptor != null) {
+ JFaceResources.getImageRegistry().put(FIND_ICON, descriptor);
+ }
+ }
+
+ private Text textControl;
+
+ private Control clearControl;
+
+ private Control findControl;
+
+ private final Set<SelectionListener> selectionListeners = new
HashSet<SelectionListener>();
+
+ private static Boolean useNativeSearchField;
+
+ private String initialMessage;
+
+ private String[] proposals;
+
+ @SuppressWarnings("restriction")
+ public TextSearchControl(Composite parent, boolean automaticFind) {
+ super(parent, getCompositeStyle(automaticFind, parent));
+
+ int textStyle = SWT.SINGLE;
+ int numColumns = 1;
+ if (useNativeSearchField(automaticFind, parent)) {
+ if (automaticFind) {
+ textStyle |= SWT.SEARCH | ICON_CANCEL;
+ } else {
+ textStyle |= SWT.SEARCH | ICON_SEARCH | ICON_CANCEL;
+ }
+ } else {
+ super.setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+ super.setFont(parent.getFont());
+ numColumns = 2;
+ if (!automaticFind) {
+ numColumns += 1;
+ }
+ }
+ GridLayoutFactory.swtDefaults()
+ .margins(0, 0)
+ .extendedMargins(0, 0, 0, 0)
+ .spacing(0, 1)
+ .numColumns(numColumns)
+ .applyTo(this);
+
+
+ textControl = new Text(this, textStyle);
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+
+ textControl.setLayoutData(gridData);
+
+ KeyStroke stroke;
+ String proposalKey = null;
+ try {
+ stroke = KeyStroke.getInstance("M1+SPACE"); //$NON-NLS-1$
+ proposalKey = stroke.format();
+ } catch (ParseException e1) {
+ JBossCentralActivator.log(e1);
+ }
+ stroke = null;
+ final ControlDecoration dec = new ControlDecoration(textControl, SWT.TOP
+ | SWT.LEFT);
+ FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();
+ FieldDecoration fd =
registry.getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
+ dec.setImage(fd.getImage());
+ String description;
+ if (proposalKey == null) {
+ description = fd.getDescription();
+ } else {
+ description = fd.getDescription() + "(" + proposalKey + ")";
+ }
+ dec.setDescriptionText(description);
+
+ dec.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(
+ FieldDecorationRegistry.DEC_CONTENT_PROPOSAL).getImage());
+
+ dec.setShowOnlyOnFocus(true);
+ dec.setShowHover(true);
+
+ ContentProposalAdapter adapter = new ContentProposalAdapter(textControl,
+ new TextContentAdapter(),
+ new SearchContentProposalProvider(),
+ null,
+ null);
+ adapter.setPropagateKeys(true);
+ adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
+
+ if (useNativeSearchField == null || !useNativeSearchField) {
+ findControl = createLabelButtonControl(this,
+ JFaceResources.getImageRegistry().getDescriptor(FIND_ICON),
+ Messages.TextControl_AccessibleListenerFindButton, Messages.TextControl_FindToolTip,
ICON_SEARCH);
+ Point size = findControl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ GridData data = (GridData) textControl.getLayoutData();
+ data.heightHint = size.y;
+ clearControl = createLabelButtonControl(this,
+ JFaceResources.getImageRegistry().getDescriptor(CLEAR_ICON),
+ WorkbenchMessages.FilteredTree_ClearToolTip,//FilteredTree_AccessibleListenerClearButton,
+ WorkbenchMessages.FilteredTree_ClearToolTip, ICON_CANCEL);
+ addModifyListener(new ModifyListener() {
+
+ public void modifyText(ModifyEvent e) {
+ updateButtonVisibilityAndEnablement();
+
+ }
+ });
+ updateButtonVisibilityAndEnablement();
+ }
+
+ IDialogSettings section = getSearchSettings();
+ proposals = section.getArray(SEARCH_KEY);
+ if (proposals == null) {
+ proposals = new String[0];
+ section.put(SEARCH_KEY, proposals);
+ }
+ String message = section.get(INITIAL_MESSAGE);
+ if (message == null || message.isEmpty()) {
+ message = JBossCentralActivator.SEARCH_THE_COMMUNITY;
+ }
+ setInitialMessage(message);
+
+ registerListeners();
+ }
+
+
+ private void registerListeners() {
+ addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ if (textControl != null && !textControl.isDisposed()) {
+ addSearchSettings();
+ }
+
+ }
+ });
+ textControl.addFocusListener(new FocusAdapter() {
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ if (textControl != null && !textControl.isDisposed()) {
+ // addSearchSettings();
+ if (textControl.getText().isEmpty()) {
+ setInitialMessage(initialMessage);
+ }
+ updateButtonVisibilityAndEnablement();
+ }
+ }
+
+ });
+ }
+
+ private static int getCompositeStyle(boolean automaticFind, Composite parent) {
+ if (useNativeSearchField(automaticFind, parent)) {
+ return SWT.NONE;
+ }
+ return SWT.BORDER;
+ }
+
+ private static boolean useNativeSearchField(boolean automaticFind, Composite parent) {
+ if (parent != null) {
+ if (useNativeSearchField == null) {
+ useNativeSearchField = Boolean.FALSE;
+ Text testText = null;
+ try {
+ int style = SWT.SEARCH | ICON_CANCEL;
+ if (automaticFind) {
+ style |= ICON_SEARCH;
+ }
+ testText = new Text(parent, style);
+ useNativeSearchField = new Boolean((testText.getStyle() & ICON_CANCEL) != 0
+ && (!automaticFind || (testText.getStyle() & ICON_SEARCH) != 0));
+ } finally {
+ if (testText != null) {
+ testText.dispose();
+ }
+ }
+
+ }
+ } else {
+ useNativeSearchField = Boolean.FALSE;
+ }
+ return useNativeSearchField.booleanValue();
+ }
+
+ private Control createLabelButtonControl(Composite parent,
+ ImageDescriptor activeImageDescriptor, final String accessibilityText, String
toolTipText, final int detail) {
+
+ final Image nativeImage = parent.getDisplay().getSystemImage(detail);
+
+ final Image activeImage = nativeImage != null ? nativeImage :
activeImageDescriptor.createImage();
+ final Image inactiveImage = new Image(parent.getDisplay(), activeImage,
SWT.IMAGE_GRAY);
+ final Image pressedImage = inactiveImage;
+
+ final Label labelButton = new Label(parent, SWT.NONE);
+ labelButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
+ labelButton.setImage(inactiveImage);
+ labelButton.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+ labelButton.setToolTipText(toolTipText);
+ labelButton.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ if (nativeImage == null && activeImage != null &&
!activeImage.isDisposed()) {
+ activeImage.dispose();
+ }
+ if (inactiveImage != null && !inactiveImage.isDisposed()) {
+ inactiveImage.dispose();
+ }
+ if (pressedImage != null && !pressedImage.isDisposed()) {
+ pressedImage.dispose();
+ }
+ }
+ });
+ labelButton.addMouseListener(new MouseAdapter() {
+ private MouseMoveListener fMoveListener;
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ labelButton.setImage(pressedImage);
+ fMoveListener = new MouseMoveListener() {
+ private boolean fMouseInButton = true;
+
+ public void mouseMove(MouseEvent e) {
+ boolean mouseInButton = isMouseInButton(e);
+ if (mouseInButton != fMouseInButton) {
+ fMouseInButton = mouseInButton;
+ labelButton.setImage(mouseInButton ? pressedImage : inactiveImage);
+ }
+ }
+ };
+ labelButton.addMouseMoveListener(fMoveListener);
+ }
+
+ @Override
+ public void mouseUp(MouseEvent e) {
+ if (fMoveListener != null) {
+ labelButton.removeMouseMoveListener(fMoveListener);
+ fMoveListener = null;
+ boolean mouseInButton = isMouseInButton(e);
+ labelButton.setImage(mouseInButton ? activeImage : inactiveImage);
+ if (mouseInButton) {
+ if (textControl != null && textControl.isEnabled() &&
textControl.getText().length() > 0) {
+ notifySelectionChanged(detail);
+ }
+ }
+ }
+ }
+
+ private boolean isMouseInButton(MouseEvent e) {
+ Point buttonSize = labelButton.getSize();
+ return 0 <= e.x && e.x < buttonSize.x && 0 <= e.y &&
e.y < buttonSize.y;
+ }
+ });
+
+ labelButton.addMouseTrackListener(new MouseTrackListener() {
+ public void mouseEnter(MouseEvent e) {
+ if (labelButton.getImage() != activeImage) {
+ labelButton.setImage(activeImage);
+ }
+ }
+
+ public void mouseExit(MouseEvent e) {
+ if (labelButton.getImage() != inactiveImage) {
+ labelButton.setImage(inactiveImage);
+ }
+ }
+
+ public void mouseHover(MouseEvent e) {
+ }
+ });
+
+ labelButton.getAccessible().addAccessibleListener(new AccessibleAdapter() {
+ @Override
+ public void getName(AccessibleEvent e) {
+ e.result = accessibilityText;
+ }
+ });
+ labelButton.getAccessible().addAccessibleControlListener(new AccessibleControlAdapter()
{
+ @Override
+ public void getRole(AccessibleControlEvent e) {
+ e.detail = ACC.ROLE_PUSHBUTTON;
+ }
+ });
+ return labelButton;
+ }
+
+ @Override
+ public void addTraverseListener(TraverseListener listener) {
+ textControl.addTraverseListener(listener);
+ }
+
+ @Override
+ public void removeTraverseListener(TraverseListener listener) {
+ textControl.removeTraverseListener(listener);
+ }
+
+ public void addSelectionListener(SelectionListener listener) {
+ textControl.addSelectionListener(listener);
+ selectionListeners.add(listener);
+ }
+
+ public void removeSelectionListener(SelectionListener listener) {
+ textControl.removeSelectionListener(listener);
+ selectionListeners.remove(listener);
+ }
+
+ public void addModifyListener(ModifyListener listener) {
+ textControl.addModifyListener(listener);
+ }
+
+ public void removeModifyListener(ModifyListener listener) {
+ textControl.removeModifyListener(listener);
+ }
+
+ private void notifySelectionChanged(int detail) {
+ if (useNativeSearchField != null && useNativeSearchField) {
+ // notification should happen via the widgets selection listener
+ return;
+ }
+ Event event = new Event();
+ event.detail = detail;
+ event.widget = textControl;
+ event.display = textControl.getDisplay();
+
+ SelectionEvent e = new SelectionEvent(event);
+ for (Object element : selectionListeners) {
+ ((SelectionListener) element).widgetDefaultSelected(e);
+ }
+ }
+
+ private void updateButtonVisibilityAndEnablement() {
+ if (textControl != null && !textControl.isDisposed()) {
+ boolean hasText = textControl.getText().length() > 0;
+
+ //setFindButtonVisibility(!(hasText && automaticFind));
+ setFindButtonVisibility(hasText);
+ setClearButtonVisibility(hasText);
+ }
+ }
+
+ private void setFindButtonVisibility(boolean visible) {
+ if (findControl != null && !findControl.isDisposed()) {
+ findControl.setVisible(visible);
+ if (findControl.getLayoutData() instanceof GridData) {
+ ((GridData) findControl.getLayoutData()).exclude = !visible;
+ findControl.getParent().layout();
+ }
+ }
+ }
+
+ private void setClearButtonVisibility(boolean visible) {
+ if (clearControl != null && !clearControl.isDisposed()) {
+ clearControl.setVisible(visible);
+ if (clearControl.getLayoutData() instanceof GridData) {
+ ((GridData) clearControl.getLayoutData()).exclude = !visible;
+ clearControl.getParent().layout();
+ }
+ }
+ }
+
+ public Text getTextControl() {
+ return textControl;
+ }
+
+ public String getText() {
+ if (textControl != null && !textControl.isDisposed()) {
+ return textControl.getText();
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ public void setText(String text) {
+ if (textControl != null && !textControl.isDisposed()) {
+ textControl.setText(text);
+ }
+ }
+
+ @Override
+ public void setBackground(Color color) {
+ if (useNativeSearchField != null && useNativeSearchField) {
+ super.setBackground(color);
+ }
+ }
+
+ public String getInitialMessage() {
+ return initialMessage;
+ }
+
+ public void setInitialMessage(String initialMessage) {
+ this.initialMessage = initialMessage;
+ if (textControl != null && !textControl.isDisposed()
+ && textControl.getText().isEmpty()) {
+ textControl.setMessage(initialMessage);
+ IDialogSettings section = getSearchSettings();
+ section.put(INITIAL_MESSAGE, initialMessage);
+ }
+ }
+
+ private IDialogSettings getSearchSettings() {
+ IDialogSettings settings = JBossCentralActivator.getDefault().getDialogSettings();
+ IDialogSettings section = settings.getSection(SEARCH_SECTION);
+ if (section == null) {
+ section = settings.addNewSection(SEARCH_SECTION);
+ }
+ return section;
+ }
+
+ private void addSearchSettings() {
+ String text = textControl.getText().trim();
+ if (!text.isEmpty()) {
+ boolean found = false;
+ for (String proposal:proposals) {
+ if (text.equals(proposal)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ int length = proposals.length;
+ if (length > MAX_PROPOSAL_ITEMS) {
+ length = MAX_PROPOSAL_ITEMS;
+ }
+ String[] newProposals = new String[length + 1];
+ System.arraycopy(proposals, 0, newProposals, 1, length);
+ newProposals[0] = text;
+ proposals = newProposals;
+ IDialogSettings section = getSearchSettings();
+ section.put(SEARCH_KEY, proposals);
+ }
+ }
+ }
+
+ private class SearchContentProposalProvider implements IContentProposalProvider {
+
+ @Override
+ public IContentProposal[] getProposals(String contents, int position) {
+ if (contents != null) {
+ if (position > 0) {
+ contents = contents.substring(0, position);
+ }
+ contents = contents.trim();
+ }
+ List<IContentProposal> contentProposals = new
ArrayList<IContentProposal>();
+ for (String proposal:proposals) {
+ if (proposal != null && proposal.startsWith(contents)) {
+ contentProposals.add(new ContentProposal(proposal));
+ }
+ }
+ return contentProposals.toArray(new IContentProposal[0]);
+ }
+
+ }
+
+}