From: Gun Kim Date: Thu, 1 Nov 2012 11:00:03 +0000 (+0900) Subject: [Title] add "Tizen","RDS" properties page & add delta detector. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=47ed17bd62a4461e511c9f510f0d14b47f3ada75;p=sdk%2Fide%2Fcommon-eplugin.git [Title] add "Tizen","RDS" properties page & add delta detector. [Type] [Module] [Priority] [Jira#] [Redmine#] [Problem] [Cause] [Solution] [TestCase] Change-Id: Ib0c31c205d7eb6f445d4556e4f6cea82ddde408e --- diff --git a/org.tizen.common/META-INF/MANIFEST.MF b/org.tizen.common/META-INF/MANIFEST.MF index d0daed3..9378167 100755 --- a/org.tizen.common/META-INF/MANIFEST.MF +++ b/org.tizen.common/META-INF/MANIFEST.MF @@ -178,6 +178,8 @@ Export-Package: org.tizen.common.daemon, org.tizen.common.file, org.tizen.common.file.filter, + org.tizen.common.rds, + org.tizen.common.rds.ui.preference, org.tizen.common.ui, org.tizen.common.ui.dialog, org.tizen.common.ui.page.preference, diff --git a/org.tizen.common/OSGI-INF/l10n/bundle.properties b/org.tizen.common/OSGI-INF/l10n/bundle.properties index e46bea9..f00fffc 100644 --- a/org.tizen.common/OSGI-INF/l10n/bundle.properties +++ b/org.tizen.common/OSGI-INF/l10n/bundle.properties @@ -1,10 +1,11 @@ +Bundle-Name = Tizen SDK Common Tools Bundle-Vendor = Tizen SDK activity.name = newXsdDisabler activity.name.0 = newDtdDisabler activity.name.1 = ValidateMenuItemDisabler -category.name = Tizen +name = Tizen page.name = Tizen SDK activity.description = Popup UI activity.name.2 = Popup UI @@ -20,7 +21,5 @@ activity.description.2 = Wizard UI activity.name.5 = Wizard UI activity.description.3 = PopupMenus activity.name.6 = PopupMenus -category.name.2 = Tizen -category.name.3 = Tizen extension-point.name = Prompter -Bundle-Name = Tizen SDK Common Tools \ No newline at end of file +RDS.name=Rapid Development Support \ No newline at end of file diff --git a/org.tizen.common/plugin.xml b/org.tizen.common/plugin.xml index 1deb66b..f3de96c 100644 --- a/org.tizen.common/plugin.xml +++ b/org.tizen.common/plugin.xml @@ -21,7 +21,7 @@ point="org.eclipse.ui.newWizards"> + name="%name"> + + @@ -348,15 +354,29 @@ point="org.eclipse.ui.importWizards"> + name="%name"> + name="%name"> + + + + + + diff --git a/org.tizen.common/src/org/tizen/common/CommonPlugin.java b/org.tizen.common/src/org/tizen/common/CommonPlugin.java index f545edb..72a6718 100755 --- a/org.tizen.common/src/org/tizen/common/CommonPlugin.java +++ b/org.tizen.common/src/org/tizen/common/CommonPlugin.java @@ -35,6 +35,7 @@ import org.tizen.common.core.command.Executor; import org.tizen.common.core.command.Prompter; import org.tizen.common.core.command.prompter.EclipsePrompter; import org.tizen.common.core.command.prompter.SWTPrompter; +import org.tizen.common.rds.ui.preference.RdsPreferencePage; import org.tizen.common.ui.page.preference.TizenBasePreferencePage; import org.tizen.common.util.DialogUtil; import org.tizen.common.util.HostUtil; @@ -135,6 +136,9 @@ public class CommonPlugin extends AbstractUIPlugin { store.setDefault(TizenBasePreferencePage.KEY_SDKLOCATION, InstallPathConfig.getSDKPath()); } store.setDefault(TizenBasePreferencePage.KEY_SDKUPDATE, TizenBasePreferencePage.VALUE_SDKUPDATE_DEFAULT); + + // RDS settings + store.setDefault(RdsPreferencePage.RDS_OPTION_ID, RdsPreferencePage.RDS_MODE_DEFAULT); } /** diff --git a/org.tizen.common/src/org/tizen/common/TizenPlatformConstants.java b/org.tizen.common/src/org/tizen/common/TizenPlatformConstants.java index ffb5271..8ebddae 100644 --- a/org.tizen.common/src/org/tizen/common/TizenPlatformConstants.java +++ b/org.tizen.common/src/org/tizen/common/TizenPlatformConstants.java @@ -60,9 +60,13 @@ public class TizenPlatformConstants { // Definitions for installing public static final String APP_INSTALL_PATH = "/opt/apps"; public static final String TEMPORARY_PKG_PATH = "/opt/apps/PKGS/"; - public static final String PKG_TOOL_LIST_COMMAND = "pkgcmd -l | grep %s"; - public static final String PKG_TOOL_REMOVE_COMMAND = "pkgcmd -q -u -t %s -n %s"; - public static final String PKG_TOOL_INSTALL_COMMAND = "pkgcmd -q -i -t %s -p %s"; + public static final String PKG_TOOL = "pkgcmd"; + public static final String PKG_TOOL_LIST_COMMAND = PKG_TOOL + " -l | grep %s"; + public static final String PKG_TOOL_REMOVE_COMMAND = PKG_TOOL + " -q -u -t %s -n %s"; + public static final String PKG_TOOL_INSTALL_COMMAND = PKG_TOOL + " -q -i -t %s -p %s"; + public static final String PKG_TOOL_RUNNING_CHECK_COMMAND = PKG_TOOL + " -C -t %s -n %s"; + public static final String PKG_TOOL_TERMINATE_COMMAND = PKG_TOOL + " -k -t %s -n%s"; + public static final String PKG_TOOL_INSTALL_PATH_COMMAND = PKG_TOOL + " -a"; // Definitions for launching public static final String LAUNCH_CMD = "launch_app %s"; @@ -79,4 +83,6 @@ public class TizenPlatformConstants { public static final String CODE_COVERAGE_LAUNCH_OPTION = " __AUL_SDK__ CODE_COVERAGE"; public static final String PROCESS_GET_PROCESS_ID_COMMAND = "ps -ef | grep '%s' | grep -v grep | awk '{print $2}'"; public static final String PROCESS_SIGKILL_COMMAND = "kill -9 %s"; + public static final String PKG_TOOL_RUNNUNG_CHECK_COMMAND_RUNNING= "is Running"; + public static final String PKG_TOOL_INSTALL_PATH_COMMAND_RESULT = "Tizen Application Installation Path:"; } diff --git a/org.tizen.common/src/org/tizen/common/rds/DeltaResourceInfo.java b/org.tizen.common/src/org/tizen/common/rds/DeltaResourceInfo.java new file mode 100644 index 0000000..8035b2b --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/rds/DeltaResourceInfo.java @@ -0,0 +1,115 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim +* Gun Kim +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.rds; + +/** + * Information of delta. + * @author Gun Kim + * + */ +public class DeltaResourceInfo { + /** + * Type constant which identifies modified status resources. + */ + public final static String TYPE_MODIFY = "modify"; + /** + * Type constant which identifies deleted status resources. + */ + public final static String TYPE_DELETE = "delete"; + /** + * Type constant which identifies installed status resources. + */ + public final static String TYPE_INSTALL = "install"; + private String name; + private String type; + private String fullPath; + private String remotePath; + + public DeltaResourceInfo(String name, String fullPath, String type) { + this.name = name; + this.fullPath = fullPath; + this.remotePath = null; + this.type = type; + } + + public DeltaResourceInfo(String name, String fullPath, String remotePath, String type) { + this.name = name; + this.fullPath = fullPath; + this.remotePath = remotePath; + this.type = type; + } + public DeltaResourceInfo(String fullPath, String remotePath) { + this.fullPath = fullPath; + this.remotePath = remotePath; + } + + /** + * Returns name of resource. + * + * @return String + */ + public String getName() { + return name; + } + /** + * Returns status of resource. + * + * @return String + */ + public String getType() { + return type; + } + /** + * Returns absolute path of resource. + * + * @return String + */ + public String getFullPath() { + return fullPath; + } + /** + * Sets the path which is installed on target. + * + * @param path installed on target + * @return String + */ + public void setRemotePath(String path) { + this.remotePath = path; + } + /** + * Returns the path which is installed on target. + * + * @return String + */ + public String getRemotePath() { + return remotePath; + } + + @Override + public String toString() { + return name; + } +} diff --git a/org.tizen.common/src/org/tizen/common/rds/RdsDeltaDetector.java b/org.tizen.common/src/org/tizen/common/rds/RdsDeltaDetector.java new file mode 100644 index 0000000..90dd759 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/rds/RdsDeltaDetector.java @@ -0,0 +1,236 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim +* Gun Kim +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.rds; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.internal.dtree.AbstractDataTreeNode; +import org.eclipse.core.internal.dtree.DataDeltaNode; +import org.eclipse.core.internal.dtree.DataTreeNode; +import org.eclipse.core.internal.dtree.DeletedNode; +import org.eclipse.core.internal.dtree.DeltaDataTree; +import org.eclipse.core.internal.dtree.NoDataDeltaNode; +import org.eclipse.core.internal.events.ResourceComparator; +import org.eclipse.core.internal.localstore.SafeFileInputStream; +import org.eclipse.core.internal.localstore.SafeFileOutputStream; +import org.eclipse.core.internal.resources.Workspace; +import org.eclipse.core.internal.watson.ElementTree; +import org.eclipse.core.internal.watson.ElementTreeReader; +import org.eclipse.core.internal.watson.ElementTreeWriter; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.tizen.common.util.IOUtil; +import org.tizen.sdblib.IDevice; +import org.tizen.sdblib.SyncService; + +/** + * Delta Detector for Rapid Development Support. + * + * @author Gun Kim + */ +@SuppressWarnings("restriction") +public class RdsDeltaDetector { + ElementTree oldTree; + IDevice device; + IProject project; + String remotePath; + String strResInfoFile = ""; + public final static String STR_TREE_FILE = ".sdk_delta.info"; + public final static String STR_TREE_DIRECTORY = "/info/"; + private static final int TREE_BUFFER_SIZE = 1024 * 64;//64KB buffer + List deltaFilterDataList; + + public RdsDeltaDetector( IDevice device, IProject project, String remotePath ) { + this.device = device; + this.project = project; + this.remotePath = remotePath; + } + + /** + * Reads the STR_TREE_FILE, and sets the oldTree. + */ + public void readOldTree() { + downloadOldTree(); + Workspace workspace = ((Workspace)project.getWorkspace()); + ElementTreeReader treeReader = new ElementTreeReader(workspace.getSaveManager()); + + String strLocalFile = project.getLocation().toString() + "/" + STR_TREE_FILE; + + DataInputStream input = null; + try { + input = new DataInputStream(new SafeFileInputStream(strLocalFile, strLocalFile + ".temp", TREE_BUFFER_SIZE)); + oldTree = treeReader.readTree(input); + } catch (IOException e) { + } finally { + IOUtil.tryClose(input); + } + } + + /** + * Returns whether oldTree is null. + * Returns false if oldTree is null. + * + * @return boolean + */ + public boolean hasOldTree() { + if ( oldTree == null ) { + return false; + } + return true; + } + + /** + * Downloads the STR_TREE_FILE which is installed on target. + * And returns the file path. + * + * @return String + */ + private String downloadOldTree( ) { + String strLocalFile = null; + + if ( remotePath == null ) { + return null; + } + + remotePath += STR_TREE_DIRECTORY + STR_TREE_FILE; + strLocalFile = project.getLocation().toString() + "/" + STR_TREE_FILE; + try { + device.getSyncService().pullFile(remotePath, strLocalFile, true, SyncService.getNullProgressMonitor()); + } catch (Exception e) { + return null; + } + + return strLocalFile; + } + + /** + * Returns the delta between oldTree and tree. + * If the tree is null, tree is IWorkspace.getElementTree(). + * + * @param current tree. + * @param The path of the new subtree in this tree. + * @return List + */ + public List getDelta(ElementTree tree, IPath subTreePath) { + if ( oldTree == null) { + return null; + } + if ( subTreePath == null ) { + subTreePath = project.getFullPath(); + } + + if ( tree == null) { + tree = ((Workspace)project.getWorkspace()).getElementTree().getSubtree(subTreePath); + } + else { + tree = tree.getSubtree(subTreePath); + } + + DeltaDataTree currentDelta = oldTree.getDataTree().forwardDeltaWith(tree.getDataTree(), ResourceComparator.getBuildComparator()); + String workspacePath = ((Workspace)project.getWorkspace()).getRoot().getLocation().toString(); + return getDelta(new ArrayList(), currentDelta.findNodeAt(subTreePath), workspacePath + subTreePath.toString()); + } + + /** + * Returns List assembled with the given deltaNode and strPath. + * + * @param current tree. + * @param the delta tree. + * @param prefix name of elements. + * @return List + */ + public List getDelta(List deltaInfoList, AbstractDataTreeNode deltaNode, String strPath) { + if ( deltaNode == null ) { + return deltaInfoList; + } + for( AbstractDataTreeNode node : deltaNode.getChildren() ) { + if ( node instanceof DeletedNode) { + deltaInfoList.add(new DeltaResourceInfo(node.getName(), strPath + "/" + node.getName(), DeltaResourceInfo.TYPE_DELETE)); + continue; + } + else if ( node instanceof DataDeltaNode ) { + if ( node.getChildren().length == 0 ) { + deltaInfoList.add(new DeltaResourceInfo(node.getName(), strPath + "/" + node.getName(), DeltaResourceInfo.TYPE_MODIFY)); + continue; + } + else { + getDelta(deltaInfoList, node, strPath + "/" + node.getName()); + } + } + else if ( node instanceof DataTreeNode ) { + if ( node.getChildren().length == 0 ) { + deltaInfoList.add(new DeltaResourceInfo(node.getName(), strPath + "/" + node.getName(), DeltaResourceInfo.TYPE_MODIFY)); + continue; + } + else { + getDelta(deltaInfoList, node, strPath + "/" + node.getName()); + } + } + else if ( node instanceof NoDataDeltaNode) { + getDelta(deltaInfoList, node, strPath + "/" + node.getName()); + } + } + + return deltaInfoList; + } + + /** + * Makes the STR_TREE_FILE file. + * + * @param The tree to be saved. + * @param The path of the new subtree in this tree. + * @return String + */ + public String makeDeltaFile(ElementTree tree, IPath subTreePath) { + Workspace workspace = ((Workspace)project.getWorkspace()); + if ( tree == null) { + tree = workspace.getElementTree().getSubtree(project.getFullPath()); + } + if ( subTreePath == null ) { + subTreePath = project.getFullPath(); + } + + ElementTreeWriter treeWriter = new ElementTreeWriter(workspace.getSaveManager()); + + String strLocalFile = project.getLocation().toString() + "/" + STR_TREE_FILE; + + DataOutputStream output = null; + try { + output = new DataOutputStream(new SafeFileOutputStream(strLocalFile, strLocalFile + ".temp")); + + treeWriter.writeTree(tree, subTreePath, ElementTreeWriter.D_INFINITE, output); + } catch (Exception e) { + return ""; + } finally { + IOUtil.tryClose(output); + } + return strLocalFile; + } +} diff --git a/org.tizen.common/src/org/tizen/common/rds/ui/preference/DialogField.java b/org.tizen.common/src/org/tizen/common/rds/ui/preference/DialogField.java new file mode 100644 index 0000000..9c3555d --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/rds/ui/preference/DialogField.java @@ -0,0 +1,241 @@ + +/******************************************************************************* + * Copyright (c) 2000, 2008 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.tizen.common.rds.ui.preference; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; + +import org.eclipse.core.runtime.Assert; + + +/** + * Base class of all dialog fields. + * Dialog fields manage controls together with the model, independed + * from the creation time of the widgets. + * - support for automated layouting. + * - enable / disable, set focus a concept of the base class. + * + * DialogField have a label. + */ +public class DialogField { + + private Label fLabel; + protected String fLabelText; + + private IDialogFieldListener fDialogFieldListener; + + private boolean fEnabled; + + public DialogField() { + fEnabled= true; + fLabel= null; + fLabelText= ""; //$NON-NLS-1$ + } + + /** + * Sets the label of the dialog field. + */ + public void setLabelText(String labeltext) { + fLabelText= labeltext; + if (isOkToUse(fLabel)) { + fLabel.setText(labeltext); + } + } + + // ------ change listener + + /** + * Defines the listener for this dialog field. + */ + public final void setDialogFieldListener(IDialogFieldListener listener) { + fDialogFieldListener= listener; + } + + /** + * Programatical invocation of a dialog field change. + */ + public void dialogFieldChanged() { + if (fDialogFieldListener != null) { + fDialogFieldListener.dialogFieldChanged(this); + } + } + + // ------- focus management + + /** + * Tries to set the focus to the dialog field. + * Returns true if the dialog field can take focus. + * To be reimplemented by dialog field implementors. + */ + public boolean setFocus() { + return false; + } + + /** + * Posts setFocus to the display event queue. + */ + public void postSetFocusOnDialogField(Display display) { + if (display != null) { + display.asyncExec( + new Runnable() { + public void run() { + setFocus(); + } + } + ); + } + } + + // ------- layout helpers + + /** + * Creates all controls of the dialog field and fills it to a composite. + * The composite is assumed to have MGridLayout as + * layout. + * The dialog field will adjust its controls' spans to the number of columns given. + * To be reimplemented by dialog field implementors. + */ + public Control[] doFillIntoGrid(Composite parent, int nColumns) { + assertEnoughColumns(nColumns); + + Label label= getLabelControl(parent); + label.setLayoutData(gridDataForLabel(nColumns)); + + return new Control[] { label }; + } + + /** + * Returns the number of columns of the dialog field. + * To be reimplemented by dialog field implementors. + */ + public int getNumberOfControls() { + return 1; + } + + protected static GridData gridDataForLabel(int span) { + GridData gd= new GridData(GridData.HORIZONTAL_ALIGN_FILL); + gd.horizontalSpan= span; + return gd; + } + + // ------- ui creation + + /** + * Creates or returns the created label widget. + * @param parent The parent composite or null if the widget has + * already been created. + */ + public Label getLabelControl(Composite parent) { + if (fLabel == null) { + assertCompositeNotNull(parent); + + fLabel= new Label(parent, SWT.LEFT | SWT.WRAP); + fLabel.setFont(parent.getFont()); + fLabel.setEnabled(fEnabled); + if (fLabelText != null && !"".equals(fLabelText)) { //$NON-NLS-1$ + fLabel.setText(fLabelText); + } else { + // XXX: to avoid a 16 pixel wide empty label - revisit + fLabel.setText("."); //$NON-NLS-1$ + fLabel.setVisible(false); + } + } + return fLabel; + } + + /** + * Creates a spacer control. + * @param parent The parent composite + */ + public static Control createEmptySpace(Composite parent) { + return createEmptySpace(parent, 1); + } + + /** + * Creates a spacer control with the given span. + * The composite is assumed to have MGridLayout as + * layout. + * @param parent The parent composite + */ + public static Control createEmptySpace(Composite parent, int span) { + Label label= new Label(parent, SWT.LEFT); + GridData gd= new GridData(); + gd.horizontalAlignment= GridData.BEGINNING; + gd.grabExcessHorizontalSpace= false; + gd.horizontalSpan= span; + gd.horizontalIndent= 0; + gd.widthHint= 0; + gd.heightHint= 0; + label.setLayoutData(gd); + return label; + } + + /** + * Tests is the control is not null and not disposed. + */ + protected final boolean isOkToUse(Control control) { + return (control != null) && (Display.getCurrent() != null) && !control.isDisposed(); + } + + // --------- enable / disable management + + /** + * Sets the enable state of the dialog field. + */ + public final void setEnabled(boolean enabled) { + if (enabled != fEnabled) { + fEnabled= enabled; + updateEnableState(); + } + } + + /** + * Called when the enable state changed. + * To be extended by dialog field implementors. + */ + protected void updateEnableState() { + if (fLabel != null) { + fLabel.setEnabled(fEnabled); + } + } + + /** + * Brings the UI in sync with the model. Only needed when model was changed + * in different thread whil UI was lready created. + */ + public void refresh() { + updateEnableState(); + } + + /** + * Gets the enable state of the dialog field. + */ + public final boolean isEnabled() { + return fEnabled; + } + + protected final void assertCompositeNotNull(Composite comp) { + Assert.isNotNull(comp, "uncreated control requested with composite null"); //$NON-NLS-1$ + } + + protected final void assertEnoughColumns(int nColumns) { + Assert.isTrue(nColumns >= getNumberOfControls(), "given number of columns is too small"); //$NON-NLS-1$ + } + + + + +} diff --git a/org.tizen.common/src/org/tizen/common/rds/ui/preference/IDialogFieldListener.java b/org.tizen.common/src/org/tizen/common/rds/ui/preference/IDialogFieldListener.java new file mode 100644 index 0000000..8f0c302 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/rds/ui/preference/IDialogFieldListener.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2000, 2008 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.tizen.common.rds.ui.preference; + +/** + * Change listener used by DialogField + */ +public interface IDialogFieldListener { + + /** + * The dialog field has changed. + * + * @param field the dialog field that changed + */ + void dialogFieldChanged(DialogField field); + +} + diff --git a/org.tizen.common/src/org/tizen/common/rds/ui/preference/LayoutUtil.java b/org.tizen.common/src/org/tizen/common/rds/ui/preference/LayoutUtil.java new file mode 100644 index 0000000..f8afc7b --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/rds/ui/preference/LayoutUtil.java @@ -0,0 +1,146 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation 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: + * IBM Corporation - initial API and implementation + * Guven Demir - [package explorer] Alternative package name shortening: abbreviation - https://bugs.eclipse.org/bugs/show_bug.cgi?id=299514 + *******************************************************************************/ +package org.tizen.common.rds.ui.preference; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +public class LayoutUtil { + + /** + * Calculates the number of columns needed by field editors + */ + public static int getNumberOfColumns(DialogField[] editors) { + int nCulumns= 0; + for (int i= 0; i < editors.length; i++) { + nCulumns= Math.max(editors[i].getNumberOfControls(), nCulumns); + } + return nCulumns; + } + + /** + * Creates a composite and fills in the given editors. + * @param labelOnTop Defines if the label of all fields should be on top of the fields + */ + public static void doDefaultLayout(Composite parent, DialogField[] editors, boolean labelOnTop) { + doDefaultLayout(parent, editors, labelOnTop, 0, 0); + } + + /** + * Creates a composite and fills in the given editors. + * @param labelOnTop Defines if the label of all fields should be on top of the fields + * @param marginWidth The margin width to be used by the composite + * @param marginHeight The margin height to be used by the composite + */ + public static void doDefaultLayout(Composite parent, DialogField[] editors, boolean labelOnTop, int marginWidth, int marginHeight) { + int nCulumns= getNumberOfColumns(editors); + Control[][] controls= new Control[editors.length][]; + for (int i= 0; i < editors.length; i++) { + controls[i]= editors[i].doFillIntoGrid(parent, nCulumns); + } + if (labelOnTop) { + nCulumns--; + modifyLabelSpans(controls, nCulumns); + } + GridLayout layout= null; + if (parent.getLayout() instanceof GridLayout) { + layout= (GridLayout) parent.getLayout(); + } else { + layout= new GridLayout(); + } + if (marginWidth != SWT.DEFAULT) { + layout.marginWidth= marginWidth; + } + if (marginHeight != SWT.DEFAULT) { + layout.marginHeight= marginHeight; + } + layout.numColumns= nCulumns; + parent.setLayout(layout); + } + + private static void modifyLabelSpans(Control[][] controls, int nCulumns) { + for (int i= 0; i < controls.length; i++) { + setHorizontalSpan(controls[i][0], nCulumns); + } + } + + /** + * Sets the span of a control. Assumes that GridData is used. + */ + public static void setHorizontalSpan(Control control, int span) { + Object ld= control.getLayoutData(); + if (ld instanceof GridData) { + ((GridData)ld).horizontalSpan= span; + } else if (span != 1) { + GridData gd= new GridData(); + gd.horizontalSpan= span; + control.setLayoutData(gd); + } + } + + /** + * Sets the width hint of a control. Assumes that GridData is used. + */ + public static void setWidthHint(Control control, int widthHint) { + Object ld= control.getLayoutData(); + if (ld instanceof GridData) { + ((GridData)ld).widthHint= widthHint; + } + } + + /** + * Sets the heightHint hint of a control. Assumes that GridData is used. + */ + public static void setHeightHint(Control control, int heightHint) { + Object ld= control.getLayoutData(); + if (ld instanceof GridData) { + ((GridData)ld).heightHint= heightHint; + } + } + + /** + * Sets the horizontal indent of a control. Assumes that GridData is used. + */ + public static void setHorizontalIndent(Control control, int horizontalIndent) { + Object ld= control.getLayoutData(); + if (ld instanceof GridData) { + ((GridData)ld).horizontalIndent= horizontalIndent; + } + } + + /** + * Sets the horizontal grabbing of a control to true. Assumes that GridData is used. + */ + public static void setHorizontalGrabbing(Control control) { + Object ld= control.getLayoutData(); + if (ld instanceof GridData) { + ((GridData)ld).grabExcessHorizontalSpace= true; + } + } + + /** + * Sets the vertical grabbing of a control to true. Assumes that GridData is used. + * @since 3.6 + */ + public static void setVerticalGrabbing(Control control) { + Object ld= control.getLayoutData(); + if (ld instanceof GridData) { + GridData gd= ((GridData)ld); + gd.grabExcessVerticalSpace= true; + gd.verticalAlignment= SWT.FILL; + } + } + +} diff --git a/org.tizen.common/src/org/tizen/common/rds/ui/preference/ProjectSelectionDialog.java b/org.tizen.common/src/org/tizen/common/rds/ui/preference/ProjectSelectionDialog.java new file mode 100644 index 0000000..2553e15 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/rds/ui/preference/ProjectSelectionDialog.java @@ -0,0 +1,194 @@ +/******************************************************************************* + * Copyright (c) 2000, 2011 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.tizen.common.rds.ui.preference; + +import java.util.ArrayList; +import java.util.Set; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Shell; + +import org.eclipse.core.runtime.IStatus; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jface.viewers.ViewerSorter; + +import org.eclipse.ui.dialogs.SelectionStatusDialog; +import org.eclipse.ui.model.WorkbenchContentProvider; +import org.eclipse.ui.model.WorkbenchLabelProvider; +import org.tizen.common.CommonPlugin; + +//import org.eclipse.jdt.core.IJavaModel; +//import org.eclipse.jdt.core.IJavaProject; +//import org.eclipse.jdt.core.JavaCore; +// +//import org.eclipse.jdt.ui.JavaElementComparator; +//import org.eclipse.jdt.ui.JavaElementLabelProvider; +//import org.eclipse.jdt.ui.StandardJavaElementContentProvider; +// +//import org.eclipse.jdt.internal.ui.JavaPlugin; +//import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; + +public class ProjectSelectionDialog extends SelectionStatusDialog { + + // the visual selection widget group + private TableViewer fTableViewer; + private Set fProjectsWithSpecifics; + + // sizing constants + private final static int SIZING_SELECTION_WIDGET_HEIGHT= 250; + private final static int SIZING_SELECTION_WIDGET_WIDTH= 300; + + private final static String DIALOG_SETTINGS_SHOW_ALL= "ProjectSelectionDialog.show_all"; //$NON-NLS-1$ + + private ViewerFilter fFilter; + + public ProjectSelectionDialog(Shell parentShell, Set projectsWithSpecifics) { + super(parentShell); + setTitle("Project Specific Configuration"); + setMessage("&Select the project to configure:"); + fProjectsWithSpecifics= projectsWithSpecifics; + + fFilter= new ViewerFilter() { + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + return fProjectsWithSpecifics.contains(element); + } + }; + } + + + /* (non-Javadoc) + * Method declared on Dialog. + */ + @Override + protected Control createDialogArea(Composite parent) { + // page group + Composite composite= (Composite) super.createDialogArea(parent); + + Font font= parent.getFont(); + composite.setFont(font); + + createMessageArea(composite); + + fTableViewer= new TableViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); + fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + doSelectionChanged(((IStructuredSelection) event.getSelection()).toArray()); + } + }); + fTableViewer.addDoubleClickListener(new IDoubleClickListener() { + public void doubleClick(DoubleClickEvent event) { + okPressed(); + } + }); + GridData data= new GridData(SWT.FILL, SWT.FILL, true, true); + data.heightHint= SIZING_SELECTION_WIDGET_HEIGHT; + data.widthHint= SIZING_SELECTION_WIDGET_WIDTH; + fTableViewer.getTable().setLayoutData(data); + + fTableViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider()); + fTableViewer.setContentProvider(getContentProvider()); +// fTableViewer.setComparator(new JavaElementComparator()); + fTableViewer.getControl().setFont(font); + fTableViewer.setSorter(new ViewerSorter()); + + Button checkbox= new Button(composite, SWT.CHECK); + checkbox.setText("Show only &projects with project specific settings"); + checkbox.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false)); + checkbox.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + updateFilter(((Button) e.widget).getSelection()); + } + public void widgetDefaultSelected(SelectionEvent e) { + updateFilter(((Button) e.widget).getSelection()); + } + }); + IDialogSettings dialogSettings= CommonPlugin.getDefault().getDialogSettings(); + boolean doFilter= !dialogSettings.getBoolean(DIALOG_SETTINGS_SHOW_ALL) && !fProjectsWithSpecifics.isEmpty(); + checkbox.setSelection(doFilter); + updateFilter(doFilter); + + fTableViewer.setInput(ResourcesPlugin.getWorkspace()); + + doSelectionChanged(new Object[0]); + Dialog.applyDialogFont(composite); + return composite; + } + + protected void updateFilter(boolean selected) { + if (selected) { + fTableViewer.addFilter(fFilter); + } else { + fTableViewer.removeFilter(fFilter); + } + CommonPlugin.getDefault().getDialogSettings().put(DIALOG_SETTINGS_SHOW_ALL, !selected); + } + + private void doSelectionChanged(Object[] objects) { + if (objects.length != 1) { + updateStatus(new StatusInfo(IStatus.ERROR, "")); //$NON-NLS-1$ + setSelectionResult(null); + } else { + updateStatus(new StatusInfo()); + setSelectionResult(objects); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult() + */ + @Override + protected void computeResult() { + } + + protected IStructuredContentProvider getContentProvider() { + return new WorkbenchContentProvider() { + public Object[] getChildren(Object element) { + if (!(element instanceof IWorkspace)) { + return new Object[0]; + } + IProject[] projects = ((IWorkspace) element).getRoot().getProjects(); + ArrayList projectList = new ArrayList(); + // get array size + for ( IProject project : projects ) { + if( !project.isOpen() ){ + continue; + } + projectList.add(project); + } + + return projectList.toArray(); + } + }; + } +} diff --git a/org.tizen.common/src/org/tizen/common/rds/ui/preference/PropertyAndPreferencePage.java b/org.tizen.common/src/org/tizen/common/rds/ui/preference/PropertyAndPreferencePage.java new file mode 100644 index 0000000..caf17ee --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/rds/ui/preference/PropertyAndPreferencePage.java @@ -0,0 +1,347 @@ + +/******************************************************************************* + * Copyright (c) 2000, 2011 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.tizen.common.rds.ui.preference; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.ControlEnableState; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Link; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.IWorkbenchPropertyPage; +import org.eclipse.ui.dialogs.PreferencesUtil; + +//import org.eclipse.jdt.core.IJavaProject; +//import org.eclipse.jdt.core.JavaCore; +//import org.eclipse.jdt.core.JavaModelException; +// +//import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; +//import org.eclipse.jdt.internal.ui.dialogs.StatusUtil; +//import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener; +//import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField; +//import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener; +//import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil; +//import org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField; + +/** + * Base for project property and preference pages + */ +public abstract class PropertyAndPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, IWorkbenchPropertyPage { + + private Control fConfigurationBlockControl; + private ControlEnableState fBlockEnableState; + private Link fChangeWorkspaceSettings; + private SelectionButtonDialogField fUseProjectSettings; + private IStatus fBlockStatus; + private Composite fParentComposite; + + private IProject fProject; // project or null + private Map fData; // page data + + public static final String DATA_NO_LINK= "PropertyAndPreferencePage.nolink"; //$NON-NLS-1$ + + public PropertyAndPreferencePage() { + fBlockStatus= new StatusInfo(); + fBlockEnableState= null; + fProject= null; + fData= null; + } + + protected abstract Control createPreferenceContent(Composite composite); + protected abstract boolean hasProjectSpecificOptions(IProject project); + + protected abstract String getPreferencePageID(); + protected abstract String getPropertyPageID(); + + protected boolean supportsProjectSpecificOptions() { + return getPropertyPageID() != null; + } + + protected boolean offerLink() { + return fData == null || !Boolean.TRUE.equals(fData.get(DATA_NO_LINK)); + } + + @Override + protected Label createDescriptionLabel(Composite parent) { + fParentComposite= parent; + if (isProjectPreferencePage()) { + Composite composite= new Composite(parent, SWT.NONE); + composite.setFont(parent.getFont()); + GridLayout layout= new GridLayout(); + layout.marginHeight= 0; + layout.marginWidth= 0; + layout.numColumns= 2; + composite.setLayout(layout); + composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); + + IDialogFieldListener listener= new IDialogFieldListener() { + public void dialogFieldChanged(DialogField field) { + boolean enabled= ((SelectionButtonDialogField) field).isSelected(); + enableProjectSpecificSettings(enabled); + + if (enabled && getData() != null) { + applyData(getData()); + } + } + }; + + fUseProjectSettings= new SelectionButtonDialogField(SWT.CHECK); + fUseProjectSettings.setDialogFieldListener(listener); + fUseProjectSettings.setLabelText("Enable Pr&oject specific settings."); + fUseProjectSettings.doFillIntoGrid(composite, 1); + LayoutUtil.setHorizontalGrabbing(fUseProjectSettings.getSelectionButton(null)); + + if (offerLink()) { + fChangeWorkspaceSettings= createLink(composite, "Configure Workspace Settings..."); + fChangeWorkspaceSettings.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, false)); + } else { + LayoutUtil.setHorizontalSpan(fUseProjectSettings.getSelectionButton(null), 2); + } + + Label horizontalLine= new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); + horizontalLine.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1)); + horizontalLine.setFont(composite.getFont()); + } else if (supportsProjectSpecificOptions() && offerLink()) { + fChangeWorkspaceSettings= createLink(parent, "Configure Project Specific Settings..."); + fChangeWorkspaceSettings.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false)); + } + + return super.createDescriptionLabel(parent); + } + + /* + * @see org.eclipse.jface.preference.IPreferencePage#createContents(Composite) + */ + @Override + protected Control createContents(Composite parent) { + Composite composite= new Composite(parent, SWT.NONE); + GridLayout layout= new GridLayout(); + layout.marginHeight= 0; + layout.marginWidth= 0; + composite.setLayout(layout); + composite.setFont(parent.getFont()); + + GridData data= new GridData(GridData.FILL, GridData.FILL, true, true); + + fConfigurationBlockControl= createPreferenceContent(composite); + fConfigurationBlockControl.setLayoutData(data); + + if (isProjectPreferencePage()) { + boolean useProjectSettings= hasProjectSpecificOptions(getProject()); + enableProjectSpecificSettings(useProjectSettings); + } + + Dialog.applyDialogFont(composite); + return composite; + } + + private Link createLink(Composite composite, String text) { + Link link= new Link(composite, SWT.NONE); + link.setFont(composite.getFont()); + link.setText("" + text + ""); //$NON-NLS-1$//$NON-NLS-2$ + link.addSelectionListener(new SelectionListener() { + public void widgetSelected(SelectionEvent e) { + doLinkActivated((Link) e.widget); + } + + public void widgetDefaultSelected(SelectionEvent e) { + doLinkActivated((Link) e.widget); + } + }); + return link; + } + + protected boolean useProjectSettings() { + return isProjectPreferencePage() && fUseProjectSettings != null && fUseProjectSettings.isSelected(); + } + + protected boolean isProjectPreferencePage() { + return fProject != null; + } + + protected IProject getProject() { + return fProject; + } + + /** + * Handle link activation. + * + * @param link the link + */ + final void doLinkActivated(Link link) { + Map data= getData(); + if (data == null) + data= new HashMap(); + data.put(DATA_NO_LINK, Boolean.TRUE); + + if (isProjectPreferencePage()) { + openWorkspacePreferences(data); + } else { + HashSet projectsWithSpecifics= new HashSet(); + try { + IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); +// IProject[] projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects(); + for (int i= 0; i < projects.length; i++) { + IProject curr= projects[i]; + if (hasProjectSpecificOptions(curr.getProject())) { + projectsWithSpecifics.add(curr); + } + } + } catch (Exception e) { + // ignore + } + ProjectSelectionDialog dialog= new ProjectSelectionDialog(getShell(), projectsWithSpecifics); + if (dialog.open() == Window.OK) { + IProject res= (IProject) dialog.getFirstResult(); + openProjectProperties(res.getProject(), data); + } + } + } + + protected final void openWorkspacePreferences(Object data) { + String id= getPreferencePageID(); + PreferencesUtil.createPreferenceDialogOn(getShell(), id, new String[] { id }, data).open(); + } + + protected final void openProjectProperties(IProject project, Object data) { + String id= getPropertyPageID(); + if (id != null) { + PreferencesUtil.createPropertyDialogOn(getShell(), project, id, new String[] { id }, data).open(); + } + } + + + protected void enableProjectSpecificSettings(boolean useProjectSpecificSettings) { + fUseProjectSettings.setSelection(useProjectSpecificSettings); + enablePreferenceContent(useProjectSpecificSettings); + updateLinkVisibility(); + doStatusChanged(); + } + + private void updateLinkVisibility() { + if (fChangeWorkspaceSettings == null || fChangeWorkspaceSettings.isDisposed()) { + return; + } + + if (isProjectPreferencePage()) { + fChangeWorkspaceSettings.setEnabled(!useProjectSettings()); + } + } + + + protected void setPreferenceContentStatus(IStatus status) { + fBlockStatus= status; + doStatusChanged(); + } + + protected IStatus getPreferenceContentStatus() { + return fBlockStatus; + } + + protected void doStatusChanged() { + if (!isProjectPreferencePage() || useProjectSettings()) { + updateStatus(fBlockStatus); + } else { + updateStatus(new StatusInfo()); + } + } + + protected void enablePreferenceContent(boolean enable) { + if (enable) { + if (fBlockEnableState != null) { + fBlockEnableState.restore(); + fBlockEnableState= null; + } + } else { + if (fBlockEnableState == null) { + fBlockEnableState= ControlEnableState.disable(fConfigurationBlockControl); + } + } + } + + /* + * @see org.eclipse.jface.preference.IPreferencePage#performDefaults() + */ + @Override + protected void performDefaults() { + if (useProjectSettings()) { + enableProjectSpecificSettings(false); + } + super.performDefaults(); + } + + private void updateStatus(IStatus status) { + setValid(!status.matches(IStatus.ERROR)); + StatusUtil.applyToStatusLine(this, status); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) + */ + public void init(IWorkbench workbench) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPropertyPage#getElement() + */ + public IAdaptable getElement() { + return fProject; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchPropertyPage#setElement(org.eclipse.core.runtime.IAdaptable) + */ + public void setElement(IAdaptable element) { + fProject= (IProject) element.getAdapter(IResource.class); + } + + + /* (non-Javadoc) + * @see org.eclipse.jface.preference.PreferencePage#applyData(java.lang.Object) + */ + @SuppressWarnings("unchecked") + @Override + public void applyData(Object data) { + if (data instanceof Map) { + fData= (Map) data; + } + if (fChangeWorkspaceSettings != null) { + if (!offerLink()) { + fChangeWorkspaceSettings.dispose(); + fParentComposite.layout(true, true); + } + } + } + + protected Map getData() { + return fData; + } + +} diff --git a/org.tizen.common/src/org/tizen/common/rds/ui/preference/RdsPreferencePage.java b/org.tizen.common/src/org/tizen/common/rds/ui/preference/RdsPreferencePage.java new file mode 100644 index 0000000..752168d --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/rds/ui/preference/RdsPreferencePage.java @@ -0,0 +1,214 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim +* Gun Kim +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.rds.ui.preference; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; +import org.tizen.common.CommonPlugin; +import org.tizen.common.ui.page.preference.Messages; +import org.tizen.common.util.log.Logger; + + +/** + * The page to configure the Rapid Development Support options. + * + * @author Gun Kim + */ +public class RdsPreferencePage extends PropertyAndPreferencePage implements IWorkbenchPreferencePage { + public static final String RDS_OPTION_ID = "org.tizen.common.option.rds"; + public static final String RDS_PREFERENCE_PAGE_ID = "org.tizen.common.preferences.rds"; + public static final String RDS_PROPERTIES_PAGE_ID = "org.tizen.common.properties.rds"; + public static final QualifiedName RDS_PROPERTIES_SPECIFIC_OPTION_NAME = new QualifiedName(RDS_PROPERTIES_PAGE_ID, RDS_PREFERENCE_PAGE_ID); + public static final QualifiedName RDS_PROPERTIES_RDS_OPTION_NAME = new QualifiedName(RDS_PROPERTIES_PAGE_ID, RDS_OPTION_ID); + public static final String OPTION_ENABLE = "true"; + public static final String OPTION_DISABLE = "false"; + public static final boolean RDS_MODE_DEFAULT = true; + + private IPreferenceStore prefStore; + Button btnRdsCheck; + + public RdsPreferencePage() { + super(); + prefStore = CommonPlugin.getDefault().getPreferenceStore(); + } + + @Override + public void init(IWorkbench workbench) { + } + + @Override + protected Control createPreferenceContent(Composite composite) { + createRdsCheck(composite); + return composite; + } + + private void createRdsCheck( Composite parent ) { + Composite rdsComposite = new Composite(parent, SWT.NONE); + + GridData gridData = new GridData(GridData.FILL_HORIZONTAL); + gridData.horizontalSpan = 1; + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 1; + gridLayout.marginHeight = 5; + gridLayout.marginWidth = 5; + rdsComposite.setLayoutData(gridData); + rdsComposite.setLayout(gridLayout); + + btnRdsCheck = new Button(rdsComposite, SWT.CHECK); + btnRdsCheck.setText("Enable Rapid Development Support"); + btnRdsCheck.setSelection( getRdsOption() ); + createNoteComposite(JFaceResources.getDialogFont(), rdsComposite, "Note:", Messages.RDS_NOTE); + } + + @Override + protected boolean hasProjectSpecificOptions(IProject project) { + boolean isSpecificOption = false; + String specificOption = ""; + + + try { + specificOption = project.getPersistentProperty(RDS_PROPERTIES_SPECIFIC_OPTION_NAME); + } catch (CoreException e) { + isSpecificOption = false; + } + + if ( OPTION_ENABLE.equals(specificOption) ) { + isSpecificOption = true; + } + else { + isSpecificOption = false; + } + + return isSpecificOption; + } + + @Override + protected String getPreferencePageID() { + return RDS_PREFERENCE_PAGE_ID; + } + + @Override + protected String getPropertyPageID() { + return RDS_PROPERTIES_PAGE_ID; + } + + @Override + public void performApply() { + if ( isProjectPreferencePage() ) { + IProject project = getProject(); + try { + if ( useProjectSettings() ) { + project.setPersistentProperty(RDS_PROPERTIES_SPECIFIC_OPTION_NAME, OPTION_ENABLE); + } + else { + project.setPersistentProperty(RDS_PROPERTIES_SPECIFIC_OPTION_NAME, OPTION_DISABLE); + } + if ( btnRdsCheck.getSelection() ) { + project.setPersistentProperty(RDS_PROPERTIES_RDS_OPTION_NAME, OPTION_ENABLE); + } + else { + project.setPersistentProperty(RDS_PROPERTIES_RDS_OPTION_NAME, OPTION_DISABLE); + } + } catch (CoreException e) { + Logger.error(Messages.RDS_OPTION_SAVE_FAIL, e); + } + } + else { + prefStore.setValue(RDS_OPTION_ID, btnRdsCheck.getSelection()); + } + } + + public boolean getRdsOption() { + boolean isRdsOption = false; + IProject project = getProject(); + if ( isProjectPreferencePage() ) { + String rdsOption = null; + try { + rdsOption = project.getPersistentProperty(RDS_PROPERTIES_RDS_OPTION_NAME); + } catch (CoreException e) { + isRdsOption = false; + } + + if ( OPTION_ENABLE.equals(rdsOption) ) { + isRdsOption = true; + } + else { + isRdsOption = false; + } + } + else { + isRdsOption = prefStore.getBoolean(RDS_OPTION_ID); + } + + return isRdsOption; + } + + @Override + public void performDefaults() { + btnRdsCheck.setSelection(prefStore.getDefaultBoolean(RDS_OPTION_ID)); + super.performDefaults(); + } + + @Override + public boolean performOk() { + performApply(); + return super.performOk(); + } + + public static boolean isRdsMode( IProject project ) { + String projectSpecificOption = ""; + String rdsOption = OPTION_DISABLE; + try { + projectSpecificOption = project.getPersistentProperty(RDS_PROPERTIES_SPECIFIC_OPTION_NAME); + } catch (CoreException e) { + Logger.error("Failed to read project specific option.", e); + } + if ( OPTION_ENABLE.equals(projectSpecificOption)) { + try { + rdsOption = project.getPersistentProperty(RDS_PROPERTIES_RDS_OPTION_NAME); + } catch (CoreException e) { + Logger.error("Failed to read RDS option.", e); + } + + return OPTION_ENABLE.equals(rdsOption); + } + else { + IPreferenceStore prefStore = CommonPlugin.getDefault().getPreferenceStore(); + return prefStore.getBoolean(RDS_OPTION_ID); + } + } +} diff --git a/org.tizen.common/src/org/tizen/common/rds/ui/preference/SelectionButtonDialogField.java b/org.tizen.common/src/org/tizen/common/rds/ui/preference/SelectionButtonDialogField.java new file mode 100644 index 0000000..dfb73d4 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/rds/ui/preference/SelectionButtonDialogField.java @@ -0,0 +1,215 @@ + +/******************************************************************************* + * Copyright (c) 2000, 2011 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.tizen.common.rds.ui.preference; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.tizen.common.util.SWTUtil; + +/** + * Dialog Field containing a single button such as a radio or checkbox button. + */ +public class SelectionButtonDialogField extends DialogField { + + private Button fButton; + private boolean fIsSelected; + private DialogField[] fAttachedDialogFields; + private int fButtonStyle; + + /** + * Creates a selection button. + * Allowed button styles: SWT.RADIO, SWT.CHECK, SWT.TOGGLE, SWT.PUSH + */ + public SelectionButtonDialogField(int buttonStyle) { + super(); + fIsSelected= false; + fAttachedDialogFields= null; + fButtonStyle= buttonStyle; + } + + /** + * Attaches a field to the selection state of the selection button. + * The attached field will be disabled if the selection button is not selected. + */ + public void attachDialogField(DialogField dialogField) { + attachDialogFields(new DialogField[] { dialogField }); + } + + /** + * Attaches fields to the selection state of the selection button. + * The attached fields will be disabled if the selection button is not selected. + */ + public void attachDialogFields(DialogField[] dialogFields) { + fAttachedDialogFields= dialogFields; + for (int i= 0; i < dialogFields.length; i++) { + dialogFields[i].setEnabled(fIsSelected); + } + } + + /** + * Returns true is teh gived field is attached to the selection button. + */ + public boolean isAttached(DialogField editor) { + if (fAttachedDialogFields != null) { + for (int i=0; i < fAttachedDialogFields.length; i++) { + if (fAttachedDialogFields[i] == editor) { + return true; + } + } + } + return false; + } + + // ------- layout helpers + + /* + * @see DialogField#doFillIntoGrid + */ + @Override + public Control[] doFillIntoGrid(Composite parent, int nColumns) { + assertEnoughColumns(nColumns); + + Button button= getSelectionButton(parent); + GridData gd= new GridData(); + gd.horizontalSpan= nColumns; + gd.horizontalAlignment= GridData.FILL; + if (fButtonStyle == SWT.PUSH) { + gd.widthHint = SWTUtil.getButtonWidthHint(button); + } + + button.setLayoutData(gd); + + return new Control[] { button }; + } + + /* + * @see DialogField#getNumberOfControls + */ + @Override + public int getNumberOfControls() { + return 1; + } + + // ------- ui creation + + /** + * Returns the selection button widget. When called the first time, the widget will be created. + * @param group The parent composite when called the first time, or null + * after. + */ + public Button getSelectionButton(Composite group) { + if (fButton == null) { + assertCompositeNotNull(group); + + fButton= new Button(group, fButtonStyle); + fButton.setFont(group.getFont()); + fButton.setText(fLabelText); + fButton.setEnabled(isEnabled()); + fButton.setSelection(fIsSelected); + fButton.addSelectionListener(new SelectionListener() { + public void widgetDefaultSelected(SelectionEvent e) { + doWidgetSelected(e); + } + public void widgetSelected(SelectionEvent e) { + doWidgetSelected(e); + } + }); + } + return fButton; + } + + private void doWidgetSelected(SelectionEvent e) { + if (isOkToUse(fButton)) { + changeValue(fButton.getSelection()); + } + } + + private void changeValue(boolean newState) { + if (fIsSelected != newState) { + fIsSelected= newState; + if (fAttachedDialogFields != null) { + boolean focusSet= false; + for (int i= 0; i < fAttachedDialogFields.length; i++) { + fAttachedDialogFields[i].setEnabled(fIsSelected); + if (fIsSelected && !focusSet) { + focusSet= fAttachedDialogFields[i].setFocus(); + } + } + } + dialogFieldChanged(); + } else if (fButtonStyle == SWT.PUSH) { + dialogFieldChanged(); + } + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField#setLabelText(java.lang.String) + */ + @Override + public void setLabelText(String labeltext) { + fLabelText= labeltext; + if (isOkToUse(fButton)) { + fButton.setText(labeltext); + } + } + + + // ------ model access + + /** + * Returns the selection state of the button. + */ + public boolean isSelected() { + return fIsSelected; + } + + /** + * Sets the selection state of the button. + */ + public void setSelection(boolean selected) { + changeValue(selected); + if (isOkToUse(fButton)) { + fButton.setSelection(selected); + } + } + + // ------ enable / disable management + + /* + * @see DialogField#updateEnableState + */ + @Override + protected void updateEnableState() { + super.updateEnableState(); + if (isOkToUse(fButton)) { + fButton.setEnabled(isEnabled()); + } + } + + /*(non-Javadoc) + * @see org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField#refresh() + */ + @Override + public void refresh() { + super.refresh(); + if (isOkToUse(fButton)) { + fButton.setSelection(fIsSelected); + } + } + + +} diff --git a/org.tizen.common/src/org/tizen/common/rds/ui/preference/StatusInfo.java b/org.tizen.common/src/org/tizen/common/rds/ui/preference/StatusInfo.java new file mode 100644 index 0000000..46696bf --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/rds/ui/preference/StatusInfo.java @@ -0,0 +1,199 @@ + +/******************************************************************************* + * Copyright (c) 2000, 2011 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.tizen.common.rds.ui.preference; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.IStatus; +import org.tizen.common.CommonPlugin; + + +/** + * A settable IStatus. + * Can be an error, warning, info or ok. For error, info and warning states, + * a message describes the problem. + */ +public class StatusInfo implements IStatus { + + public static final IStatus OK_STATUS= new StatusInfo(); + + private String fStatusMessage; + private int fSeverity; + + /** + * Creates a status set to OK (no message) + */ + public StatusInfo() { + this(OK, null); + } + + /** + * Creates a status . + * @param severity The status severity: ERROR, WARNING, INFO and OK. + * @param message The message of the status. Applies only for ERROR, + * WARNING and INFO. + */ + public StatusInfo(int severity, String message) { + fStatusMessage= message; + fSeverity= severity; + } + + /** + * Returns if the status' severity is OK. + */ + public boolean isOK() { + return fSeverity == IStatus.OK; + } + + /** + * Returns if the status' severity is WARNING. + */ + public boolean isWarning() { + return fSeverity == IStatus.WARNING; + } + + /** + * Returns if the status' severity is INFO. + */ + public boolean isInfo() { + return fSeverity == IStatus.INFO; + } + + /** + * Returns if the status' severity is ERROR. + */ + public boolean isError() { + return fSeverity == IStatus.ERROR; + } + + /** + * @see IStatus#getMessage + */ + public String getMessage() { + return fStatusMessage; + } + + /** + * Sets the status to ERROR. + * @param errorMessage The error message (can be empty, but not null) + */ + public void setError(String errorMessage) { + Assert.isNotNull(errorMessage); + fStatusMessage= errorMessage; + fSeverity= IStatus.ERROR; + } + + /** + * Sets the status to WARNING. + * @param warningMessage The warning message (can be empty, but not null) + */ + public void setWarning(String warningMessage) { + Assert.isNotNull(warningMessage); + fStatusMessage= warningMessage; + fSeverity= IStatus.WARNING; + } + + /** + * Sets the status to INFO. + * @param infoMessage The info message (can be empty, but not null) + */ + public void setInfo(String infoMessage) { + Assert.isNotNull(infoMessage); + fStatusMessage= infoMessage; + fSeverity= IStatus.INFO; + } + + /** + * Sets the status to OK. + */ + public void setOK() { + fStatusMessage= null; + fSeverity= IStatus.OK; + } + + /* + * @see IStatus#matches(int) + */ + public boolean matches(int severityMask) { + return (fSeverity & severityMask) != 0; + } + + /** + * Returns always false. + * @see IStatus#isMultiStatus() + */ + public boolean isMultiStatus() { + return false; + } + + /* + * @see IStatus#getSeverity() + */ + public int getSeverity() { + return fSeverity; + } + + /* + * @see IStatus#getPlugin() + */ + public String getPlugin() { + return CommonPlugin.PLUGIN_ID; + } + + /** + * Returns always null. + * @see IStatus#getException() + */ + public Throwable getException() { + return null; + } + + /** + * Returns always the error severity. + * @see IStatus#getCode() + */ + public int getCode() { + return fSeverity; + } + + /** + * Returns always an empty array. + * @see IStatus#getChildren() + */ + public IStatus[] getChildren() { + return new IStatus[0]; + } + + /** + * Returns a string representation of the status, suitable + * for debugging purposes only. + */ + @Override + public String toString() { + StringBuffer buf = new StringBuffer(); + buf.append("StatusInfo "); //$NON-NLS-1$ + if (fSeverity == OK) { + buf.append("OK"); //$NON-NLS-1$ + } else if (fSeverity == ERROR) { + buf.append("ERROR"); //$NON-NLS-1$ + } else if (fSeverity == WARNING) { + buf.append("WARNING"); //$NON-NLS-1$ + } else if (fSeverity == INFO) { + buf.append("INFO"); //$NON-NLS-1$ + } else { + buf.append("severity="); //$NON-NLS-1$ + buf.append(fSeverity); + } + buf.append(": "); //$NON-NLS-1$ + buf.append(fStatusMessage); + return buf.toString(); + } +} diff --git a/org.tizen.common/src/org/tizen/common/rds/ui/preference/StatusUtil.java b/org.tizen.common/src/org/tizen/common/rds/ui/preference/StatusUtil.java new file mode 100644 index 0000000..fd25e07 --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/rds/ui/preference/StatusUtil.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2000, 2008 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.tizen.common.rds.ui.preference; + +import org.eclipse.core.runtime.IStatus; + +import org.eclipse.jface.dialogs.DialogPage; +import org.eclipse.jface.dialogs.IMessageProvider; + +/** + * A utility class to work with IStatus. + */ +public class StatusUtil { + + /** + * Compares two instances of IStatus. The more severe is returned: + * An error is more severe than a warning, and a warning is more severe + * than ok. If the two stati have the same severity, the second is returned. + * @param s1 first status + * @param s2 second status + * @return the more severe status + */ + public static IStatus getMoreSevere(IStatus s1, IStatus s2) { + if (s1.getSeverity() > s2.getSeverity()) { + return s1; + } else { + return s2; + } + } + + /** + * Finds the most severe status from a array of stati. + * An error is more severe than a warning, and a warning is more severe + * than ok. + * @param status an array of stati + * @return the most severe status + */ + public static IStatus getMostSevere(IStatus[] status) { + IStatus max= null; + for (int i= 0; i < status.length; i++) { + IStatus curr= status[i]; + if (curr.matches(IStatus.ERROR)) { + return curr; + } + if (max == null || curr.getSeverity() > max.getSeverity()) { + max= curr; + } + } + return max; + } + + /** + * Applies the status to the status line of a dialog page. + * @param page the dialog page + * @param status the status to apply + */ + public static void applyToStatusLine(DialogPage page, IStatus status) { + String message= status.getMessage(); + if (message != null && message.length() == 0) { + message= null; + } + switch (status.getSeverity()) { + case IStatus.OK: + page.setMessage(message, IMessageProvider.NONE); + page.setErrorMessage(null); + break; + case IStatus.WARNING: + page.setMessage(message, IMessageProvider.WARNING); + page.setErrorMessage(null); + break; + case IStatus.INFO: + page.setMessage(message, IMessageProvider.INFORMATION); + page.setErrorMessage(null); + break; + default: + page.setMessage(null); + page.setErrorMessage(message); + break; + } + } +} diff --git a/org.tizen.common/src/org/tizen/common/ui/page/preference/Messages.java b/org.tizen.common/src/org/tizen/common/ui/page/preference/Messages.java index 6e0c469..99acede 100644 --- a/org.tizen.common/src/org/tizen/common/ui/page/preference/Messages.java +++ b/org.tizen.common/src/org/tizen/common/ui/page/preference/Messages.java @@ -38,6 +38,10 @@ public class Messages { public static String LABEL_LOCATION; public static String LABEL_UPDATE; + public static String PROPERTIES_PAGE_BODY; + public static String RDS_NOTE; + public static String RDS_OPTION_SAVE_FAIL; + static { // initialize resource bundle NLS.initializeMessages( BUNDLE_NAME, Messages.class ); diff --git a/org.tizen.common/src/org/tizen/common/ui/page/preference/Messages.properties b/org.tizen.common/src/org/tizen/common/ui/page/preference/Messages.properties index b26e800..cec78c5 100644 --- a/org.tizen.common/src/org/tizen/common/ui/page/preference/Messages.properties +++ b/org.tizen.common/src/org/tizen/common/ui/page/preference/Messages.properties @@ -3,3 +3,6 @@ GROUP1=SDK path LABEL_LOCATION=Location: GROUP2=SDK update LABEL_UPDATE=Automatically find new updates at start-up and notify me +PROPERTIES_PAGE_BODY=Expand the tree to edit preferences for a specific feature. +RDS_NOTE=Currently, this option is not supported for web application. +RDS_OPTION_SAVE_FAIL=Failed to save options. \ No newline at end of file diff --git a/org.tizen.common/src/org/tizen/common/ui/page/preference/PreferenceMessages.properties b/org.tizen.common/src/org/tizen/common/ui/page/preference/PreferenceMessages.properties index d91c289..af75455 100644 --- a/org.tizen.common/src/org/tizen/common/ui/page/preference/PreferenceMessages.properties +++ b/org.tizen.common/src/org/tizen/common/ui/page/preference/PreferenceMessages.properties @@ -2,4 +2,4 @@ TizenPreferencePage.0=General settings TizenPreferencePage.1=SDK path TizenPreferencePage.2=Location: TizenPreferencePage.3=SDK update -TizenPreferencePage.4=Automatically find new updates at start-up and notify me +TizenPreferencePage.4=Automatically find new updates at start-up and notify me \ No newline at end of file diff --git a/org.tizen.common/src/org/tizen/common/ui/page/properties/TizenProperties.java b/org.tizen.common/src/org/tizen/common/ui/page/properties/TizenProperties.java new file mode 100644 index 0000000..9d6eb4e --- /dev/null +++ b/org.tizen.common/src/org/tizen/common/ui/page/properties/TizenProperties.java @@ -0,0 +1,53 @@ +/* +* Common +* +* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. +* +* Contact: +* Kangho Kim +* Gun Kim +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +* Contributors: +* - S-Core Co., Ltd +* +*/ +package org.tizen.common.ui.page.properties; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IWorkbenchPropertyPage; +import org.eclipse.ui.dialogs.PropertyPage; +import org.tizen.common.ui.page.preference.Messages; + +/** + * The page to configure for options of Tizen SDK. + * + * @author Gun Kim + */ +public class TizenProperties extends PropertyPage implements + IWorkbenchPropertyPage { + + public TizenProperties() { + String description = Messages.PROPERTIES_PAGE_BODY; + setDescription( description ); + } + + @Override + protected Control createContents(Composite parent) { + noDefaultAndApplyButton(); + return null; + } + +} diff --git a/org.tizen.common/src/org/tizen/common/util/SWTUtil.java b/org.tizen.common/src/org/tizen/common/util/SWTUtil.java index 6c40dc5..6da335f 100755 --- a/org.tizen.common/src/org/tizen/common/util/SWTUtil.java +++ b/org.tizen.common/src/org/tizen/common/util/SWTUtil.java @@ -45,6 +45,9 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.layout.PixelConverter; +import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.VerifyEvent; @@ -52,6 +55,7 @@ import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.graphics.Resource; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; @@ -551,5 +555,17 @@ public class SWTUtil { gd.horizontalSpan = columnSpan; label.setLayoutData(gd); } + + /** + * Returns a width hint for a button control. + * @param button the button + * @return the width hint + */ + public static int getButtonWidthHint(Button button) { + button.setFont(JFaceResources.getDialogFont()); + PixelConverter converter= new PixelConverter(button); + int widthHint= converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); + return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); + } } diff --git a/org.tizen.common/test/src/org/tizen/common/CommonPluginTest.java b/org.tizen.common/test/src/org/tizen/common/CommonPluginTest.java index ec80700..89f8410 100755 --- a/org.tizen.common/test/src/org/tizen/common/CommonPluginTest.java +++ b/org.tizen.common/test/src/org/tizen/common/CommonPluginTest.java @@ -32,6 +32,7 @@ import static org.tizen.common.FrequentlyUsedMatcher.doNotCare; import org.eclipse.jface.preference.IPreferenceStore; import org.junit.Test; import org.tizen.common.core.application.InstallPathConfig; +import org.tizen.common.rds.ui.preference.RdsPreferencePage; import org.tizen.common.ui.page.preference.TizenBasePreferencePage; @@ -74,7 +75,9 @@ CommonPluginTest (String) doNotCare() ); } + verify( preferenceStore ).setDefault( TizenBasePreferencePage.KEY_SDKUPDATE, false ); + verify( preferenceStore ).setDefault( RdsPreferencePage.RDS_OPTION_ID, RdsPreferencePage.RDS_MODE_DEFAULT ); } }