JBoss Tools SVN: r16878 - in trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools: src/org/jboss/ide/eclipse/archives/webtools and 2 other directories.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2009-07-29 14:42:53 -0400 (Wed, 29 Jul 2009)
New Revision: 16878
Added:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/DefaultFilesetPreferencePage.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/Fileset.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetActionProvider.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetContentProvider.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetDialog.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetLabelProvider.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetUtil.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/NewServerFilesetHandler.java
Removed:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/Fileset.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetActionProvider.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetContentProvider.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetDialog.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetLabelProvider.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.properties
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.xml
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/IntegrationPlugin.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/Messages.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/Messages.properties
Log:
JBIDE-2534
Modified: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.properties
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.properties 2009-07-29 16:52:11 UTC (rev 16877)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.properties 2009-07-29 18:42:53 UTC (rev 16878)
@@ -7,3 +7,4 @@
newPackageAction.label.ejbJar = EJB JAR
newPackageAction.label.ear = EAR
NavigatorContent_Filesets=Filesets
+defaultFilesetPreferencePageTitle=Default Filesets
\ No newline at end of file
Modified: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.xml 2009-07-29 16:52:11 UTC (rev 16877)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/plugin.xml 2009-07-29 18:42:53 UTC (rev 16878)
@@ -105,8 +105,8 @@
id="org.jboss.ide.eclipse.archives.webtools.ui.extensions.filesets"
activeByDefault="true"
icon="icons/multiple_files.gif"
- contentProvider="org.jboss.ide.eclipse.archives.webtools.ui.FilesetContentProvider"
- labelProvider="org.jboss.ide.eclipse.archives.webtools.ui.FilesetLabelProvider"
+ contentProvider="org.jboss.ide.eclipse.archives.webtools.filesets.FilesetContentProvider"
+ labelProvider="org.jboss.ide.eclipse.archives.webtools.filesets.FilesetLabelProvider"
name="%NavigatorContent_Filesets"
priority="normal">
<triggerPoints>
@@ -117,20 +117,20 @@
<possibleChildren>
<or>
<instanceof
- value="org.jboss.ide.eclipse.archives.webtools.ui.FilesetContentProvider$ServerWrapper">
+ value="org.jboss.ide.eclipse.archives.webtools.filesets.FilesetContentProvider$ServerWrapper">
</instanceof>
<instanceof
- value="org.jboss.ide.eclipse.archives.webtools.ui.Fileset">
+ value="org.jboss.ide.eclipse.archives.webtools.filesets.Fileset">
</instanceof>
<instanceof
- value="org.jboss.ide.eclipse.archives.webtools.ui.FilesetContentProvider$FolderWrapper">
+ value="org.jboss.ide.eclipse.archives.webtools.filesets.FilesetContentProvider$FolderWrapper">
</instanceof>
<instanceof
- value="org.jboss.ide.eclipse.archives.webtools.ui.FilesetContentProvider$PathWrapper">
+ value="org.jboss.ide.eclipse.archives.webtools.filesets.FilesetContentProvider$PathWrapper">
</instanceof>
</or></possibleChildren>
<actionProvider
- class="org.jboss.ide.eclipse.archives.webtools.ui.FilesetActionProvider"
+ class="org.jboss.ide.eclipse.archives.webtools.filesets.FilesetActionProvider"
id="org.jboss.ide.eclipse.archives.webtools.ui.extensions.filesets.actions"
priority="highest">
</actionProvider>
@@ -148,5 +148,15 @@
</includes>
</viewerContentBinding>
</extension>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ id="org.jboss.ide.eclipse.archives.webtools.defaultFileFilters.page"
+ name="%defaultFilesetPreferencePageTitle"
+ category="org.eclipse.wst.server.ui.preferencePage"
+ class="org.jboss.ide.eclipse.archives.webtools.filesets.DefaultFilesetPreferencePage">
+ <keywordReference id="org.eclipse.wst.server.preferenceKeywords"/>
+ </page>
+ </extension>
</plugin>
Modified: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/IntegrationPlugin.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/IntegrationPlugin.java 2009-07-29 16:52:11 UTC (rev 16877)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/IntegrationPlugin.java 2009-07-29 18:42:53 UTC (rev 16878)
@@ -11,7 +11,9 @@
package org.jboss.ide.eclipse.archives.webtools;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.jboss.ide.eclipse.archives.webtools.filesets.NewServerFilesetHandler;
import org.jboss.ide.eclipse.archives.webtools.modules.ArchivesModuleModelListener;
+import org.jboss.ide.eclipse.as.core.server.UnitedServerListenerManager;
import org.osgi.framework.BundleContext;
/**
@@ -39,6 +41,7 @@
super.start(context);
plugin = this;
ArchivesModuleModelListener.getInstance();
+ UnitedServerListenerManager.getDefault().addListener(NewServerFilesetHandler.getDefault());
}
/*
@@ -47,6 +50,7 @@
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
+ UnitedServerListenerManager.getDefault().removeListener(NewServerFilesetHandler.getDefault());
super.stop(context);
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/Messages.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/Messages.java 2009-07-29 16:52:11 UTC (rev 16877)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/Messages.java 2009-07-29 18:42:53 UTC (rev 16878)
@@ -46,7 +46,13 @@
public static String FilesetsDialogTitle;
public static String FilesetsDialogMessage;
-
+ public static String DefaultFilesetsAllServerTypes;
+ public static String DefaultFilesetsLabel;
+ public static String DefaultFilesetsAdd;
+ public static String DefaultFilesetsRemove;
+
+
+
public static String NewEar;
public static String EarPreview;
public static String EarDescription;
Modified: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/Messages.properties
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/Messages.properties 2009-07-29 16:52:11 UTC (rev 16877)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/Messages.properties 2009-07-29 18:42:53 UTC (rev 16878)
@@ -31,6 +31,12 @@
FilesetsDialogTitle=File filter
FilesetsDialogMessage=Creates a new file filter
+DefaultFilesetsAllServerTypes=All server types
+DefaultFilesetsLabel=This page will allow you to designate some default filesets to add to new servers.
+DefaultFilesetsAdd=Add Fileset...
+DefaultFilesetsRemove=Remove Fileset
+
+
NewEar=New EAR
EarPreview=EAR Preview
EarDescription=Preview the EAR\nLater, you can customize this structure further.
Added: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/DefaultFilesetPreferencePage.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/DefaultFilesetPreferencePage.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/DefaultFilesetPreferencePage.java 2009-07-29 18:42:53 UTC (rev 16878)
@@ -0,0 +1,275 @@
+package org.jboss.ide.eclipse.archives.webtools.filesets;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+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.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.wst.server.core.IServerType;
+import org.eclipse.wst.server.core.ServerCore;
+import org.jboss.ide.eclipse.archives.webtools.Messages;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+
+public class DefaultFilesetPreferencePage extends PreferencePage implements
+ IWorkbenchPreferencePage {
+
+ private Combo servers;
+ private TreeViewer viewer;
+ private Button addButton;
+ private Button removeButton;
+ private HashMap<String, ArrayList<Fileset>> cacheMap
+ = new HashMap<String, ArrayList<Fileset>>();
+ private ArrayList<String> changed = new ArrayList<String>();
+
+ public DefaultFilesetPreferencePage() {
+ }
+
+ public DefaultFilesetPreferencePage(String title) {
+ super(title);
+ }
+
+ public DefaultFilesetPreferencePage(String title, ImageDescriptor image) {
+ super(title, image);
+ }
+
+ public void init(IWorkbench workbench) {
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Composite c = new Composite(parent, SWT.NONE);
+ c.setLayout(new FormLayout());
+ c.setLayoutData(new GridData(GridData.FILL_BOTH));
+ Label l = new Label(c, SWT.None);
+ l.setText(Messages.DefaultFilesetsLabel);
+ l.setLayoutData(createFormData(0,5,null,0,0,5,100,-5));
+
+ servers = new Combo(c, SWT.READ_ONLY);
+ servers.setLayoutData(createFormData(l,5,null,0,0,5,null,0));
+ servers.setItems(getComboItems());
+
+ viewer = new TreeViewer(c);
+ viewer.getTree().setLayoutData(createFormData(
+ servers,5,100,-5,0,5,80,0));
+ viewer.setLabelProvider(getLabelProvider());
+ viewer.setContentProvider(getContentProvider());
+
+ addButton = new Button(c, SWT.DEFAULT);
+ addButton.setText(Messages.DefaultFilesetsAdd);
+ addButton.setLayoutData(createFormData(
+ servers,5,null,0,viewer.getTree(),5,100,-5));
+ removeButton = new Button(c, SWT.DEFAULT);
+ removeButton.setText(Messages.DefaultFilesetsRemove);
+ removeButton.setLayoutData(createFormData(
+ addButton,5,null,0,viewer.getTree(),5,100,-5));
+
+ servers.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ getCurrentServerSets();
+ viewer.refresh();
+ } });
+
+ addButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ addPressed();
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ removeButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ removePressed();
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ servers.select(0);
+ getCurrentServerSets();
+ viewer.setInput(ResourcesPlugin.getWorkspace());
+ c.layout();
+ return c;
+ }
+
+ protected void addPressed() {
+ FilesetDialog d = new FilesetDialog(addButton.getShell(), "", null); //$NON-NLS-1$
+ d.setShowViewer(false);
+ if( d.open() == Window.OK) {
+ Fileset fs = d.getFileset();
+ String id = getCurrentId();
+ cacheMap.get(id).add(fs);
+ if( !changed.contains(id))
+ changed.add(id);
+ viewer.refresh();
+ }
+ }
+
+ protected void removePressed() {
+ Fileset fs = null;
+ IStructuredSelection sel = (IStructuredSelection)viewer.getSelection();
+ fs = (Fileset)sel.getFirstElement();
+ if( fs != null ) {
+ String id = getCurrentId();
+ cacheMap.get(id).remove(fs);
+ if( !changed.contains(id))
+ changed.add(id);
+ viewer.refresh();
+ }
+ }
+
+ protected String getCurrentId() {
+ int index = servers.getSelectionIndex();
+ if( index == 0 )
+ return FilesetUtil.DEFAULT_FS_ALL_SERVERS;
+ if( index == -1 )
+ return null;
+ IServerType type = getServerTypes()[index-1];
+ String id = type.getId();
+ return id;
+ }
+ protected Fileset[] getCurrentServerSets() {
+ String id = getCurrentId();
+ List<Fileset> list = new ArrayList<Fileset>();
+ if( id != null ) {
+ list = cacheMap.get(id);
+ if( list == null ) {
+ IPath fileToRead = FilesetUtil.DEFAULT_FS_ROOT.append(id);
+ Fileset[] sets = FilesetUtil.loadFilesets(fileToRead.toFile(), null);
+ list = Arrays.asList(sets);
+ cacheMap.put(id, new ArrayList<Fileset>(list));
+ }
+ }
+ return (Fileset[]) list.toArray(new Fileset[list.size()]);
+ }
+
+ protected LabelProvider getLabelProvider() {
+ return new FilesetLabelProvider();
+ }
+
+ protected ITreeContentProvider getContentProvider() {
+ return new ITreeContentProvider() {
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public void dispose() {
+ }
+ public Object[] getElements(Object inputElement) {
+ return getCurrentServerSets();
+ }
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+ public Object getParent(Object element) {
+ return null;
+ }
+ public Object[] getChildren(Object parentElement) {
+ return null;
+ }
+ };
+ }
+
+ private String[] getComboItems() {
+ ArrayList<String> list = new ArrayList<String>();
+ IServerType[] types = getServerTypes();
+ list.add(Messages.DefaultFilesetsAllServerTypes);
+ for( int i = 0; i < types.length; i++ )
+ list.add(types[i].getName());
+ return (String[]) list.toArray(new String[list.size()]);
+ }
+
+ private IServerType[] types = null;
+ private IServerType[] getServerTypes() {
+ if( types == null ) {
+ ArrayList<IServerType> sorted = new ArrayList<IServerType>();
+ ArrayList<IServerType> all = new ArrayList(
+ Arrays.asList( ServerCore.getServerTypes()));
+ Iterator<IServerType> i = all.iterator();
+ IServerType t;
+ while(i.hasNext()) {
+ t = i.next();
+ if( t.getId().startsWith("org.jboss.ide.eclipse.as.")) {//$NON-NLS-1$
+ sorted.add(t);
+ i.remove();
+ }
+ }
+ sorted.addAll(all);
+ types = (IServerType[]) sorted.toArray(new IServerType[sorted.size()]);
+ }
+ return types;
+ }
+
+ private FormData createFormData(Object topStart, int topOffset,
+ Object bottomStart, int bottomOffset, Object leftStart,
+ int leftOffset, Object rightStart, int rightOffset) {
+ FormData data = new FormData();
+
+ if (topStart != null) {
+ data.top = topStart instanceof Control ? new FormAttachment(
+ (Control) topStart, topOffset) : new FormAttachment(
+ ((Integer) topStart).intValue(), topOffset);
+ }
+
+ if (bottomStart != null) {
+ data.bottom = bottomStart instanceof Control ? new FormAttachment(
+ (Control) bottomStart, bottomOffset) : new FormAttachment(
+ ((Integer) bottomStart).intValue(), bottomOffset);
+ }
+
+ if (leftStart != null) {
+ data.left = leftStart instanceof Control ? new FormAttachment(
+ (Control) leftStart, leftOffset) : new FormAttachment(
+ ((Integer) leftStart).intValue(), leftOffset);
+ }
+
+ if (rightStart != null) {
+ data.right = rightStart instanceof Control ? new FormAttachment(
+ (Control) rightStart, rightOffset) : new FormAttachment(
+ ((Integer) rightStart).intValue(), rightOffset);
+ }
+
+ return data;
+ }
+
+ public boolean performOk() {
+ String[] changed2 = (String[]) changed.toArray(new String[changed.size()]);
+ ArrayList<Fileset> list;
+ Fileset[] arr;
+ for( int i = 0; i < changed2.length; i++ ) {
+ list = cacheMap.get(changed2[i]);
+ arr = (Fileset[]) list.toArray(new Fileset[list.size()]);
+ IPath fileToWrite = FilesetUtil.DEFAULT_FS_ROOT.append(changed2[i]);
+ FilesetUtil.saveFilesets(fileToWrite.toFile(), arr);
+ }
+ changed.clear();
+ return true;
+ }
+
+}
Copied: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/Fileset.java (from rev 16851, trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/Fileset.java)
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/Fileset.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/Fileset.java 2009-07-29 18:42:53 UTC (rev 16878)
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.archives.webtools.filesets;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.server.core.IServer;
+
+
+public class Fileset implements Cloneable {
+ private static final String HASH_SEPARATOR = "::_::"; //$NON-NLS-1$
+ private static final String SEP = "\n"; //$NON-NLS-1$
+ private String name, folder, includesPattern, excludesPattern;
+ private IServer server;
+ public Fileset() {
+ }
+ public Fileset(String string) {
+ try {
+ name = folder = includesPattern =excludesPattern = ""; //$NON-NLS-1$
+ String[] parts = string.split(SEP);
+ name = parts[0];
+ folder = parts[1];
+ includesPattern = parts[2];
+ excludesPattern = parts[3];
+ } catch( ArrayIndexOutOfBoundsException aioobe) {}
+ }
+
+ public Fileset(String name, String folder, String inc, String exc) {
+ this.name = name;
+ this.folder = folder;
+ includesPattern = inc;
+ excludesPattern = exc;
+ }
+ public String toString() {
+ return name + SEP + folder + SEP + includesPattern + SEP + excludesPattern;
+ }
+ /**
+ * @return the folder
+ */
+ public String getFolder() {
+ String tmp = folder == null ? "" : folder; //$NON-NLS-1$
+ IPath p = new Path(tmp);
+ if( !p.isAbsolute() && server != null ) {
+ if( server.getRuntime() != null )
+ p = server.getRuntime().getLocation().append(p);
+ }
+ return p.toString();
+ }
+
+ public String getRawFolder() {
+ return folder == null ? "" : folder; //$NON-NLS-1$
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name == null ? "" : name; //$NON-NLS-1$
+ }
+ /**
+ * @return the excludesPattern
+ */
+ public String getExcludesPattern() {
+ return excludesPattern == null ? "" : excludesPattern; //$NON-NLS-1$
+ }
+ /**
+ * @return the includesPattern
+ */
+ public String getIncludesPattern() {
+ return includesPattern == null ? "" : includesPattern; //$NON-NLS-1$
+ }
+
+ /**
+ * @param excludesPattern the excludesPattern to set
+ */
+ public void setExcludesPattern(String excludesPattern) {
+ this.excludesPattern = excludesPattern;
+ }
+
+ /**
+ * @param folder the folder to set
+ */
+ public void setFolder(String folder) {
+ this.folder = folder;
+ }
+
+ /**
+ * @param includesPattern the includesPattern to set
+ */
+ public void setIncludesPattern(String includesPattern) {
+ this.includesPattern = includesPattern;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public IServer getServer() { return this.server; }
+ public void setServer(IServer server) { this.server = server; }
+
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch( Exception e ) {}
+ return null;
+ }
+
+ public boolean equals(Object other) {
+ if( !(other instanceof Fileset)) return false;
+ if( other == this ) return true;
+ Fileset o = (Fileset)other;
+ return o.getName().equals(getName()) && o.getFolder().equals(getFolder())
+ && o.getIncludesPattern().equals(getIncludesPattern()) && o.getExcludesPattern().equals(getExcludesPattern());
+ }
+ public int hashCode() {
+ return (name + HASH_SEPARATOR + folder + HASH_SEPARATOR + includesPattern + HASH_SEPARATOR + excludesPattern + HASH_SEPARATOR).hashCode();
+ }
+}
\ No newline at end of file
Copied: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetActionProvider.java (from rev 16851, trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetActionProvider.java)
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetActionProvider.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetActionProvider.java 2009-07-29 18:42:53 UTC (rev 16878)
@@ -0,0 +1,323 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.archives.webtools.filesets;
+
+import java.io.File;
+import java.util.ArrayList;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ITreeSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.FileStoreEditorInput;
+import org.eclipse.ui.navigator.CommonActionProvider;
+import org.eclipse.ui.navigator.ICommonActionExtensionSite;
+import org.eclipse.ui.navigator.ICommonViewerSite;
+import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.archives.webtools.Messages;
+import org.jboss.ide.eclipse.archives.webtools.filesets.FilesetContentProvider.PathWrapper;
+import org.jboss.ide.eclipse.archives.webtools.filesets.FilesetContentProvider.ServerWrapper;
+import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
+import org.jboss.ide.eclipse.as.core.util.FileUtil;
+import org.jboss.ide.eclipse.as.core.util.IConstants;
+import org.jboss.ide.eclipse.as.ui.JBossServerUIPlugin;
+
+public class FilesetActionProvider extends CommonActionProvider implements IDoubleClickListener {
+ private ICommonActionExtensionSite actionSite;
+ private Action createFilter, deleteFilter, editFilter,
+ deleteFileAction, editFileAction;
+ private ITreeSelection treeSelection;
+ private Object[] selected;
+
+ public FilesetActionProvider() {
+ super();
+ }
+
+ public void init(ICommonActionExtensionSite aSite) {
+ super.init(aSite);
+ this.actionSite = aSite;
+ ICommonViewerSite site = aSite.getViewSite();
+ if( site instanceof ICommonViewerWorkbenchSite ) {
+ StructuredViewer v = aSite.getStructuredViewer();
+ v.addDoubleClickListener(this);
+ }
+ createActions();
+ }
+
+ public void dispose() {
+ ICommonViewerSite site = actionSite.getViewSite();
+ if( site instanceof ICommonViewerWorkbenchSite ) {
+ StructuredViewer v = actionSite.getStructuredViewer();
+ v.removeDoubleClickListener(this);
+ }
+ super.dispose();
+ }
+
+ public void fillContextMenu(IMenuManager menu) {
+ ICommonViewerSite site = actionSite.getViewSite();
+ if (site instanceof ICommonViewerWorkbenchSite) {
+ setSelection();
+ if( selected == null )
+ return;
+ if( selected.length == 1 && selected[0] instanceof ServerWrapper ) {
+ menu.add(createFilter);
+ }else if( selected.length == 1 && selected[0] instanceof Fileset ) {
+ menu.add(deleteFilter);
+ menu.add(editFilter);
+ } else if( allPathWrappers(selected) ) {
+ editFileAction.setEnabled(canEdit(selected));
+ deleteFileAction.setEnabled(canDelete(selected));
+ menu.add(editFileAction);
+ menu.add(deleteFileAction);
+ }
+ }
+ }
+
+ protected void setSelection() {
+ ICommonViewerSite site = actionSite.getViewSite();
+ if (site instanceof ICommonViewerWorkbenchSite) {
+ ICommonViewerWorkbenchSite wsSite = (ICommonViewerWorkbenchSite) site;
+ ITreeSelection selection = (ITreeSelection) wsSite.getSelectionProvider()
+ .getSelection();
+ this.treeSelection = selection;
+ selected = selection.toArray();
+ }
+ }
+
+ protected boolean allPathWrappers(Object[] list) {
+ boolean result = true;
+ for( int i = 0; i < list.length; i++ )
+ result &= list[i] instanceof PathWrapper;
+ return result;
+ }
+
+ protected boolean canDelete(Object[] list ) {
+ boolean result = true;
+ for( int i = 0; i < list.length; i++ )
+ result &= ((PathWrapper)list[i]).getPath().toFile().exists();
+ return result;
+ }
+
+ protected boolean canEdit(Object[] list) {
+ for( int i = 0; i < list.length; i++ )
+ if( canEdit(((PathWrapper)list[i]).getPath().toFile()))
+ return true;
+ return false;
+ }
+
+ protected boolean canEdit(File file) {
+ IFile eclipseFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(file.getAbsolutePath()));
+ IFileStore fileStore= EFS.getLocalFileSystem().fromLocalFile(file);
+ boolean editable = false;
+ if( eclipseFile != null ) {
+ IEditorInput input = new FileEditorInput(eclipseFile);
+ IEditorDescriptor desc = PlatformUI.getWorkbench().
+ getEditorRegistry().getDefaultEditor(file.getName());
+ if( input != null && desc != null )
+ editable = true;
+ } else if( fileStore != null ){
+ IEditorInput input = new FileStoreEditorInput(fileStore);
+ IEditorDescriptor desc = PlatformUI.getWorkbench().
+ getEditorRegistry().getDefaultEditor(file.getName());
+ if( input != null && desc != null )
+ editable = true;
+ }
+ return editable;
+ }
+
+ protected File[] getSelectedFiles() {
+ ArrayList<File> tmp = new ArrayList<File>();
+ for( int i = 0; i < selected.length; i++ ) {
+ if( selected[i] instanceof PathWrapper)
+ tmp.add(((PathWrapper)selected[i]).getPath().toFile());
+ }
+ return (File[]) tmp.toArray(new File[tmp.size()]);
+ }
+
+ protected ServerWrapper getServerWrapper(Fileset fs) {
+ TreePath[] paths = treeSelection.getPathsFor(fs);
+ if( paths.length == 1 ) {
+ int count = paths[0].getSegmentCount();
+ if( count > 1 ) {
+ Object wrapper = paths[0].getSegment(count-2);
+ if( wrapper != null && wrapper instanceof ServerWrapper ) {
+ return ((ServerWrapper)wrapper);
+ }
+ }
+ }
+ return null;
+ }
+
+ protected void createActions() {
+ createFilter = new Action() {
+ public void run() {
+ IServer iserver = null;
+ ServerWrapper wrapper;
+ if( !(selected[0] instanceof ServerWrapper))
+ return;
+
+ wrapper = (ServerWrapper)selected[0];
+ iserver = wrapper.server;
+
+ IDeployableServer server = (IDeployableServer) iserver
+ .loadAdapter(IDeployableServer.class,
+ new NullProgressMonitor());
+ String location = null;
+ if (server != null && server.getServer().getRuntime() != null ) {
+ IJBossServerRuntime runtime = (IJBossServerRuntime)
+ server.getServer().getRuntime().loadAdapter(IJBossServerRuntime.class, null);
+ if( runtime != null ) {
+ location = IConstants.SERVER + IPath.SEPARATOR + runtime.getJBossConfiguration();
+ }
+ }
+ if( location == null )
+ location = iserver.getRuntime().getLocation().toOSString();
+
+ if (location != null) {
+ FilesetDialog d = new FilesetDialog(new Shell(), location, iserver);
+ if (d.open() == Window.OK) {
+ Fileset fs = d.getFileset();
+ wrapper.addFileset(fs);
+ actionSite.getStructuredViewer().refresh(wrapper);
+ }
+ }
+ }
+ };
+ createFilter.setText(Messages.FilesetsCreateFilter);
+
+ deleteFilter = new Action() {
+ public void run() {
+ Fileset fs = (Fileset)selected[0];
+ ServerWrapper wrapper = getServerWrapper(fs);
+ if( wrapper != null ) {
+ wrapper.removeFileset(fs);
+ actionSite.getStructuredViewer().refresh(wrapper);
+ }
+ }
+ };
+ deleteFilter.setText(Messages.FilesetsDeleteFilter);
+
+ editFilter = new Action() {
+ public void run() {
+ Fileset sel = (Fileset)selected[0];
+ ServerWrapper wrapper = getServerWrapper(sel);
+ FilesetDialog d = new FilesetDialog(new Shell(), sel);
+ if (d.open() == Window.OK) {
+ Fileset ret = d.getFileset();
+ sel.setName(ret.getName());
+ sel.setFolder(ret.getRawFolder());
+ sel.setIncludesPattern(ret.getIncludesPattern());
+ sel.setExcludesPattern(ret.getExcludesPattern());
+ wrapper.saveFilesets();
+ actionSite.getStructuredViewer().refresh(wrapper);
+ }
+ }
+ };
+ editFilter.setText(Messages.FilesetsEditFilter);
+
+ deleteFileAction = new Action() {
+ public void run() {
+ try {
+ Shell shell = Display.getCurrent().getActiveShell();
+ File[] files = getSelectedFiles();
+ MessageBox mb = new MessageBox(shell, SWT.ICON_QUESTION
+ | SWT.OK | SWT.CANCEL);
+ mb.setText(Messages.DeleteFiles);
+ mb.setMessage(Messages.DeleteFilesMessage);
+ if (mb.open() == SWT.OK) {
+ for (int i = 0; i < files.length; i++)
+ FileUtil.safeDelete(files[i]);
+ refreshViewer();
+ }
+ } catch (Exception e) {
+ }
+ }
+ };
+ deleteFileAction.setText(Messages.FilesetsDeleteFile);
+
+ editFileAction = new Action() {
+ public void run() {
+ File[] files = getSelectedFiles();
+ IWorkbench wb = PlatformUI.getWorkbench();
+ IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
+ IWorkbenchPage page = win.getActivePage();
+ for (int i = 0; i < files.length; i++) {
+ try {
+ IFile eclipseFile = ResourcesPlugin.getWorkspace()
+ .getRoot().getFileForLocation(
+ new Path(files[i].getAbsolutePath()));
+ IFileStore fileStore = EFS.getLocalFileSystem()
+ .fromLocalFile(files[i]);
+ if (eclipseFile != null) {
+ IEditorInput input = new FileEditorInput(
+ eclipseFile);
+ IEditorDescriptor desc = PlatformUI.getWorkbench()
+ .getEditorRegistry().getDefaultEditor(
+ files[i].getName());
+ if (desc != null)
+ page.openEditor(input, desc.getId());
+ } else if (fileStore != null) {
+ IEditorInput input = new FileStoreEditorInput(
+ fileStore);
+ IEditorDescriptor desc = PlatformUI.getWorkbench()
+ .getEditorRegistry().getDefaultEditor(
+ files[i].getName());
+ if (desc != null)
+ page.openEditor(input, desc.getId());
+ }
+ } catch (Exception e) {
+ IStatus status = new Status(IStatus.ERROR,
+ JBossServerUIPlugin.PLUGIN_ID,
+ Messages.FilesetsCannotOpenFile, e);
+ JBossServerUIPlugin.getDefault().getLog().log(status);
+ }
+ }
+ }
+ };
+ editFileAction.setText(Messages.FilesetsEditFile);
+ }
+
+ protected void refreshViewer() {
+ actionSite.getStructuredViewer().refresh();
+ }
+
+ public void doubleClick(DoubleClickEvent event) {
+ setSelection();
+ editFileAction.run();
+ }
+
+}
\ No newline at end of file
Copied: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetContentProvider.java (from rev 16851, trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetContentProvider.java)
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetContentProvider.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetContentProvider.java 2009-07-29 18:42:53 UTC (rev 16878)
@@ -0,0 +1,267 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.archives.webtools.filesets;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.tools.ant.BuildException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.archives.core.asf.DirectoryScanner;
+import org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory;
+import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
+
+public class FilesetContentProvider implements ITreeContentProvider {
+ private static final String FILESET_KEY = "org.jboss.ide.eclipse.as.ui.views.server.providers.FilesetViewProvider.PropertyKey"; //$NON-NLS-1$
+
+ public static class PathWrapper {
+ private IPath path;
+ private IPath folder;
+
+ public PathWrapper(IPath path, IPath folder) {
+ this.path = path;
+ this.folder = folder;
+ }
+
+ public IPath getFolder() {
+ return folder;
+ }
+
+ public IPath getPath() {
+ return folder.append(path);
+ }
+
+ public String getLocalizedResourceName() {
+ return path.toOSString();
+ }
+
+ public boolean equals(Object o) {
+ return o == null ? false :
+ !(o instanceof PathWrapper) ? false :
+ ((PathWrapper)o).folder.equals(folder) && ((PathWrapper)o).path.equals(path);
+ }
+
+ public int hashCode() {
+ return path.hashCode() + folder.hashCode();
+ }
+ }
+
+ public static class FolderWrapper extends PathWrapper {
+ private HashMap<String, FolderWrapper> childrenFolders;
+ private ArrayList<PathWrapper> children;
+
+ public FolderWrapper(IPath path, IPath folder) {
+ super(path, folder);
+ children = new ArrayList<PathWrapper>();
+ childrenFolders = new HashMap<String, FolderWrapper>();
+ }
+
+ public void addChild(IPath path) {
+ if (path.segmentCount() == 1) {
+ children.add(new PathWrapper(path, getFolder().append(
+ getLocalizedResourceName())));
+ } else {
+ addPath(children, childrenFolders, path, getFolder().append(
+ getLocalizedResourceName()));
+ }
+ }
+
+ public Object[] getChildren() {
+ return children.toArray(new Object[children.size()]);
+ }
+
+ private void addPath(ArrayList<PathWrapper> children,
+ HashMap<String, FolderWrapper> folders, IPath path, IPath folder) {
+ try {
+ FolderWrapper fw = null;
+ if (!folders.containsKey(path.segment(0))) {
+ fw = new FolderWrapper(path.removeLastSegments(path
+ .segmentCount() - 1), folder);
+ folders.put(path.segment(0), fw);
+ children.add(fw);
+ } else {
+ fw = folders.get(path.segment(0));
+ }
+ fw.addChild(path.removeFirstSegments(1));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public class ServerWrapper {
+ public IServer server;
+ private Fileset[] children;
+
+ public ServerWrapper(IServer server) {
+ this.server = server;
+ }
+
+ public int hashCode() {
+ return server.getId().hashCode();
+ }
+
+ public boolean equals(Object other) {
+ return other instanceof ServerWrapper
+ && ((ServerWrapper) other).server.getId().equals(
+ server.getId());
+ }
+
+ public void addFileset(Fileset fs) {
+ Fileset[] filesetsNew = new Fileset[children.length + 1];
+ System.arraycopy(children, 0, filesetsNew, 0, children.length);
+ filesetsNew[filesetsNew.length - 1] = fs;
+ children = filesetsNew;
+ saveFilesets();
+ }
+
+ public void removeFileset(Fileset fs) {
+ ArrayList<Fileset> asList = new ArrayList<Fileset>(Arrays
+ .asList(children));
+ asList.remove(fs);
+ children = asList.toArray(new Fileset[asList.size()]);
+ saveFilesets();
+ }
+
+ public Fileset[] getFilesets() {
+ if (children == null)
+ children = loadFilesets();
+ return children;
+ }
+
+ private Fileset[] loadFilesets() {
+ if( FilesetUtil.getFile(server).exists()) {
+ return FilesetUtil.loadFilesets(server);
+ } else {
+ return loadFilesets_LEGACY();
+ }
+ }
+
+ @Deprecated
+ private Fileset[] loadFilesets_LEGACY() {
+ Fileset[] filesets = new Fileset[0];
+ if (server != null) {
+ ServerAttributeHelper helper = ServerAttributeHelper
+ .createHelper(server);
+ List<String> tmp = (ArrayList<String>)helper.getAttribute(FILESET_KEY, new ArrayList<String>());
+ String[] asStrings = (String[]) tmp.toArray(new String[tmp
+ .size()]);
+ filesets = new Fileset[asStrings.length];
+ for (int i = 0; i < asStrings.length; i++) {
+ filesets[i] = new Fileset(asStrings[i]);
+ filesets[i].setServer(server);
+ }
+ }
+ return filesets;
+ }
+
+ public void saveFilesets() {
+ FilesetUtil.saveFilesets(server, children);
+ }
+ }
+
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof IServer) {
+ return new Object[] { new ServerWrapper((IServer) parentElement) };
+ }
+ if (parentElement instanceof ServerWrapper) {
+ return ((ServerWrapper) parentElement).getFilesets();
+ } else if (parentElement instanceof Fileset) {
+ Fileset fs = (Fileset) parentElement;
+ IPath[] paths = null;
+ try {
+ paths = findPaths(fs.getFolder(), fs.getIncludesPattern(), fs
+ .getExcludesPattern());
+ } catch (BuildException be) {
+ return new Object[] {};
+ }
+
+ HashMap<String, FolderWrapper> folders = new HashMap<String, FolderWrapper>();
+ ArrayList<PathWrapper> wrappers = new ArrayList<PathWrapper>();
+ for (int i = 0; i < paths.length; i++) {
+ if (paths[i].segmentCount() == 1) {
+ wrappers.add(new PathWrapper(paths[i], new Path(fs
+ .getFolder())));
+ } else {
+ addPath(wrappers, folders, paths[i], new Path(fs
+ .getFolder()));
+ }
+ }
+ return wrappers.toArray(new Object[wrappers.size()]);
+ } else if (parentElement instanceof FolderWrapper) {
+ return ((FolderWrapper) parentElement).getChildren();
+ }
+ return new Object[0];
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return getChildren(element).length > 0 ? true : false;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return null;
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ private IPath[] findPaths(String dir, String includes, String excludes) {
+ IPath[] paths = new IPath[0];
+ try {
+ if (dir != null) {
+ DirectoryScanner scanner = DirectoryScannerFactory
+ .createDirectoryScanner(dir, null, includes, excludes,
+ null, false, 1, true);
+ if (scanner != null) {
+ String[] files = scanner.getIncludedFiles();
+ paths = new IPath[files.length];
+ for (int i = 0; i < files.length; i++) {
+ paths[i] = new Path(files[i]);
+ }
+ }
+ }
+ } catch (IllegalStateException ise) {
+ }
+ return paths;
+ }
+
+ private static void addPath(ArrayList<PathWrapper> children,
+ HashMap<String, FolderWrapper> folders, IPath path, IPath folder) {
+ try {
+ FolderWrapper fw = null;
+ if (!folders.containsKey(path.segment(0))) {
+ fw = new FolderWrapper(path.removeLastSegments(path
+ .segmentCount() - 1), folder);
+ folders.put(path.segment(0), fw);
+ children.add(fw);
+ } else {
+ fw = folders.get(path.segment(0));
+ }
+ fw.addChild(path.removeFirstSegments(1));
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetDialog.java (from rev 16851, trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetDialog.java)
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetDialog.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetDialog.java 2009-07-29 18:42:53 UTC (rev 16878)
@@ -0,0 +1,244 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.archives.webtools.filesets;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.FillLayout;
+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.DirectoryDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.archives.core.asf.DirectoryScanner;
+import org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory;
+import org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory.DirectoryScannerExtension.FileWrapper;
+import org.jboss.ide.eclipse.archives.ui.util.composites.FilesetPreviewComposite;
+import org.jboss.ide.eclipse.archives.webtools.Messages;
+
+public class FilesetDialog extends TitleAreaDialog {
+ protected Fileset fileset;
+ private String name, dir, includes, excludes;
+ private Button browse;
+ private Text includesText, excludesText, folderText, nameText;
+ private Composite main;
+ private FilesetPreviewComposite preview;
+ private IServer server;
+ private boolean showViewer = true;
+ protected FilesetDialog(Shell parentShell, String defaultLocation, IServer server) {
+ super(parentShell);
+ this.fileset = new Fileset();
+ this.fileset.setFolder(defaultLocation);
+ this.fileset.setServer(server);
+ this.fileset.setIncludesPattern("**/*.xml"); //$NON-NLS-1$
+ this.server = server;
+ }
+ protected FilesetDialog(Shell parentShell, Fileset fileset) {
+ super(parentShell);
+ this.fileset = (Fileset)fileset.clone();
+ this.server = fileset.getServer();
+ }
+ public void setShowViewer(boolean val) {
+ showViewer = val;
+ }
+ protected Point getInitialSize() {
+ //return new Point(400, 150);
+ Point p = super.getInitialSize();
+ return new Point(500, p.y);
+ }
+ protected int getShellStyle() {
+ return super.getShellStyle() | SWT.RESIZE;
+ }
+
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setText(Messages.FilesetsNewFileset);
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ setTitle(Messages.FilesetsDialogTitle);
+ setMessage(Messages.FilesetsDialogMessage);
+
+ Composite sup = (Composite) super.createDialogArea(parent);
+ main = new Composite(sup, SWT.NONE);
+ main.setLayout(new GridLayout(3, false));
+ main.setLayoutData(new GridData(GridData.FILL_BOTH));
+ fillArea(main);
+
+ nameText.setText(fileset.getName());
+ folderText.setText(fileset.getRawFolder());
+ includesText.setText(fileset.getIncludesPattern());
+ excludesText.setText(fileset.getExcludesPattern());
+
+ addListeners();
+ getShell().layout();
+ textModified();
+ return sup;
+ }
+
+ protected void addListeners() {
+ ModifyListener mListener = new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ textModified();
+ }
+ };
+ nameText.addModifyListener(mListener);
+ folderText.addModifyListener(mListener);
+ includesText.addModifyListener(mListener);
+ excludesText.addModifyListener(mListener);
+
+ browse.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ public void widgetSelected(SelectionEvent e) {
+ DirectoryDialog d = new DirectoryDialog(new Shell());
+ String txt = folderText.getText();
+ if( !new Path(txt).isAbsolute() && server != null && server.getRuntime() != null)
+ txt = server.getRuntime().getLocation().append(txt).toString();
+ d.setFilterPath(txt);
+ String x = d.open();
+ if( x != null ) {
+ folderText.setText(makeRelative(x));
+ }
+ }
+ });
+ }
+
+ protected String makeRelative(String path) {
+ if( server != null && server.getRuntime() != null ) {
+ if( server.getRuntime().getLocation().isPrefixOf(new Path(path))) {
+ String p2 = path.substring(server.getRuntime().getLocation().toString().length());
+ return new Path(p2).makeRelative().toString();
+ }
+ }
+ return path;
+ }
+
+ protected void textModified() {
+ name = nameText.getText();
+ dir = folderText.getText();
+ includes = includesText.getText();
+ excludes = excludesText.getText();
+ fileset.setName(name);
+ fileset.setFolder(dir);
+ fileset.setIncludesPattern(includes);
+ fileset.setExcludesPattern(excludes);
+ updatePreview();
+ }
+ protected void fillArea(Composite main) {
+ Label nameLabel = new Label(main, SWT.NONE);
+ nameLabel.setText(Messages.FilesetsNewName);
+
+ nameText = new Text(main, SWT.BORDER);
+ nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+
+ Label folderLabel = new Label(main, SWT.NONE);
+ folderLabel.setText(Messages.FilesetsNewRootDir);
+
+ folderText = new Text(main, SWT.BORDER);
+ folderText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ browse = new Button(main, SWT.PUSH);
+ browse.setText(Messages.FilesetsNewBrowse);
+
+ Label includesLabel = new Label(main, SWT.NONE);
+ includesLabel.setText(Messages.FilesetsNewIncludes);
+
+ includesText = new Text(main, SWT.BORDER);
+ includesText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+
+ Label excludeLabel= new Label(main, SWT.NONE);
+ excludeLabel.setText(Messages.FilesetsNewExcludes);
+
+ excludesText = new Text(main, SWT.BORDER);
+ excludesText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+
+ if( showViewer ) {
+ Group previewWrapper = new Group(main, SWT.NONE);
+
+ previewWrapper.setLayout(new GridLayout());
+
+ GridData data = new GridData(GridData.FILL_BOTH);
+ data.grabExcessHorizontalSpace = true;
+ data.grabExcessVerticalSpace = true;
+ data.horizontalSpan = 3;
+ data.minimumHeight = 200;
+
+ previewWrapper.setLayoutData(data);
+ previewWrapper.setText(Messages.FilesetsNewPreview);
+
+ previewWrapper.setLayout(new FillLayout());
+ preview = new FilesetPreviewComposite(previewWrapper, SWT.NONE);
+ }
+ }
+
+ private void updatePreview() {
+ if( preview != null )
+ preview.setInput(findPaths(fileset.getFolder(), includes, excludes));
+ }
+
+ public String getDir() {
+ return dir;
+ }
+ public String getExcludes() {
+ return excludes;
+ }
+ public String getIncludes() {
+ return includes;
+ }
+ public String getName() {
+ return name;
+ }
+ public Fileset getFileset() {
+ return fileset;
+ }
+
+
+ private static IPath[] findPaths(String dir, String includes, String excludes) {
+ try {
+ if( dir != null ) {
+ DirectoryScanner scanner =
+ DirectoryScannerFactory.createDirectoryScanner(dir, null, includes, excludes, null, false, 1, false);
+ if( scanner != null ) {
+ Iterator<File> i = scanner.iterator();
+ ArrayList<IPath> paths2 = new ArrayList<IPath>();
+ while(i.hasNext() && paths2.size() < 30) {
+ FileWrapper fw = (FileWrapper)i.next();
+ paths2.add(new Path(fw.getFilesetRelative()));
+ }
+
+ return (IPath[]) paths2.toArray(new IPath[paths2.size()]);
+ }
+ }
+ } catch( IllegalStateException ise ) {}
+ catch(Exception e) {
+ e.printStackTrace();
+ }
+ return new IPath[]{};
+ }
+
+}
\ No newline at end of file
Copied: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetLabelProvider.java (from rev 16851, trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetLabelProvider.java)
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetLabelProvider.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetLabelProvider.java 2009-07-29 18:42:53 UTC (rev 16878)
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.archives.webtools.filesets;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.core.runtime.content.IContentTypeManager;
+import org.eclipse.core.runtime.content.IContentTypeMatcher;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
+import org.jboss.ide.eclipse.archives.webtools.filesets.FilesetContentProvider.FolderWrapper;
+import org.jboss.ide.eclipse.archives.webtools.filesets.FilesetContentProvider.PathWrapper;
+import org.jboss.ide.eclipse.archives.webtools.filesets.FilesetContentProvider.ServerWrapper;
+
+public class FilesetLabelProvider extends LabelProvider {
+
+ private LocalResourceManager resourceManager;
+ private Image rootImage;
+ public FilesetLabelProvider() {
+ super();
+ this.resourceManager = new LocalResourceManager(JFaceResources.getResources());
+ ImageDescriptor des = ImageDescriptor.createFromURL(IntegrationPlugin.getDefault().getBundle().getEntry("icons/multiple_files.gif")); //$NON-NLS-1$
+ rootImage = des.createImage();
+ }
+
+ public Image getImage(Object element) {
+ if( element instanceof Fileset ) {
+ return PlatformUI.getWorkbench().getSharedImages()
+ .getImage(ISharedImages.IMG_OBJ_FOLDER);
+ } else if( element instanceof FolderWrapper ) {
+ return PlatformUI.getWorkbench().getSharedImages()
+ .getImage(ISharedImages.IMG_OBJ_FOLDER);
+ } else if( element instanceof PathWrapper ) {
+ String fileName = ((PathWrapper)element).getPath().toOSString();
+ IContentTypeManager manager = Platform.getContentTypeManager();
+ IContentTypeMatcher matcher = manager.getMatcher(null, null);
+ IContentType contentType = matcher.findContentTypeFor(fileName);
+ ImageDescriptor descriptor = PlatformUI.getWorkbench().getEditorRegistry()
+ .getImageDescriptor(fileName, contentType);
+ if (descriptor == null) {
+ descriptor = PlatformUI.getWorkbench().getSharedImages()
+ .getImageDescriptor(ISharedImages.IMG_OBJ_FILE);
+ }
+ return resourceManager.createImage(descriptor);
+ } else if( element instanceof ServerWrapper ) {
+ return rootImage;
+ }
+ return null;
+ }
+
+ public String getText(Object element) {
+ if( element instanceof PathWrapper ) return ((PathWrapper)element).getLocalizedResourceName();
+ if( element instanceof Fileset ) return ((Fileset)element).getName() + " " + ((Fileset)element).getRawFolder(); //$NON-NLS-1$
+ if( element instanceof ServerWrapper ) return "Filesets"; //$NON-NLS-1$
+ return null;
+ }
+
+
+ public void dispose() {
+ resourceManager.dispose();
+ resourceManager = null;
+ rootImage.dispose();
+ super.dispose();
+ }
+
+}
Added: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetUtil.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetUtil.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/FilesetUtil.java 2009-07-29 18:42:53 UTC (rev 16878)
@@ -0,0 +1,72 @@
+package org.jboss.ide.eclipse.archives.webtools.filesets;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.tools.jmx.core.IMemento;
+import org.jboss.tools.jmx.core.util.XMLMemento;
+
+public class FilesetUtil {
+ protected static final String FILESET_FILE_NAME = "filesets.xml"; //$NON-NLS-1$
+ protected static IPath DEFAULT_FS_ROOT = JBossServerCorePlugin.getGlobalSettingsLocation().append("filesets").append("default"); //$NON-NLS-1$ //$NON-NLS-2$
+ protected static String DEFAULT_FS_ALL_SERVERS = "org.jboss.ide.eclipse.archives.webtools.ui.allServers"; //$NON-NLS-1$
+ public static Fileset[] loadFilesets(IServer server) {
+ return loadFilesets(getFile(server), server);
+ }
+
+ public static Fileset[] loadFilesets(File file, IServer server) {
+ Fileset[] filesets = null;
+ try {
+ XMLMemento memento = XMLMemento.createReadRoot(new FileInputStream(file));
+ IMemento[] categoryMementos = memento.getChildren("fileset");//$NON-NLS-1$
+ filesets = new Fileset[categoryMementos.length];
+ String name, folder, includes, excludes;
+ for( int i = 0; i < categoryMementos.length; i++ ) {
+ name = categoryMementos[i].getString("name"); //$NON-NLS-1$
+ folder = categoryMementos[i].getString("folder");//$NON-NLS-1$
+ includes = categoryMementos[i].getString("includes");//$NON-NLS-1$
+ excludes = categoryMementos[i].getString("excludes");//$NON-NLS-1$
+ filesets[i] = new Fileset(name, folder, includes, excludes);
+ filesets[i].setServer(server);
+ }
+ } catch( IOException ioe) {
+ // TODO LOG
+ }
+ return filesets == null ? new Fileset[] { } : filesets;
+ }
+
+ public static void saveFilesets(IServer server, Fileset[] sets) {
+ saveFilesets(getFile(server), sets);
+ }
+
+ public static void saveFilesets(File file, Fileset[] sets) {
+ if( file != null ) {
+ file.getParentFile().mkdirs();
+ XMLMemento memento = XMLMemento.createWriteRoot("filesets"); //$NON-NLS-1$
+ for( int i = 0; i < sets.length; i++ ) {
+ XMLMemento child = (XMLMemento)memento.createChild("fileset");//$NON-NLS-1$
+ child.putString("name", sets[i].getName());//$NON-NLS-1$
+ child.putString("folder", sets[i].getRawFolder());//$NON-NLS-1$
+ child.putString("includes", sets[i].getIncludesPattern());//$NON-NLS-1$
+ child.putString("excludes", sets[i].getExcludesPattern());//$NON-NLS-1$
+ }
+ try {
+ memento.save(new FileOutputStream(file));
+ } catch( IOException ioe) {
+ // TODO LOG
+ }
+ }
+ }
+
+
+ public static File getFile(IServer server) {
+ return JBossServerCorePlugin.getServerStateLocation(server)
+ .append(FILESET_FILE_NAME).toFile();
+ }
+
+}
Added: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/NewServerFilesetHandler.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/NewServerFilesetHandler.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/filesets/NewServerFilesetHandler.java 2009-07-29 18:42:53 UTC (rev 16878)
@@ -0,0 +1,31 @@
+package org.jboss.ide.eclipse.archives.webtools.filesets;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.server.UnitedServerListener;
+
+public class NewServerFilesetHandler extends UnitedServerListener {
+ private static NewServerFilesetHandler instance;
+ public static NewServerFilesetHandler getDefault() {
+ if( instance == null )
+ instance = new NewServerFilesetHandler();
+ return instance;
+ }
+
+ public void serverAdded(IServer server) {
+ IPath fileToRead = FilesetUtil.DEFAULT_FS_ROOT.append(FilesetUtil.DEFAULT_FS_ALL_SERVERS);
+ Fileset[] sets = FilesetUtil.loadFilesets(fileToRead.toFile(), null);
+ ArrayList<Fileset> list = new ArrayList<Fileset>();
+ list.addAll(Arrays.asList(sets));
+
+ String typeId = server.getServerType().getId();
+ fileToRead = FilesetUtil.DEFAULT_FS_ROOT.append(typeId);
+ sets = FilesetUtil.loadFilesets(fileToRead.toFile(), null);
+ list.addAll(Arrays.asList(sets));
+ Fileset[] finalSets = (Fileset[]) list.toArray(new Fileset[list.size()]);
+ FilesetUtil.saveFilesets(server, finalSets);
+ }
+}
Deleted: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/Fileset.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/Fileset.java 2009-07-29 16:52:11 UTC (rev 16877)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/Fileset.java 2009-07-29 18:42:53 UTC (rev 16878)
@@ -1,129 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.ide.eclipse.archives.webtools.ui;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.wst.server.core.IServer;
-
-
-public class Fileset implements Cloneable {
- private static final String HASH_SEPARATOR = "::_::"; //$NON-NLS-1$
- private static final String SEP = "\n"; //$NON-NLS-1$
- private String name, folder, includesPattern, excludesPattern;
- private IServer server;
- public Fileset() {
- }
- public Fileset(String string) {
- try {
- name = folder = includesPattern =excludesPattern = ""; //$NON-NLS-1$
- String[] parts = string.split(SEP);
- name = parts[0];
- folder = parts[1];
- includesPattern = parts[2];
- excludesPattern = parts[3];
- } catch( ArrayIndexOutOfBoundsException aioobe) {}
- }
-
- public Fileset(String name, String folder, String inc, String exc) {
- this.name = name;
- this.folder = folder;
- includesPattern = inc;
- excludesPattern = exc;
- }
- public String toString() {
- return name + SEP + folder + SEP + includesPattern + SEP + excludesPattern;
- }
- /**
- * @return the folder
- */
- public String getFolder() {
- String tmp = folder == null ? "" : folder; //$NON-NLS-1$
- IPath p = new Path(tmp);
- if( !p.isAbsolute() && server != null ) {
- if( server.getRuntime() != null )
- p = server.getRuntime().getLocation().append(p);
- }
- return p.toString();
- }
-
- public String getRawFolder() {
- return folder == null ? "" : folder; //$NON-NLS-1$
- }
-
- /**
- * @return the name
- */
- public String getName() {
- return name == null ? "" : name; //$NON-NLS-1$
- }
- /**
- * @return the excludesPattern
- */
- public String getExcludesPattern() {
- return excludesPattern == null ? "" : excludesPattern; //$NON-NLS-1$
- }
- /**
- * @return the includesPattern
- */
- public String getIncludesPattern() {
- return includesPattern == null ? "" : includesPattern; //$NON-NLS-1$
- }
-
- /**
- * @param excludesPattern the excludesPattern to set
- */
- public void setExcludesPattern(String excludesPattern) {
- this.excludesPattern = excludesPattern;
- }
-
- /**
- * @param folder the folder to set
- */
- public void setFolder(String folder) {
- this.folder = folder;
- }
-
- /**
- * @param includesPattern the includesPattern to set
- */
- public void setIncludesPattern(String includesPattern) {
- this.includesPattern = includesPattern;
- }
-
- /**
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- public IServer getServer() { return this.server; }
- public void setServer(IServer server) { this.server = server; }
-
- public Object clone() {
- try {
- return super.clone();
- } catch( Exception e ) {}
- return null;
- }
-
- public boolean equals(Object other) {
- if( !(other instanceof Fileset)) return false;
- if( other == this ) return true;
- Fileset o = (Fileset)other;
- return o.getName().equals(getName()) && o.getFolder().equals(getFolder())
- && o.getIncludesPattern().equals(getIncludesPattern()) && o.getExcludesPattern().equals(getExcludesPattern());
- }
- public int hashCode() {
- return (name + HASH_SEPARATOR + folder + HASH_SEPARATOR + includesPattern + HASH_SEPARATOR + excludesPattern + HASH_SEPARATOR).hashCode();
- }
-}
\ No newline at end of file
Deleted: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetActionProvider.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetActionProvider.java 2009-07-29 16:52:11 UTC (rev 16877)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetActionProvider.java 2009-07-29 18:42:53 UTC (rev 16878)
@@ -1,323 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.ide.eclipse.archives.webtools.ui;
-
-import java.io.File;
-import java.util.ArrayList;
-
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IMenuManager;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ITreeSelection;
-import org.eclipse.jface.viewers.StructuredViewer;
-import org.eclipse.jface.viewers.TreePath;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.MessageBox;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.ide.FileStoreEditorInput;
-import org.eclipse.ui.navigator.CommonActionProvider;
-import org.eclipse.ui.navigator.ICommonActionExtensionSite;
-import org.eclipse.ui.navigator.ICommonViewerSite;
-import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
-import org.eclipse.ui.part.FileEditorInput;
-import org.eclipse.wst.server.core.IServer;
-import org.jboss.ide.eclipse.archives.webtools.Messages;
-import org.jboss.ide.eclipse.archives.webtools.ui.FilesetContentProvider.PathWrapper;
-import org.jboss.ide.eclipse.archives.webtools.ui.FilesetContentProvider.ServerWrapper;
-import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
-import org.jboss.ide.eclipse.as.core.util.FileUtil;
-import org.jboss.ide.eclipse.as.core.util.IConstants;
-import org.jboss.ide.eclipse.as.ui.JBossServerUIPlugin;
-
-public class FilesetActionProvider extends CommonActionProvider implements IDoubleClickListener {
- private ICommonActionExtensionSite actionSite;
- private Action createFilter, deleteFilter, editFilter,
- deleteFileAction, editFileAction;
- private ITreeSelection treeSelection;
- private Object[] selected;
-
- public FilesetActionProvider() {
- super();
- }
-
- public void init(ICommonActionExtensionSite aSite) {
- super.init(aSite);
- this.actionSite = aSite;
- ICommonViewerSite site = aSite.getViewSite();
- if( site instanceof ICommonViewerWorkbenchSite ) {
- StructuredViewer v = aSite.getStructuredViewer();
- v.addDoubleClickListener(this);
- }
- createActions();
- }
-
- public void dispose() {
- ICommonViewerSite site = actionSite.getViewSite();
- if( site instanceof ICommonViewerWorkbenchSite ) {
- StructuredViewer v = actionSite.getStructuredViewer();
- v.removeDoubleClickListener(this);
- }
- super.dispose();
- }
-
- public void fillContextMenu(IMenuManager menu) {
- ICommonViewerSite site = actionSite.getViewSite();
- if (site instanceof ICommonViewerWorkbenchSite) {
- setSelection();
- if( selected == null )
- return;
- if( selected.length == 1 && selected[0] instanceof ServerWrapper ) {
- menu.add(createFilter);
- }else if( selected.length == 1 && selected[0] instanceof Fileset ) {
- menu.add(deleteFilter);
- menu.add(editFilter);
- } else if( allPathWrappers(selected) ) {
- editFileAction.setEnabled(canEdit(selected));
- deleteFileAction.setEnabled(canDelete(selected));
- menu.add(editFileAction);
- menu.add(deleteFileAction);
- }
- }
- }
-
- protected void setSelection() {
- ICommonViewerSite site = actionSite.getViewSite();
- if (site instanceof ICommonViewerWorkbenchSite) {
- ICommonViewerWorkbenchSite wsSite = (ICommonViewerWorkbenchSite) site;
- ITreeSelection selection = (ITreeSelection) wsSite.getSelectionProvider()
- .getSelection();
- this.treeSelection = selection;
- selected = selection.toArray();
- }
- }
-
- protected boolean allPathWrappers(Object[] list) {
- boolean result = true;
- for( int i = 0; i < list.length; i++ )
- result &= list[i] instanceof PathWrapper;
- return result;
- }
-
- protected boolean canDelete(Object[] list ) {
- boolean result = true;
- for( int i = 0; i < list.length; i++ )
- result &= ((PathWrapper)list[i]).getPath().toFile().exists();
- return result;
- }
-
- protected boolean canEdit(Object[] list) {
- for( int i = 0; i < list.length; i++ )
- if( canEdit(((PathWrapper)list[i]).getPath().toFile()))
- return true;
- return false;
- }
-
- protected boolean canEdit(File file) {
- IFile eclipseFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(file.getAbsolutePath()));
- IFileStore fileStore= EFS.getLocalFileSystem().fromLocalFile(file);
- boolean editable = false;
- if( eclipseFile != null ) {
- IEditorInput input = new FileEditorInput(eclipseFile);
- IEditorDescriptor desc = PlatformUI.getWorkbench().
- getEditorRegistry().getDefaultEditor(file.getName());
- if( input != null && desc != null )
- editable = true;
- } else if( fileStore != null ){
- IEditorInput input = new FileStoreEditorInput(fileStore);
- IEditorDescriptor desc = PlatformUI.getWorkbench().
- getEditorRegistry().getDefaultEditor(file.getName());
- if( input != null && desc != null )
- editable = true;
- }
- return editable;
- }
-
- protected File[] getSelectedFiles() {
- ArrayList<File> tmp = new ArrayList<File>();
- for( int i = 0; i < selected.length; i++ ) {
- if( selected[i] instanceof PathWrapper)
- tmp.add(((PathWrapper)selected[i]).getPath().toFile());
- }
- return (File[]) tmp.toArray(new File[tmp.size()]);
- }
-
- protected ServerWrapper getServerWrapper(Fileset fs) {
- TreePath[] paths = treeSelection.getPathsFor(fs);
- if( paths.length == 1 ) {
- int count = paths[0].getSegmentCount();
- if( count > 1 ) {
- Object wrapper = paths[0].getSegment(count-2);
- if( wrapper != null && wrapper instanceof ServerWrapper ) {
- return ((ServerWrapper)wrapper);
- }
- }
- }
- return null;
- }
-
- protected void createActions() {
- createFilter = new Action() {
- public void run() {
- IServer iserver = null;
- ServerWrapper wrapper;
- if( !(selected[0] instanceof ServerWrapper))
- return;
-
- wrapper = (ServerWrapper)selected[0];
- iserver = wrapper.server;
-
- IDeployableServer server = (IDeployableServer) iserver
- .loadAdapter(IDeployableServer.class,
- new NullProgressMonitor());
- String location = null;
- if (server != null && server.getServer().getRuntime() != null ) {
- IJBossServerRuntime runtime = (IJBossServerRuntime)
- server.getServer().getRuntime().loadAdapter(IJBossServerRuntime.class, null);
- if( runtime != null ) {
- location = IConstants.SERVER + IPath.SEPARATOR + runtime.getJBossConfiguration();
- }
- }
- if( location == null )
- location = iserver.getRuntime().getLocation().toOSString();
-
- if (location != null) {
- FilesetDialog d = new FilesetDialog(new Shell(), location, iserver);
- if (d.open() == Window.OK) {
- Fileset fs = d.getFileset();
- wrapper.addFileset(fs);
- actionSite.getStructuredViewer().refresh(wrapper);
- }
- }
- }
- };
- createFilter.setText(Messages.FilesetsCreateFilter);
-
- deleteFilter = new Action() {
- public void run() {
- Fileset fs = (Fileset)selected[0];
- ServerWrapper wrapper = getServerWrapper(fs);
- if( wrapper != null ) {
- wrapper.removeFileset(fs);
- actionSite.getStructuredViewer().refresh(wrapper);
- }
- }
- };
- deleteFilter.setText(Messages.FilesetsDeleteFilter);
-
- editFilter = new Action() {
- public void run() {
- Fileset sel = (Fileset)selected[0];
- ServerWrapper wrapper = getServerWrapper(sel);
- FilesetDialog d = new FilesetDialog(new Shell(), sel);
- if (d.open() == Window.OK) {
- Fileset ret = d.getFileset();
- sel.setName(ret.getName());
- sel.setFolder(ret.getRawFolder());
- sel.setIncludesPattern(ret.getIncludesPattern());
- sel.setExcludesPattern(ret.getExcludesPattern());
- wrapper.saveFilesets();
- actionSite.getStructuredViewer().refresh(wrapper);
- }
- }
- };
- editFilter.setText(Messages.FilesetsEditFilter);
-
- deleteFileAction = new Action() {
- public void run() {
- try {
- Shell shell = Display.getCurrent().getActiveShell();
- File[] files = getSelectedFiles();
- MessageBox mb = new MessageBox(shell, SWT.ICON_QUESTION
- | SWT.OK | SWT.CANCEL);
- mb.setText(Messages.DeleteFiles);
- mb.setMessage(Messages.DeleteFilesMessage);
- if (mb.open() == SWT.OK) {
- for (int i = 0; i < files.length; i++)
- FileUtil.safeDelete(files[i]);
- refreshViewer();
- }
- } catch (Exception e) {
- }
- }
- };
- deleteFileAction.setText(Messages.FilesetsDeleteFile);
-
- editFileAction = new Action() {
- public void run() {
- File[] files = getSelectedFiles();
- IWorkbench wb = PlatformUI.getWorkbench();
- IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
- IWorkbenchPage page = win.getActivePage();
- for (int i = 0; i < files.length; i++) {
- try {
- IFile eclipseFile = ResourcesPlugin.getWorkspace()
- .getRoot().getFileForLocation(
- new Path(files[i].getAbsolutePath()));
- IFileStore fileStore = EFS.getLocalFileSystem()
- .fromLocalFile(files[i]);
- if (eclipseFile != null) {
- IEditorInput input = new FileEditorInput(
- eclipseFile);
- IEditorDescriptor desc = PlatformUI.getWorkbench()
- .getEditorRegistry().getDefaultEditor(
- files[i].getName());
- if (desc != null)
- page.openEditor(input, desc.getId());
- } else if (fileStore != null) {
- IEditorInput input = new FileStoreEditorInput(
- fileStore);
- IEditorDescriptor desc = PlatformUI.getWorkbench()
- .getEditorRegistry().getDefaultEditor(
- files[i].getName());
- if (desc != null)
- page.openEditor(input, desc.getId());
- }
- } catch (Exception e) {
- IStatus status = new Status(IStatus.ERROR,
- JBossServerUIPlugin.PLUGIN_ID,
- Messages.FilesetsCannotOpenFile, e);
- JBossServerUIPlugin.getDefault().getLog().log(status);
- }
- }
- }
- };
- editFileAction.setText(Messages.FilesetsEditFile);
- }
-
- protected void refreshViewer() {
- actionSite.getStructuredViewer().refresh();
- }
-
- public void doubleClick(DoubleClickEvent event) {
- setSelection();
- editFileAction.run();
- }
-
-}
\ No newline at end of file
Deleted: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetContentProvider.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetContentProvider.java 2009-07-29 16:52:11 UTC (rev 16877)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetContentProvider.java 2009-07-29 18:42:53 UTC (rev 16878)
@@ -1,321 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.ide.eclipse.archives.webtools.ui;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.tools.ant.BuildException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.wst.server.core.IServer;
-import org.jboss.ide.eclipse.archives.core.asf.DirectoryScanner;
-import org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.extensions.descriptors.XPathCategory;
-import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
-import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
-import org.jboss.tools.jmx.core.IMemento;
-import org.jboss.tools.jmx.core.util.XMLMemento;
-
-public class FilesetContentProvider implements ITreeContentProvider {
- private static final String FILESET_KEY = "org.jboss.ide.eclipse.as.ui.views.server.providers.FilesetViewProvider.PropertyKey"; //$NON-NLS-1$
- private static final String FILESET_FILE_NAME = "filesets.xml"; //$NON-NLS-1$
-
- public static class PathWrapper {
- private IPath path;
- private IPath folder;
-
- public PathWrapper(IPath path, IPath folder) {
- this.path = path;
- this.folder = folder;
- }
-
- public IPath getFolder() {
- return folder;
- }
-
- public IPath getPath() {
- return folder.append(path);
- }
-
- public String getLocalizedResourceName() {
- return path.toOSString();
- }
-
- public boolean equals(Object o) {
- return o == null ? false :
- !(o instanceof PathWrapper) ? false :
- ((PathWrapper)o).folder.equals(folder) && ((PathWrapper)o).path.equals(path);
- }
-
- public int hashCode() {
- return path.hashCode() + folder.hashCode();
- }
- }
-
- public static class FolderWrapper extends PathWrapper {
- private HashMap<String, FolderWrapper> childrenFolders;
- private ArrayList<PathWrapper> children;
-
- public FolderWrapper(IPath path, IPath folder) {
- super(path, folder);
- children = new ArrayList<PathWrapper>();
- childrenFolders = new HashMap<String, FolderWrapper>();
- }
-
- public void addChild(IPath path) {
- if (path.segmentCount() == 1) {
- children.add(new PathWrapper(path, getFolder().append(
- getLocalizedResourceName())));
- } else {
- addPath(children, childrenFolders, path, getFolder().append(
- getLocalizedResourceName()));
- }
- }
-
- public Object[] getChildren() {
- return children.toArray(new Object[children.size()]);
- }
-
- private void addPath(ArrayList<PathWrapper> children,
- HashMap<String, FolderWrapper> folders, IPath path, IPath folder) {
- try {
- FolderWrapper fw = null;
- if (!folders.containsKey(path.segment(0))) {
- fw = new FolderWrapper(path.removeLastSegments(path
- .segmentCount() - 1), folder);
- folders.put(path.segment(0), fw);
- children.add(fw);
- } else {
- fw = folders.get(path.segment(0));
- }
- fw.addChild(path.removeFirstSegments(1));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- public class ServerWrapper {
- public IServer server;
- private Fileset[] children;
-
- public ServerWrapper(IServer server) {
- this.server = server;
- }
-
- public int hashCode() {
- return server.getId().hashCode();
- }
-
- public boolean equals(Object other) {
- return other instanceof ServerWrapper
- && ((ServerWrapper) other).server.getId().equals(
- server.getId());
- }
-
- public void addFileset(Fileset fs) {
- Fileset[] filesetsNew = new Fileset[children.length + 1];
- System.arraycopy(children, 0, filesetsNew, 0, children.length);
- filesetsNew[filesetsNew.length - 1] = fs;
- children = filesetsNew;
- saveFilesets();
- }
-
- public void removeFileset(Fileset fs) {
- ArrayList<Fileset> asList = new ArrayList<Fileset>(Arrays
- .asList(children));
- asList.remove(fs);
- children = asList.toArray(new Fileset[asList.size()]);
- saveFilesets();
- }
-
- public Fileset[] getFilesets() {
- if (children == null)
- children = loadFilesets();
- return children;
- }
-
- private Fileset[] loadFilesets() {
- if( getFile(server).exists()) {
- return FilesetContentProvider.loadFilesets(server);
- } else {
- return loadFilesets_LEGACY();
- }
- }
-
- @Deprecated
- private Fileset[] loadFilesets_LEGACY() {
- Fileset[] filesets = new Fileset[0];
- if (server != null) {
- ServerAttributeHelper helper = ServerAttributeHelper
- .createHelper(server);
- List<String> tmp = (ArrayList<String>)helper.getAttribute(FILESET_KEY, new ArrayList<String>());
- String[] asStrings = (String[]) tmp.toArray(new String[tmp
- .size()]);
- filesets = new Fileset[asStrings.length];
- for (int i = 0; i < asStrings.length; i++) {
- filesets[i] = new Fileset(asStrings[i]);
- filesets[i].setServer(server);
- }
- }
- return filesets;
- }
-
- public void saveFilesets() {
- FilesetContentProvider.saveFilesets(server, children);
- }
- }
-
- protected static Fileset[] loadFilesets(IServer server) {
- Fileset[] filesets = null;
- try {
- File file = getFile(server);
- XMLMemento memento = XMLMemento.createReadRoot(new FileInputStream(file));
- IMemento[] categoryMementos = memento.getChildren("fileset");//$NON-NLS-1$
- filesets = new Fileset[categoryMementos.length];
- String name, folder, includes, excludes;
- for( int i = 0; i < categoryMementos.length; i++ ) {
- name = categoryMementos[i].getString("name"); //$NON-NLS-1$
- folder = categoryMementos[i].getString("folder");//$NON-NLS-1$
- includes = categoryMementos[i].getString("includes");//$NON-NLS-1$
- excludes = categoryMementos[i].getString("excludes");//$NON-NLS-1$
- filesets[i] = new Fileset(name, folder, includes, excludes);
- filesets[i].setServer(server);
- }
- } catch( IOException ioe) {
- // TODO LOG
- }
- return filesets == null ? new Fileset[] { } : filesets;
- }
-
- protected static void saveFilesets(IServer server, Fileset[] sets) {
- if( server != null ) {
- XMLMemento memento = XMLMemento.createWriteRoot("filesets"); //$NON-NLS-1$
- for( int i = 0; i < sets.length; i++ ) {
- XMLMemento child = (XMLMemento)memento.createChild("fileset");//$NON-NLS-1$
- child.putString("name", sets[i].getName());//$NON-NLS-1$
- child.putString("folder", sets[i].getRawFolder());//$NON-NLS-1$
- child.putString("includes", sets[i].getIncludesPattern());//$NON-NLS-1$
- child.putString("excludes", sets[i].getExcludesPattern());//$NON-NLS-1$
- }
- try {
- memento.save(new FileOutputStream(getFile(server)));
- } catch( IOException ioe) {
- // TODO LOG
- }
- }
- }
-
- protected static File getFile(IServer server) {
- return JBossServerCorePlugin.getServerStateLocation(server)
- .append(FILESET_FILE_NAME).toFile();
- }
-
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof IServer) {
- return new Object[] { new ServerWrapper((IServer) parentElement) };
- }
- if (parentElement instanceof ServerWrapper) {
- return ((ServerWrapper) parentElement).getFilesets();
- } else if (parentElement instanceof Fileset) {
- Fileset fs = (Fileset) parentElement;
- IPath[] paths = null;
- try {
- paths = findPaths(fs.getFolder(), fs.getIncludesPattern(), fs
- .getExcludesPattern());
- } catch (BuildException be) {
- return new Object[] {};
- }
-
- HashMap<String, FolderWrapper> folders = new HashMap<String, FolderWrapper>();
- ArrayList<PathWrapper> wrappers = new ArrayList<PathWrapper>();
- for (int i = 0; i < paths.length; i++) {
- if (paths[i].segmentCount() == 1) {
- wrappers.add(new PathWrapper(paths[i], new Path(fs
- .getFolder())));
- } else {
- addPath(wrappers, folders, paths[i], new Path(fs
- .getFolder()));
- }
- }
- return wrappers.toArray(new Object[wrappers.size()]);
- } else if (parentElement instanceof FolderWrapper) {
- return ((FolderWrapper) parentElement).getChildren();
- }
- return new Object[0];
- }
-
- public Object getParent(Object element) {
- return null;
- }
-
- public boolean hasChildren(Object element) {
- return getChildren(element).length > 0 ? true : false;
- }
-
- public Object[] getElements(Object inputElement) {
- return null;
- }
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- private IPath[] findPaths(String dir, String includes, String excludes) {
- IPath[] paths = new IPath[0];
- try {
- if (dir != null) {
- DirectoryScanner scanner = DirectoryScannerFactory
- .createDirectoryScanner(dir, null, includes, excludes,
- null, false, 1, true);
- if (scanner != null) {
- String[] files = scanner.getIncludedFiles();
- paths = new IPath[files.length];
- for (int i = 0; i < files.length; i++) {
- paths[i] = new Path(files[i]);
- }
- }
- }
- } catch (IllegalStateException ise) {
- }
- return paths;
- }
-
- private static void addPath(ArrayList<PathWrapper> children,
- HashMap<String, FolderWrapper> folders, IPath path, IPath folder) {
- try {
- FolderWrapper fw = null;
- if (!folders.containsKey(path.segment(0))) {
- fw = new FolderWrapper(path.removeLastSegments(path
- .segmentCount() - 1), folder);
- folders.put(path.segment(0), fw);
- children.add(fw);
- } else {
- fw = folders.get(path.segment(0));
- }
- fw.addChild(path.removeFirstSegments(1));
- } catch (Exception e) {
- // ignore
- }
- }
-}
\ No newline at end of file
Deleted: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetDialog.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetDialog.java 2009-07-29 16:52:11 UTC (rev 16877)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetDialog.java 2009-07-29 18:42:53 UTC (rev 16878)
@@ -1,237 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.ide.eclipse.archives.webtools.ui;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.FillLayout;
-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.DirectoryDialog;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.wst.server.core.IServer;
-import org.jboss.ide.eclipse.archives.core.asf.DirectoryScanner;
-import org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory;
-import org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory.DirectoryScannerExtension.FileWrapper;
-import org.jboss.ide.eclipse.archives.ui.util.composites.FilesetPreviewComposite;
-import org.jboss.ide.eclipse.archives.webtools.Messages;
-
-public class FilesetDialog extends TitleAreaDialog {
- protected Fileset fileset;
- private String name, dir, includes, excludes;
- private Button browse;
- private Text includesText, excludesText, folderText, nameText;
- private Composite main;
- private FilesetPreviewComposite preview;
- private IServer server;
- protected FilesetDialog(Shell parentShell, String defaultLocation, IServer server) {
- super(parentShell);
- this.fileset = new Fileset();
- this.fileset.setFolder(defaultLocation);
- this.fileset.setServer(server);
- this.fileset.setIncludesPattern("**/*.xml"); //$NON-NLS-1$
- this.server = server;
- }
- protected FilesetDialog(Shell parentShell, Fileset fileset) {
- super(parentShell);
- this.fileset = (Fileset)fileset.clone();
- this.server = fileset.getServer();
- }
- protected Point getInitialSize() {
- //return new Point(400, 150);
- Point p = super.getInitialSize();
- return new Point(500, p.y);
- }
- protected int getShellStyle() {
- return super.getShellStyle() | SWT.RESIZE;
- }
-
- protected void configureShell(Shell shell) {
- super.configureShell(shell);
- shell.setText(Messages.FilesetsNewFileset);
- }
-
- protected Control createDialogArea(Composite parent) {
- setTitle(Messages.FilesetsDialogTitle);
- setMessage(Messages.FilesetsDialogMessage);
-
- Composite sup = (Composite) super.createDialogArea(parent);
- main = new Composite(sup, SWT.NONE);
- main.setLayout(new GridLayout(3, false));
- main.setLayoutData(new GridData(GridData.FILL_BOTH));
- fillArea(main);
-
- nameText.setText(fileset.getName());
- folderText.setText(fileset.getRawFolder());
- includesText.setText(fileset.getIncludesPattern());
- excludesText.setText(fileset.getExcludesPattern());
-
- addListeners();
- getShell().layout();
- textModified();
- return sup;
- }
-
- protected void addListeners() {
- ModifyListener mListener = new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- textModified();
- }
- };
- nameText.addModifyListener(mListener);
- folderText.addModifyListener(mListener);
- includesText.addModifyListener(mListener);
- excludesText.addModifyListener(mListener);
-
- browse.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- public void widgetSelected(SelectionEvent e) {
- DirectoryDialog d = new DirectoryDialog(new Shell());
- String txt = folderText.getText();
- if( !new Path(txt).isAbsolute() && server != null && server.getRuntime() != null)
- txt = server.getRuntime().getLocation().append(txt).toString();
- d.setFilterPath(txt);
- String x = d.open();
- if( x != null ) {
- folderText.setText(makeRelative(x));
- }
- }
- });
- }
-
- protected String makeRelative(String path) {
- if( server != null && server.getRuntime() != null ) {
- if( server.getRuntime().getLocation().isPrefixOf(new Path(path))) {
- String p2 = path.substring(server.getRuntime().getLocation().toString().length());
- return new Path(p2).makeRelative().toString();
- }
- }
- return path;
- }
-
- protected void textModified() {
- name = nameText.getText();
- dir = folderText.getText();
- includes = includesText.getText();
- excludes = excludesText.getText();
- fileset.setName(name);
- fileset.setFolder(dir);
- fileset.setIncludesPattern(includes);
- fileset.setExcludesPattern(excludes);
- updatePreview();
- }
- protected void fillArea(Composite main) {
- Label nameLabel = new Label(main, SWT.NONE);
- nameLabel.setText(Messages.FilesetsNewName);
-
- nameText = new Text(main, SWT.BORDER);
- nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
-
- Label folderLabel = new Label(main, SWT.NONE);
- folderLabel.setText(Messages.FilesetsNewRootDir);
-
- folderText = new Text(main, SWT.BORDER);
- folderText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
- browse = new Button(main, SWT.PUSH);
- browse.setText(Messages.FilesetsNewBrowse);
-
- Label includesLabel = new Label(main, SWT.NONE);
- includesLabel.setText(Messages.FilesetsNewIncludes);
-
- includesText = new Text(main, SWT.BORDER);
- includesText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
-
- Label excludeLabel= new Label(main, SWT.NONE);
- excludeLabel.setText(Messages.FilesetsNewExcludes);
-
- excludesText = new Text(main, SWT.BORDER);
- excludesText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
-
- Group previewWrapper = new Group(main, SWT.NONE);
-
- previewWrapper.setLayout(new GridLayout());
-
- GridData data = new GridData(GridData.FILL_BOTH);
- data.grabExcessHorizontalSpace = true;
- data.grabExcessVerticalSpace = true;
- data.horizontalSpan = 3;
- data.minimumHeight = 200;
-
- previewWrapper.setLayoutData(data);
- previewWrapper.setText(Messages.FilesetsNewPreview);
-
- previewWrapper.setLayout(new FillLayout());
- preview = new FilesetPreviewComposite(previewWrapper, SWT.NONE);
- }
-
- private void updatePreview() {
- preview.setInput(findPaths(fileset.getFolder(), includes, excludes));
- }
-
- public String getDir() {
- return dir;
- }
- public String getExcludes() {
- return excludes;
- }
- public String getIncludes() {
- return includes;
- }
- public String getName() {
- return name;
- }
- public Fileset getFileset() {
- return fileset;
- }
-
-
- private static IPath[] findPaths(String dir, String includes, String excludes) {
- try {
- if( dir != null ) {
- DirectoryScanner scanner =
- DirectoryScannerFactory.createDirectoryScanner(dir, null, includes, excludes, null, false, 1, false);
- if( scanner != null ) {
- Iterator<File> i = scanner.iterator();
- ArrayList<IPath> paths2 = new ArrayList<IPath>();
- while(i.hasNext() && paths2.size() < 30) {
- FileWrapper fw = (FileWrapper)i.next();
- paths2.add(new Path(fw.getFilesetRelative()));
- }
-
- return (IPath[]) paths2.toArray(new IPath[paths2.size()]);
- }
- }
- } catch( IllegalStateException ise ) {}
- catch(Exception e) {
- e.printStackTrace();
- }
- return new IPath[]{};
- }
-
-}
\ No newline at end of file
Deleted: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetLabelProvider.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetLabelProvider.java 2009-07-29 16:52:11 UTC (rev 16877)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/ui/FilesetLabelProvider.java 2009-07-29 18:42:53 UTC (rev 16878)
@@ -1,80 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.ide.eclipse.archives.webtools.ui;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.core.runtime.content.IContentTypeManager;
-import org.eclipse.core.runtime.content.IContentTypeMatcher;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.resource.LocalResourceManager;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.PlatformUI;
-import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
-import org.jboss.ide.eclipse.archives.webtools.ui.FilesetContentProvider.FolderWrapper;
-import org.jboss.ide.eclipse.archives.webtools.ui.FilesetContentProvider.PathWrapper;
-import org.jboss.ide.eclipse.archives.webtools.ui.FilesetContentProvider.ServerWrapper;
-
-public class FilesetLabelProvider extends LabelProvider {
-
- private LocalResourceManager resourceManager;
- private Image rootImage;
- public FilesetLabelProvider() {
- super();
- this.resourceManager = new LocalResourceManager(JFaceResources.getResources());
- ImageDescriptor des = ImageDescriptor.createFromURL(IntegrationPlugin.getDefault().getBundle().getEntry("icons/multiple_files.gif")); //$NON-NLS-1$
- rootImage = des.createImage();
- }
-
- public Image getImage(Object element) {
- if( element instanceof Fileset ) {
- return PlatformUI.getWorkbench().getSharedImages()
- .getImage(ISharedImages.IMG_OBJ_FOLDER);
- } else if( element instanceof FolderWrapper ) {
- return PlatformUI.getWorkbench().getSharedImages()
- .getImage(ISharedImages.IMG_OBJ_FOLDER);
- } else if( element instanceof PathWrapper ) {
- String fileName = ((PathWrapper)element).getPath().toOSString();
- IContentTypeManager manager = Platform.getContentTypeManager();
- IContentTypeMatcher matcher = manager.getMatcher(null, null);
- IContentType contentType = matcher.findContentTypeFor(fileName);
- ImageDescriptor descriptor = PlatformUI.getWorkbench().getEditorRegistry()
- .getImageDescriptor(fileName, contentType);
- if (descriptor == null) {
- descriptor = PlatformUI.getWorkbench().getSharedImages()
- .getImageDescriptor(ISharedImages.IMG_OBJ_FILE);
- }
- return resourceManager.createImage(descriptor);
- } else if( element instanceof ServerWrapper ) {
- return rootImage;
- }
- return null;
- }
-
- public String getText(Object element) {
- if( element instanceof PathWrapper ) return ((PathWrapper)element).getLocalizedResourceName();
- if( element instanceof Fileset ) return ((Fileset)element).getName() + " " + ((Fileset)element).getRawFolder(); //$NON-NLS-1$
- if( element instanceof ServerWrapper ) return "Filesets"; //$NON-NLS-1$
- return null;
- }
-
-
- public void dispose() {
- resourceManager.dispose();
- resourceManager = null;
- rootImage.dispose();
- super.dispose();
- }
-
-}
15 years, 5 months
JBoss Tools SVN: r16877 - trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test.
by jbosstools-commits@lists.jboss.org
Author: dazarov
Date: 2009-07-29 12:52:11 -0400 (Wed, 29 Jul 2009)
New Revision: 16877
Modified:
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4495
Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java 2009-07-29 15:02:29 UTC (rev 16876)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/SeamValidatorsTest.java 2009-07-29 16:52:11 UTC (rev 16877)
@@ -133,154 +133,80 @@
assertMarkerIsCreated(project.getFile(jbide1631XHTMLFile), MARKER_TYPE, "\"foo2\" cannot be resolved", 16 );
}
- public void testDuplicateComponentName_Validator() {
- IFile bbcComponentFile = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/BbcComponent.java");
- IFile statefulComponentFile = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.java");
- IFile componentsFile = project.getFile("WebContent/WEB-INF/components.xml");
+ public void testDuplicateComponentName_Validator() throws CoreException {
+ IFile bbcComponentFile = project
+ .getFile("src/action/org/domain/SeamWebWarTestProject/session/BbcComponent.java");
- int number = getMarkersNumber(bbcComponentFile);
- assertEquals("Problem marker was found in BbcComponent.java file", 0, number);
+ String markerText = "Duplicate component name: \"abcComponent\"";
+
+ assertMarkerIsNotCreated(bbcComponentFile, MARKER_TYPE, markerText);
- number = getMarkersNumber(statefulComponentFile);
- assertEquals("Problem marker was found in StatefulComponent.java file", 0, number);
-
- number = getMarkersNumber(componentsFile);
- // Because of bug in Seam 1.2.1GA there is one error marker. See https://jira.jboss.org/jira/browse/JBIDE-4354
- assertEquals("Problem marker was found in components.xml file", 1, number);
-
// Duplicate component name
-
- IFile bbcComponentFile2 = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/BbcComponent.2");
- try{
- bbcComponentFile.setContents(bbcComponentFile2.getContents(), true, false, null);
- bbcComponentFile.touch(null);
- }catch(Exception ex){
- JUnitUtils.fail("Error in changing 'BbcComponent.java' content to " +
- "'BbcComponent.2'", ex);
- }
-
- refreshProject(project);
-
- number = getMarkersNumber(bbcComponentFile);
- assertFalse("Problem marker 'Duplicate component name' not found", number == 0);
-
- String[] messages = getMarkersMessage(bbcComponentFile, SEAM_MARKER_FILTER);
-
- assertEquals("Problem marker 'Duplicate component name' not found","Duplicate component name: \"abcComponent\"", messages[0]);
-
- Integer[] lineNumbers = getMarkersNumbersOfLine(bbcComponentFile, SEAM_MARKER_FILTER);
-
- assertEquals("Problem marker has wrong line number", 7, lineNumbers[0].intValue());
+ assertMarkerIsCreated(
+ "src/action/org/domain/SeamWebWarTestProject/session/BbcComponent.java",
+ "src/action/org/domain/SeamWebWarTestProject/session/BbcComponent.2",
+ markerText, 7);
}
- public void testStatefulComponentWithoutRemoveMethod_Validator(){
+ public void testStatefulComponentWithoutRemoveMethod_Validator() throws CoreException {
IFile statefulComponentFile = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.java");
- // Stateful component does not contain @Remove method
+ String markerText = "Stateful component \"statefulComponent\" must have a method marked @Remove";
- IFile statefulComponentFile2 = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.2");
- try{
- statefulComponentFile.setContents(statefulComponentFile2.getContents(), true, false, null);
- }catch(Exception ex){
- JUnitUtils.fail("Error in changing 'StatefulComponent.java' content to " +
- "'StatefulComponent.2'", ex);
- }
+ assertMarkerIsNotCreated(statefulComponentFile, MARKER_TYPE, markerText);
- refreshProject(project);
-
- int number = getMarkersNumber(statefulComponentFile);
- assertFalse("Problem marker 'Stateful component does not contain @Remove method' not found' not found", number == 0);
-
- String[] messages = getMarkersMessage(statefulComponentFile, SEAM_MARKER_FILTER);
- assertEquals("Problem marker 'Stateful component does not contain @Remove method' not found", "Stateful component \"statefulComponent\" must have a method marked @Remove", messages[0]);
-
- Integer[] lineNumbers = getMarkersNumbersOfLine(statefulComponentFile, SEAM_MARKER_FILTER);
-
- assertEquals("Problem marker has wrong line number", 16, lineNumbers[0].intValue());
-
+ // Stateful component does not contain @Remove method
+ assertMarkerIsCreated(
+ "src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.java",
+ "src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.2",
+ markerText, 16);
}
- public void testStatefulComponentWithoutDestroyMethod_Validator(){
+ public void testStatefulComponentWithoutDestroyMethod_Validator() throws CoreException {
IFile statefulComponentFile = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.java");
- // Stateful component does not contain @Destroy method
-
- IFile statefulComponentFile3 = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.3");
- try{
- statefulComponentFile.setContents(statefulComponentFile3.getContents(), true, false, null);
- }catch(Exception ex){
- JUnitUtils.fail("Error in changing 'StatefulComponent.java' content to " +
- "'StatefulComponent.3'", ex);
- }
+ String markerText = "Stateful component \"statefulComponent\" must have a method marked @Destroy";
- refreshProject(project);
+ assertMarkerIsNotCreated(statefulComponentFile, MARKER_TYPE, markerText);
- int number = getMarkersNumber(statefulComponentFile);
- assertFalse("Problem marker 'Stateful component does not contain @Destroy method' not found' not found' not found", number == 0);
-
- String[] messages = getMarkersMessage(statefulComponentFile, SEAM_MARKER_FILTER);
- assertEquals("Problem marker 'Stateful component does not contain @Destroy method' not found", "Stateful component \"statefulComponent\" must have a method marked @Destroy", messages[0]);
-
- Integer[] lineNumbers = getMarkersNumbersOfLine(statefulComponentFile, SEAM_MARKER_FILTER);
-
- assertEquals("Problem marker has wrong line number", 16, lineNumbers[0].intValue());
-
+ // Stateful component does not contain @Destroy method
+ assertMarkerIsCreated(
+ "src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.java",
+ "src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.3",
+ markerText, 16);
}
- public void testStatefulComponentHasWrongScope_Validator(){
+ public void testStatefulComponentHasWrongScope_Validator() throws CoreException {
IFile statefulComponentFile = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.java");
+
+ String markerText = "Stateful component \"statefulComponent\" should not have org.jboss.seam.ScopeType.PAGE, nor org.jboss.seam.ScopeType.STATELESS";
+ assertMarkerIsNotCreated(statefulComponentFile, MARKER_TYPE, markerText);
+
// Stateful component has wrong scope
- IFile statefulComponentFile4 = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.4");
- try{
- statefulComponentFile.setContents(statefulComponentFile4.getContents(), true, false, null);
- }catch(Exception ex){
- JUnitUtils.fail("Error in changing 'StatefulComponent.java' content to " +
- "'StatefulComponent.4'", ex);
- }
-
- refreshProject(project);
-
- int number = getMarkersNumber(statefulComponentFile);
- assertFalse("Problem marker 'Stateful component has wrong scope' not found' not found' not found", number == 0);
-
- String[] messages = getMarkersMessage(statefulComponentFile, SEAM_MARKER_FILTER);
- assertEquals("Problem marker 'Stateful component has wrong scope' not found", "Stateful component \"statefulComponent\" should not have org.jboss.seam.ScopeType.PAGE, nor org.jboss.seam.ScopeType.STATELESS", messages[0]);
-
- Integer[] lineNumbers = getMarkersNumbersOfLine(statefulComponentFile, SEAM_MARKER_FILTER);
-
- assertEquals("Problem marker has wrong line number", 16, lineNumbers[0].intValue());
+ assertMarkerIsCreated(
+ "src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.java",
+ "src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.4",
+ markerText, 16);
}
- public void testComponentType_Validator(){
+ public void testComponentType_Validator() throws CoreException {
IFile componentsFile = project.getFile("WebContent/WEB-INF/components.xml");
- // Component class name cannot be resolved to a type
+ String markerText = "\"org.domain.SeamWebWarTestProject.session.StateComponent\" cannot be resolved to a type";
- IFile componentsFile2 = project.getFile("WebContent/WEB-INF/components.2");
+ assertMarkerIsNotCreated(componentsFile, MARKER_TYPE, markerText);
- try{
- componentsFile.setContents(componentsFile2.getContents(), true, false, null);
- }catch(Exception ex){
- JUnitUtils.fail("Error in changing 'components.xml' content to " +
- "'components.2'", ex);
- }
+ // Component class name cannot be resolved to a type
- refreshProject(project);
-
- int number = getMarkersNumber(componentsFile);
- assertFalse("Problem marker 'Component class name cannot be resolved to a type' was not found", number == 0);
-
- String[] messages = getMarkersMessage(componentsFile, SEAM_MARKER_FILTER);
- assertEquals("Problem marker 'Component class name cannot be resolved to a type' was not found", "\"org.domain.SeamWebWarTestProject.session.StateComponent\" cannot be resolved to a type", messages[0]);
-
- Integer[] lineNumbers = getMarkersNumbersOfLine(componentsFile, SEAM_MARKER_FILTER);
-
- assertEquals("Problem marker has wrong line number", 15, lineNumbers[0].intValue());
+ assertMarkerIsCreated(
+ "WebContent/WEB-INF/components.xml",
+ "WebContent/WEB-INF/components.2",
+ markerText, 15);
}
- public void testComponentWithoutSetter_Validator(){
+ public void testComponentWithoutSetter_Validator() throws CoreException {
IFile statefulComponentFile = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/StatefulComponent.java");
IFile componentsFile = project.getFile("WebContent/WEB-INF/components.xml");
IFile bbcComponentFile = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/BbcComponent.java");
@@ -327,33 +253,19 @@
}
}
- public void testEntityHasWrongScope_Validator() {
+ public void testEntityHasWrongScope_Validator() throws CoreException {
IFile abcEntityFile = project.getFile("src/action/org/domain/SeamWebWarTestProject/entity/abcEntity.java");
- int number = getMarkersNumber(abcEntityFile);
- assertTrue("Problem marker was found in abcEntity.java", number == 0);
+ String markerText = "Entity component \"abcEntity\" should not have org.jboss.seam.ScopeType.STATELESS";
+ assertMarkerIsNotCreated(abcEntityFile, MARKER_TYPE, markerText);
+
// Entity component has wrong scope
- IFile abcEntityFile2 = project.getFile("src/action/org/domain/SeamWebWarTestProject/entity/abcEntity.2");
- try{
- abcEntityFile.setContents(abcEntityFile2.getContents(), true, false, null);
- }catch(Exception ex){
- JUnitUtils.fail("Error in changing 'abcEntity.java' content to " +
- "'abcEntity.2'", ex);
- }
-
- refreshProject(project);
-
- number = getMarkersNumber(abcEntityFile);
- assertFalse("Problem marker 'Entity component has wrong scope' was not found'", number == 0);
-
- String[] messages = getMarkersMessage(abcEntityFile, SEAM_MARKER_FILTER);
- assertEquals("Problem marker 'Entity component has wrong scope' was not found", "Entity component \"abcEntity\" should not have org.jboss.seam.ScopeType.STATELESS", messages[0]);
-
- Integer[] lineNumbers = getMarkersNumbersOfLine(abcEntityFile, SEAM_MARKER_FILTER);
-
- assertEquals("Problem marker has wrong line number", 15, lineNumbers[0].intValue());
+ assertMarkerIsCreated(
+ "src/action/org/domain/SeamWebWarTestProject/entity/abcEntity.java",
+ "src/action/org/domain/SeamWebWarTestProject/entity/abcEntity.2",
+ markerText, 15);
}
final String TARGET_FILE_NAME
@@ -506,38 +418,22 @@
assertEquals("Problem marker was found in UsualComponent.java file", 0, number);
}
- public void testFactoriesValidator() {
+ public void testFactoriesValidator() throws CoreException {
IFile component12File = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/Component12.java");
- refreshProject(project);
+ String markerText = "Factory method \"messageList2\" with a void return type must have an associated @Out/Databinder";
- int number = getMarkersNumber(component12File);
- assertEquals("Problem marker was found in Component12.java", 0, number);
-
+ assertMarkerIsNotCreated(component12File, MARKER_TYPE, markerText);
+
// Unknown factory name
- IFile component12File2 = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/Component12.2");
- try{
- component12File.setContents(component12File2.getContents(), true, false, null);
- }catch(Exception ex){
- JUnitUtils.fail("Error in changing 'Component12File2.java' content to " +
- "'Component12File2.2'", ex);
- }
+ assertMarkerIsCreated(
+ "src/action/org/domain/SeamWebWarTestProject/session/Component12.java",
+ "src/action/org/domain/SeamWebWarTestProject/session/Component12.2",
+ markerText, 24);
- refreshProject(project);
-
- number = getMarkersNumber(component12File);
- assertFalse("Problem marker 'Unknown factory name' was not found", number == 0);
-
- String[] messages = getMarkersMessage(component12File, SEAM_MARKER_FILTER);
- assertEquals("Problem marker 'Unknown factory name' was not found", "Factory method \"messageList2\" with a void return type must have an associated @Out/Databinder", messages[0]);
-
- Integer[] lineNumbers = getMarkersNumbersOfLine(component12File, SEAM_MARKER_FILTER);
-
- assertEquals("Problem marker has wrong line number", 24, lineNumbers[0].intValue());
-
- component12File2 = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/DuplicateFactory");
+ IFile component12File2 = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/DuplicateFactory");
try{
component12File.setContents(component12File2.getContents(), true, false, null);
}catch(Exception ex){
@@ -547,11 +443,11 @@
refreshProject(project);
- number = getMarkersNumber(component12File);
+ int number = getMarkersNumber(component12File);
assertEquals("Duplicate factory name markers were not found", 2, number);
}
- public void testMultipleDataBinder_Validator() {
+ public void testMultipleDataBinder_Validator() throws CoreException {
IFile selectionTestFile = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/SelectionTest.java");
IFile selectionIndexTestFile = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/SelectionIndexTest.java");
@@ -612,7 +508,7 @@
}
- public void testUnknownDataModelName_Validator(){
+ public void testUnknownDataModelName_Validator() throws CoreException {
IFile selectionTestFile = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/SelectionTest.java");
IFile selectionIndexTestFile = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/SelectionIndexTest.java");
// Unknown @DataModel/@Out name
@@ -656,7 +552,7 @@
assertEquals("Problem marker has wrong line number", 27, lineNumbers[0].intValue());
}
- public void testDuplicateVariableName_Validator() {
+ public void testDuplicateVariableName_Validator() throws CoreException {
modifyPreferences();
// IPreferenceStore store = SeamCorePlugin.getDefault().getPreferenceStore();
@@ -694,7 +590,7 @@
}
- public void testUnknownVariableName_Validator(){
+ public void testUnknownVariableName_Validator() throws CoreException {
IFile contextVariableTestFile = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/ContextVariableTest.java");
// Unknown variable name
@@ -759,7 +655,7 @@
assertEquals("Problem marker has wrong line number", 22, lineNumbers[0].intValue());
}
- public void testPropertyCannotBeResolved_Validator(){
+ public void testPropertyCannotBeResolved_Validator() throws CoreException {
IFile abcComponentXHTMLFile = project.getFile("WebContent/abcComponent.xhtml");
// Property cannot be resolved
@@ -786,7 +682,7 @@
assertEquals("Problem marker has wrong line number", 22, lineNumbers[0].intValue());
}
- public void testUnpairedGetterOrSetter_Validator(){
+ public void testUnpairedGetterOrSetter_Validator() throws CoreException {
IFile abcComponentXHTMLFile = project.getFile("WebContent/abcComponent.xhtml");
IFile abcComponentFile = project.getFile("src/action/org/domain/SeamWebWarTestProject/session/AbcComponent.java");
15 years, 5 months
JBoss Tools SVN: r16876 - trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar.
by jbosstools-commits@lists.jboss.org
Author: yradtsevich
Date: 2009-07-29 11:02:29 -0400 (Wed, 29 Jul 2009)
New Revision: 16876
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/SelectionBar.java
Log:
issue JBIDE-4029: Make selection bar scrollable for tags and their parents
https://jira.jboss.org/jira/browse/JBIDE-4029
- performance improvements
- drop down button image changed
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/SelectionBar.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/SelectionBar.java 2009-07-29 14:59:15 UTC (rev 16875)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/selbar/SelectionBar.java 2009-07-29 15:02:29 UTC (rev 16876)
@@ -17,8 +17,13 @@
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
@@ -26,8 +31,8 @@
import org.eclipse.swt.layout.FormLayout;
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.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
@@ -36,6 +41,8 @@
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
+import org.eclipse.ui.internal.WorkbenchImages;
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapter;
import org.eclipse.wst.sse.core.internal.provisional.INodeNotifier;
import org.jboss.tools.common.meta.XAttribute;
@@ -55,26 +62,28 @@
* This class create and manage the Selection Bar under the VPE.
* Entry point from the class MozilaEditor This bar can be hiden and
* shown it uses splitter for this.
- *
+ *
* @author erick
+ * @author yradtsevich
*/
-
public class SelectionBar implements SelectionListener {
- private Splitter splitter;
+ /**
+ *
+ */
+ private static final int SEL_ITEM_RIGHT_MARGIN = 5;
+ private Splitter splitter;
+
private boolean resizeListenerAdded = false;
-
private VpeController vpeController = null;
-
private ToolBar selBar = null;
- private ToolBar closeSelectionBar = null;
-
+ private FormData selBarData;
+// private Composite closeBar = null;
+ private Menu dropDownMenu = null;
private int itemCount = 0;
-
+// private Composite arrowBar;
private Composite cmpToolBar = null;
private Composite cmpTlEmpty = null;
- private Composite closeBar = null;
-
private List<VisibilityListener> visibilityListeners = new ArrayList<VisibilityListener>(1);
/**
@@ -82,16 +91,12 @@
*/
private boolean visible;
- private ToolItem dropDownItem;
+ private ImageButton arrowButton;
- private Button arrowButton;
+// private ToolItem arrowButton;
- private Menu dropDownMenu;
-
- //Listener selbarListener = null;
-
- final static String PREFERENCE_YES = "yes"; //$NON-NLS-1$
+ final static String PREFERENCE_YES = "yes"; //$NON-NLS-1$
final static String PREFERENCE_NO = "no"; //$NON-NLS-1$
public Composite createToolBarComposite(Composite parent, boolean visible) {
@@ -101,6 +106,7 @@
* The empty composite
*/
cmpTlEmpty = new Composite(splitter, SWT.NONE) {
+ @Override
public Point computeSize(int wHint, int hHint, boolean changed) {
Point point = super.computeSize(wHint, hHint, changed);
point.y = 1;
@@ -114,37 +120,21 @@
cmpToolBar = new Composite(splitter, SWT.NONE);
cmpToolBar.setLayout(new FormLayout());
- GridLayout layoutTl = new GridLayout(1, false);
- layoutTl.marginBottom = 0;
- layoutTl.marginHeight = 0;
- layoutTl.marginWidth = 0;
- layoutTl.verticalSpacing = 0;
- layoutTl.horizontalSpacing = 0;
+ final Image closeImage = PlatformUI.getWorkbench().getSharedImages()
+ .getImage(ISharedImages.IMG_TOOL_DELETE);
- closeBar = new Composite(cmpToolBar, SWT.NONE);
- FormData closeBarData = new FormData();
- closeBarData.right = new FormAttachment(100);
- closeBarData.top = new FormAttachment(0);
- closeBar.setLayout(layoutTl);
- closeBar.setLayoutData(closeBarData);
-
- closeSelectionBar = new ToolBar(closeBar, SWT.HORIZONTAL | SWT.FLAT);
- ToolItem closeItem = new ToolItem(closeSelectionBar, SWT.FLAT);
- closeItem.setImage(PlatformUI.getWorkbench().getSharedImages()
- .getImage(ISharedImages.IMG_TOOL_DELETE));
- closeItem.setToolTipText(VpeUIMessages.HIDE_SELECTION_BAR);
- closeItem.addListener(SWT.Selection, new Listener() {
+ final Listener closeListener = new Listener() {
public void handleEvent(Event event) {
if (!getHideWithoutPromptOption()) {
MessageDialogWithToggle dialog = MessageDialogWithToggle
- .openOkCancelConfirm(
- PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow()
- .getShell(),
- VpeUIMessages.CONFIRM_SELECTION_BAR_DIALOG_TITLE,
- VpeUIMessages.CONFIRM_SELECTION_BAR_DIALOG_MESSAGE,
- VpeUIMessages.CONFIRM_SELECTION_BAR_DIALOG_TOGGLE_MESSAGE,
- false, null, null);
+ .openOkCancelConfirm(
+ PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow()
+ .getShell(),
+ VpeUIMessages.CONFIRM_SELECTION_BAR_DIALOG_TITLE,
+ VpeUIMessages.CONFIRM_SELECTION_BAR_DIALOG_MESSAGE,
+ VpeUIMessages.CONFIRM_SELECTION_BAR_DIALOG_TOGGLE_MESSAGE,
+ false, null, null);
if (dialog.getReturnCode() != IDialogConstants.OK_ID) {
return;
}
@@ -156,15 +146,26 @@
setAlwaysVisibleOption(false);
setVisible(false);
}
+ };
- });
+ ImageButton closeButton = new ImageButton(cmpToolBar, closeImage,
+ VpeUIMessages.HIDE_SELECTION_BAR);
+ closeButton.addSelectionListener(closeListener);
+ FormData closeBarData = new FormData();
+ closeBarData.right = new FormAttachment(100);
+ closeBarData.top = new FormAttachment(0);
+ Composite closeItemComposite = closeButton.getComposite();
+ closeItemComposite.setLayoutData(closeBarData);
+
// Create selection bar
- selBar = new ToolBar(cmpToolBar, SWT.HORIZONTAL | SWT.FLAT);
- FormData selBarData = new FormData(SWT.DEFAULT, SWT.DEFAULT);
+ selBar = new ToolBar(cmpToolBar, SWT.HORIZONTAL | SWT.FLAT | SWT.NO_BACKGROUND);
+ selBarData = new FormData();
selBarData.left = new FormAttachment(0);
- selBarData.right = new FormAttachment(closeBar, 0, SWT.LEFT);
+ selBarData.right = new FormAttachment(closeItemComposite, 0, SWT.LEFT);
selBarData.top = new FormAttachment(0);
selBar.setLayoutData(selBarData);
+ createArrowButton();
+ cmpToolBar.layout();
setVisible(visible);
return splitter;
@@ -176,7 +177,7 @@
/*
* Fixes http://jira.jboss.com/jira/browse/JBIDE-2298
- * To get stored in xml XModelObject
+ * To get stored in xml XModelObject
* should be marked as modified.
*/
optionsObject.setModified(true);
@@ -215,7 +216,7 @@
setPersistentOption(VpePreference.ATT_ALWAYS_HIDE_SELECTION_BAR_WITHOUT_PROMT,
optionValue);
}
-
+
public boolean getHideWithoutPromptOption() {
return VpePreference.ALWAYS_HIDE_SELECTION_BAR_WITHOUT_PROMT
.getValue().equals(PREFERENCE_YES);
@@ -249,22 +250,22 @@
/**
* Adds the listener to the collection of listeners who will
* be notified when the {@code #visible} state is changed.
- *
+ *
* @param listener the listener which should be notified
- *
+ *
* @see VisibilityListener
* @see VisibilityEvent
*/
public void addVisibilityListener(VisibilityListener listener) {
visibilityListeners.add(listener);
}
-
+
/**
* Removes the listener from the collection of listeners who will
* be notified when the {@link #visible} state is changed.
- *
+ *
* @param listener the listener which should be removed
- *
+ *
* @see VisibilityListener
*/
public void removeVisibilityListener(VisibilityListener listener) {
@@ -274,7 +275,7 @@
/**
* Fires all registered instances of {@code VisibilityListener} by
* sending them {@link VisibilityEvent}.
- *
+ *
* @see #addVisibilityListener(VisibilityListener)
* @see #removeVisibilityListener(VisibilityListener)
*/
@@ -289,6 +290,10 @@
this.vpeController = vpeController;
}
+ /**
+ * Updates buttons in the selection bar and the drop-down menu
+ * according to the source selection.
+ */
public void updateNodes() {
VpeSourceSelectionBuilder sourceSelectionBuilder = new VpeSourceSelectionBuilder(
vpeController.getSourceEditor());
@@ -306,34 +311,49 @@
removeNodeListenerFromAllNodes();
cleanToolBar(selBar);
+ disposeDropDownMenu();
+ // for now dropDownMenu = null
+
int elementCounter = 0;
- while (node != null
+ while (node != null
&& (node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.COMMENT_NODE)) {
addNodeListenerTo(node);
- ToolItem item = new ToolItem(selBar, SWT.FLAT, 0);
- item.addSelectionListener(this);
- item.setData(node);
- item.setText(node.getNodeName());
+ if (dropDownMenu == null) {
+ ToolItem item = new ToolItem(selBar, SWT.FLAT, 1);
+ item.addSelectionListener(this);
+ item.setData(node);
+ item.setText(node.getNodeName());
+ if (!isItemShown(selBar.getItem(elementCounter + 1))) {
+ item.dispose();
+ dropDownMenu = new Menu(selBar);
+ }
+ }
+
+ if (dropDownMenu != null) {
+ MenuItem menuItem = new MenuItem(dropDownMenu, SWT.PUSH, 0);
+ menuItem.addSelectionListener(this);
+ menuItem.setText(node.getNodeName());
+ menuItem.setData(node);
+ }
+
elementCounter++;
node = node.getParentNode();
}
+ itemCount = elementCounter;
+ arrowButton.setEnabled(dropDownMenu != null);
+
if (node != null && node.getNodeType() == Node.DOCUMENT_NODE) {
addNodeListenerTo(node);
}
- itemCount = elementCounter;
- cmpToolBar.layout();
// bug was fixed when toolbar are not shown for resizeble components
cmpToolBar.layout();
splitter.getParent().layout(true, true);
- deleteArrow();
- addArrowIfNecessary();
-
if (!resizeListenerAdded ) {
- selBar.addListener(SWT.Resize, new Listener() {
+ cmpToolBar.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event event) {
updateNodes();
}
@@ -343,76 +363,57 @@
}
/**
- * Deletes all items from {@code #toolBar}.
+ * Deletes all items (except the first item-arrow button)
+ * from the given {@code #toolBar}.
*/
private void cleanToolBar(ToolBar toolBar) {
ToolItem[] oldItems = toolBar.getItems();
- for (ToolItem oldItem : oldItems) {
- oldItem.dispose();
+ for (int i = 1; i < oldItems.length; i++) {
+ oldItems[i].dispose();
}
}
- /**
- * Deletes the {@link #arrowButton} with drop-down menu if it is existing.
- */
- private void deleteArrow() {
- if (dropDownMenu != null) {
- dropDownMenu.dispose();
- dropDownMenu = null;
- }
- if (dropDownItem != null) {
- dropDownItem.dispose();
- dropDownItem = null;
- }
- if (arrowButton != null) {
- arrowButton.dispose();
- arrowButton = null;
- }
- }
-
- /**
- * Adds {@link #arrowButton} with drop-down menu if there are
- * invisible items in the {@link #selBar}.
- * <P>
- * It is assumed that the arrow is not existing at the entry point.
+ /**
+ * Initializes {@link #arrowButton}.
*/
- private void addArrowIfNecessary() {
- ToolItem[] items = selBar.getItems();
+ private void createArrowButton() {
+ final Image hoverImage = WorkbenchImages.getImage(
+ IWorkbenchGraphicConstants.IMG_LCL_RENDERED_VIEW_MENU);
- if (items.length == 0 || isItemShown(items[items.length - 1])) {
- // the arrow is not necessary
- return;
- }
+ arrowButton = new ImageButton(selBar, hoverImage,
+ VpeUIMessages.SelectionBar_MoreNodes);
+ arrowButton.setEnabled(false);
+ arrowButton.addSelectionListener(
+ new Listener() {
+ public void handleEvent(Event event) {
+ Rectangle bounds = arrowButton.getButtonBounds();
+ Point point = selBar.toDisplay(bounds.x, bounds.y
+ + bounds.height);
+ dropDownMenu.setLocation(point);
+ dropDownMenu.setVisible(true);
+ }
+ });
- dropDownItem = new ToolItem(selBar, SWT.SEPARATOR, 0);
- arrowButton = new Button(selBar, SWT.ARROW | SWT.DOWN);
- arrowButton.setToolTipText(VpeUIMessages.SelectionBar_MoreNodes);
- arrowButton.pack();
- dropDownItem.setWidth(arrowButton.getSize().x);
- dropDownItem.setControl(arrowButton);
- dropDownMenu = new Menu(selBar);
- for (int i = 0; i < items.length
- && !isItemShown(items[items.length - 1]); i++) {
- MenuItem menuItem = new MenuItem(dropDownMenu, SWT.PUSH);
- menuItem.setText(items[i].getText());
- menuItem.setData(items[i].getData());
- menuItem.addSelectionListener(this);
- items[i].dispose();
- }
- arrowButton.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event event) {
- Rectangle bounds = dropDownItem.getBounds();
- Point point = selBar.toDisplay(bounds.x, bounds.y
- + bounds.height);
- dropDownMenu.setLocation(point);
- dropDownMenu.setVisible(true);
- }
- });
+ ToolItem arrowItem = new ToolItem(selBar, SWT.SEPARATOR, 0);
+ Composite arrowButtonComposite = arrowButton.getComposite();
+ arrowItem.setControl(arrowButtonComposite);
+ arrowButtonComposite.pack();
+ arrowItem.setWidth(arrowButtonComposite.getSize().x);
+
+ FormData arrowToolBarData = new FormData();
+ arrowToolBarData.left = new FormAttachment(0);
+ arrowToolBarData.top = new FormAttachment(0);
+ arrowButtonComposite.setLayoutData(arrowToolBarData);
}
+ /**
+ * Checks if the given {@code toolItem} is fully shown on the screen.
+ */
private boolean isItemShown(ToolItem toolItem) {
ToolBar toolBar = toolItem.getParent();
Rectangle toolItemBounds = toolItem.getBounds();
+
+ toolItemBounds.width += SEL_ITEM_RIGHT_MARGIN;
Rectangle intersection = toolBar.getBounds().intersection(
toolItemBounds);
return intersection.equals(toolItemBounds);
@@ -420,17 +421,17 @@
/**
* List of nodes that are notifying {@link #nodeListener} when they are
- * changed.
+ * changed.
*/
private List<INodeNotifier> nodeNotifiers = new ArrayList<INodeNotifier>();
/**
- * Listener for all {@link #nodeNotifiers}
+ * Listener for all {@link #nodeNotifiers}
*/
private NodeListener nodeListener = new NodeListener(this);
-
+
/**
* Adds {@link #nodeListener} to the given {@code node}.
- *
+ *
* @param node the node to that the listener must be added.
*/
private void addNodeListenerTo(Node node) {
@@ -443,7 +444,7 @@
}
}
/**
- * Removes {@link #nodeListener} from all nodes associated with this {@code SelectionBar}.
+ * Removes {@link #nodeListener} from all nodes associated with this {@code SelectionBar}.
*/
private void removeNodeListenerFromAllNodes() {
for (INodeNotifier notifier : nodeNotifiers) {
@@ -455,30 +456,24 @@
public void dispose() {
removeNodeListenerFromAllNodes();
- if (!selBar.isDisposed()) {
- for (int i = 0; i < selBar.getItemCount(); i++) {
- if (!selBar.getItem(i).isDisposed()) {
- selBar.getItem(i).removeSelectionListener(this);
- }
- }
- selBar.dispose();
- selBar = null;
- }
- if (!closeSelectionBar.isDisposed()) {
- for (int i = 0; i < closeSelectionBar.getItemCount(); i++) {
- if (!closeSelectionBar.getItem(i).isDisposed()) {
- closeSelectionBar.getItem(i).removeSelectionListener(this);
- }
- }
- closeSelectionBar.dispose();
- closeSelectionBar = null;
- }
if (splitter != null) {
splitter.dispose();
splitter = null;
}
+
+ disposeDropDownMenu();
}
+ /**
+ * Disposes {@link #dropDownMenu}.
+ */
+ private void disposeDropDownMenu() {
+ if (dropDownMenu != null) {
+ dropDownMenu.dispose();
+ dropDownMenu = null;
+ }
+ }
+
public void widgetSelected(SelectionEvent e) {
SelectionUtil.setSourceSelection(vpeController.getPageContext(),
(Node) e.widget.getData());
@@ -489,7 +484,7 @@
/**
* Performs storing model object in the model and xml file.
- *
+ *
* @param xmo the model object to store
*/
private void performStore(XModelObject xmo) {
@@ -497,7 +492,7 @@
|| null == xmo.getModelEntity()) {
return;
}
-
+
ArrayList<IModelPropertyEditorAdapter> adapters = new ArrayList<IModelPropertyEditorAdapter>();
XAttribute[] attribute = xmo.getModelEntity().getAttributes();
for (int i = 0; i < attribute.length; i++) {
@@ -508,7 +503,7 @@
adapters.add(adapter);
}
/*
- * Stores model object by its adaptors.
+ * Stores model object by its adaptors.
*/
for (IModelPropertyEditorAdapter adapter : adapters) {
adapter.store();
@@ -520,7 +515,8 @@
xmo.getModel().saveOptions();
}
- public String toString() {
+ @Override
+ public String toString() {
StringBuffer st = new StringBuffer("CountItem: "); //$NON-NLS-1$
st.append(itemCount);
st.append(" Parent Composite: " + cmpToolBar.getBounds().width); //$NON-NLS-1$
@@ -530,17 +526,91 @@
}
/**
+ * Instances of this class represent a flat button with image.
+ *
+ * @author yradtsevich
+ */
+class ImageButton {
+ private ToolItem item;
+ private Composite composite;
+ private Image emptyImage;
+
+ public ImageButton(Composite parent, Image image, String toolTip) {
+ composite = new Composite(parent, SWT.NONE);
+ composite.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ release();
+ }
+ });
+ GridLayout layoutTl = new GridLayout(1, false);
+ layoutTl.marginBottom = 0;
+ layoutTl.marginHeight = 0;
+ layoutTl.marginWidth = 0;
+ layoutTl.verticalSpacing = 0;
+ layoutTl.horizontalSpacing = 0;
+ composite.setLayout(layoutTl);
+
+ ToolBar toolBar = new ToolBar(composite, SWT.HORIZONTAL | SWT.FLAT);
+ item = new ToolItem(toolBar, SWT.FLAT);
+ item.setImage(image);
+ emptyImage = new Image(Display.getCurrent(), 1, 1);
+ Color emptyImageColor = toolBar.getBackground();
+ emptyImage.setBackground(emptyImageColor);
+ GC gc = new GC(emptyImage);
+ gc.setForeground(emptyImageColor);
+ gc.drawPoint(0, 0);
+ gc.dispose();
+ item.setDisabledImage(emptyImage);
+ item.setToolTipText(toolTip);
+ }
+
+ public void addSelectionListener (Listener listener) {
+ item.addListener(SWT.Selection, listener);
+ }
+
+ /**
+ * Releases resources.
+ */
+ protected void release() {
+ if (emptyImage != null) {
+ emptyImage.dispose();
+ emptyImage = null;
+ }
+ }
+
+ public void dispose () {
+ if (composite != null) {
+ composite.dispose();
+ composite = null;
+ item = null;
+ }
+ }
+ public void setEnabled (boolean enabled) {
+ item.setEnabled(enabled);
+ }
+
+ public Rectangle getButtonBounds() {
+ return item.getBounds();
+ }
+
+
+ public Composite getComposite() {
+ return composite;
+ }
+}
+
+/**
* Listener for nodes that are implementing {@link INodeAdapter}.
* Calls {@link SelectionBar#updateNodes()} every time when these nodes are changed.
* <P>
- * This class is a part of fix of JBIDE-3919:
+ * This class is a part of fix of JBIDE-3919:
* Incorrect interaction of block comments with selection bar.
* </P>
* @author yradtsevich
*/
class NodeListener implements INodeAdapter {
private SelectionBar selectionBar;
-
+
public NodeListener(SelectionBar selectionBar) {
this.selectionBar = selectionBar;
}
15 years, 5 months
JBoss Tools SVN: r16875 - trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor.
by jbosstools-commits@lists.jboss.org
Author: koen.aers(a)jboss.com
Date: 2009-07-29 10:59:15 -0400 (Wed, 29 Jul 2009)
New Revision: 16875
Modified:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlEditor.java
Log:
JBPM-2432
Modified: trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlEditor.java
===================================================================
--- trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlEditor.java 2009-07-29 14:14:03 UTC (rev 16874)
+++ trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlEditor.java 2009-07-29 14:59:15 UTC (rev 16875)
@@ -99,7 +99,7 @@
figure.paint(g);
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[] { image.getImageData() };
- imageLoader.save(getImageSavePath(), SWT.IMAGE_JPEG);
+ imageLoader.save(getImageSavePath(), SWT.IMAGE_PNG);
refreshProcessFolder();
} finally {
15 years, 5 months
JBoss Tools SVN: r16874 - in trunk/hibernatetools/plugins: org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context and 6 other directories.
by jbosstools-commits@lists.jboss.org
Author: dgeraskov
Date: 2009-07-29 10:14:03 -0400 (Wed, 29 Jul 2009)
New Revision: 16874
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernateEntity.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/DiscriminatorFormula.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntityImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormula.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormulaImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/DiscriminatorFormulaAnnotation.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/DiscriminatorFormulaAnnotationImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/NullDiscriminatorFormulaAnnotation.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateAbstractInheritanceComposite.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateDiscriminatorColumnComposite.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateJavaInheritanceComposite.java
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaAnnotationDefinitionProvider.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaFactory.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/Hibernate.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/ParameterAnnotation.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateJavaEntityComposite.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/mapping/details/HibernateUIMappingMessages.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/mapping/details/messages.properties
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/platform/HibernateJpaUiFactory.java
Log:
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaAnnotationDefinitionProvider.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaAnnotationDefinitionProvider.java 2009-07-29 13:24:09 UTC (rev 16873)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaAnnotationDefinitionProvider.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -19,6 +19,7 @@
import org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedNativeQueryAnnotationDefinition;
import org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedQueriesAnnotationDefinition;
import org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedQueryAnnotationDefinition;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.DiscriminatorFormulaAnnotationImpl.DiscriminatorFormulaAnnotationDefinition;
import org.jboss.tools.hibernate.jpt.core.internal.resource.java.GenericGeneratorAnnotationImpl.GenericGeneratorAnnotationDefinition;
import org.jboss.tools.hibernate.jpt.core.internal.resource.java.SourceGenericGeneratorsAnnotation.GenericGeneratorsAnnotationDefinition;
@@ -57,6 +58,7 @@
definitions.add(HibernateNamedQueriesAnnotationDefinition.instance());
definitions.add(HibernateNamedNativeQueryAnnotationDefinition.instance());
definitions.add(HibernateNamedNativeQueriesAnnotationDefinition.instance());
+ definitions.add(DiscriminatorFormulaAnnotationDefinition.instance());
}
@Override
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaFactory.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaFactory.java 2009-07-29 13:24:09 UTC (rev 16873)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaFactory.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -21,12 +21,15 @@
import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit;
import org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaEntity;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaEntityImpl;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaIdMapping;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaParameter;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateNamedNativeQuery;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateNamedNativeQueryImpl;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateNamedQuery;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateNamedQueryImpl;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaDiscriminatorFormula;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaDiscriminatorFormulaImpl;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaGenericGenerator;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaGenericGeneratorImpl;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaParameter;
@@ -45,7 +48,7 @@
@Override
public JavaEntity buildJavaEntity(JavaPersistentType parent) {
- return new HibernateJavaEntity(parent);
+ return new HibernateJavaEntityImpl(parent);
}
@Override
@@ -69,4 +72,9 @@
return new HibernateJavaParameter(javaGenericGeneratorImpl);
}
+ public JavaDiscriminatorFormula buildJavaDiscriminatorFormula(
+ HibernateJavaEntity hibernateJavaEntity) {
+ return new JavaDiscriminatorFormulaImpl(hibernateJavaEntity);
+ }
+
}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernateEntity.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernateEntity.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernateEntity.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.context;
+
+import org.eclipse.jpt.core.context.Entity;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.DiscriminatorFormula;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.GenericGeneratorHolder;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateQueryContainer;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface HibernateEntity extends Entity,
+ GenericGeneratorHolder, HibernateQueryContainer {
+
+ DiscriminatorFormula getDiscriminatorFormula();
+
+}
Property changes on: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernateEntity.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/Hibernate.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/Hibernate.java 2009-07-29 13:24:09 UTC (rev 16873)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/Hibernate.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -86,5 +86,7 @@
String CACHE_MODE_TYPE__PUT = CACHE_MODE_TYPE_ + "PUT"; //$NON-NLS-1$
String CACHE_MODE_TYPE__REFRESH = CACHE_MODE_TYPE_ + "REFRESH"; //$NON-NLS-1$
+ String DISCRIMINATOR_FORMULA = PACKAGE_ + "DiscriminatorFormula"; //$NON-NLS-1$
+ String DISCRIMINATOR_FORMULA__VALUE = "value"; //$NON-NLS-1$
}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/DiscriminatorFormula.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/DiscriminatorFormula.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/DiscriminatorFormula.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+
+import org.eclipse.jpt.core.context.JpaContextNode;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface DiscriminatorFormula extends JpaContextNode {
+
+ String getValue();
+ void setValue(String value);
+ String VALUE_PROPERTY = "value"; //$NON-NLS-1$
+
+}
Property changes on: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/DiscriminatorFormula.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java 2009-07-29 13:24:09 UTC (rev 16873)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -10,370 +10,15 @@
******************************************************************************/
package org.jboss.tools.hibernate.jpt.core.internal.context.java;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
+import org.eclipse.jpt.core.context.java.JavaEntity;
+import org.jboss.tools.hibernate.jpt.core.internal.context.HibernateEntity;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jpt.core.context.java.JavaGenerator;
-import org.eclipse.jpt.core.context.java.JavaPersistentType;
-import org.eclipse.jpt.core.context.java.JavaQuery;
-import org.eclipse.jpt.core.internal.context.java.AbstractJavaEntity;
-import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
-import org.eclipse.jpt.core.resource.java.NestableAnnotation;
-import org.eclipse.jpt.utility.Filter;
-import org.eclipse.jpt.utility.internal.CollectionTools;
-import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
-import org.eclipse.jpt.utility.internal.iterators.CloneListIterator;
-import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
-import org.eclipse.wst.validation.internal.provisional.core.IMessage;
-import org.eclipse.wst.validation.internal.provisional.core.IReporter;
-import org.jboss.tools.hibernate.jpt.core.internal.HibernateJpaFactory;
-import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
-import org.jboss.tools.hibernate.jpt.core.internal.resource.java.GenericGeneratorAnnotation;
-import org.jboss.tools.hibernate.jpt.core.internal.resource.java.GenericGeneratorsAnnotation;
-import org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedNativeQueriesAnnotation;
-import org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedNativeQueryAnnotation;
-import org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedQueriesAnnotation;
-import org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedQueryAnnotation;
-
/**
* @author Dmitry Geraskov
- *
+ *
*/
-public class HibernateJavaEntity extends AbstractJavaEntity
-implements GenericGeneratorHolder, HibernateQueryContainer {
+public interface HibernateJavaEntity extends HibernateEntity, JavaEntity {
- protected final List<JavaGenericGenerator> genericGenerators;
+ JavaDiscriminatorFormula getDiscriminatorFormula();
- protected final List<HibernateNamedQuery> hibernateNamedQueries;
-
- protected final List<HibernateNamedNativeQuery> hibernateNamedNativeQueries;
-
- public HibernateJavaEntity(JavaPersistentType parent) {
- super(parent);
- this.genericGenerators = new ArrayList<JavaGenericGenerator>();
- this.hibernateNamedQueries = new ArrayList<HibernateNamedQuery>();
- this.hibernateNamedNativeQueries = new ArrayList<HibernateNamedNativeQuery>();
- }
-
- @Override
- public void initialize(JavaResourcePersistentType resourcePersistentType) {
- super.initialize(resourcePersistentType);
- this.initializeGenericGenerators();
- this.initializeHibernateNamedQueries();
- this.initializeHibernateNamedNativeQueries();
- }
-
- @Override
- public void update(JavaResourcePersistentType resourcePersistentType) {
- super.update(resourcePersistentType);
- this.updateGenericGenerators();
- this.updateHibernateNamedQueries();
- this.updateHibernateNamedNativeQueries();
- }
-
- protected HibernateJpaFactory getJpaFactory() {
- return (HibernateJpaFactory) this.getJpaPlatform().getJpaFactory();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Iterator<JavaQuery> queries() {
- return new CompositeIterator<JavaQuery>(
- super.queries(),
- this.hibernateNamedQueries(),
- this.hibernateNamedNativeQueries());
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Iterator<String> correspondingAnnotationNames() {
- return new CompositeIterator<String>(
- new ArrayIterator<String>(
- Hibernate.GENERIC_GENERATOR,
- Hibernate.GENERIC_GENERATORS,
- Hibernate.NAMED_QUERY,
- Hibernate.NAMED_QUERIES,
- Hibernate.NAMED_NATIVE_QUERY,
- Hibernate.NAMED_NATIVE_QUERIES),
- super.correspondingAnnotationNames());
- }
-
- // ********************* GenericGenerators **************
-
- public GenericGenerator addGenericGenerator(int index) {
- JavaGenericGenerator newGenericGenerator = getJpaFactory().buildJavaGenericGenerator(this);
- this.genericGenerators.add(newGenericGenerator);
- GenericGeneratorAnnotation genericGeneratorAnnotation = (GenericGeneratorAnnotation)this.javaResourcePersistentType
- .addSupportingAnnotation(index, GenericGeneratorAnnotation.ANNOTATION_NAME, GenericGeneratorsAnnotation.ANNOTATION_NAME);
- newGenericGenerator.initialize(genericGeneratorAnnotation);
- fireItemAdded(GENERIC_GENERATORS_LIST, index, newGenericGenerator);
- return newGenericGenerator;
- }
-
- protected void addGenericGenerator(JavaGenericGenerator genericGenerator) {
- this.addGenericGenerator(genericGeneratorsSize(), genericGenerator);
- }
-
- protected void addGenericGenerator(int index, JavaGenericGenerator genericGenerator) {
- addItemToList(index, genericGenerator, this.genericGenerators, GENERIC_GENERATORS_LIST);
- }
-
- @SuppressWarnings("unchecked")
- public ListIterator<JavaGenericGenerator> genericGenerators() {
- return new CloneListIterator<JavaGenericGenerator>(genericGenerators);
- }
-
- public int genericGeneratorsSize() {
- return this.genericGenerators.size();
- }
-
- public void moveGenericGenerator(int targetIndex, int sourceIndex) {
- CollectionTools.move(this.genericGenerators, targetIndex, sourceIndex);
- this.javaResourcePersistentType.moveSupportingAnnotation(targetIndex, sourceIndex, GenericGeneratorAnnotation.ANNOTATION_NAME);
- fireItemMoved(GENERIC_GENERATORS_LIST, targetIndex, sourceIndex);
- }
-
- public void removeGenericGenerator(int index) {
- JavaGenericGenerator removedGenericGenerator = this.genericGenerators.remove(index);
- this.javaResourcePersistentType.removeSupportingAnnotation(index, GenericGeneratorAnnotation.ANNOTATION_NAME, GenericGeneratorsAnnotation.ANNOTATION_NAME);
- fireItemRemoved(GENERIC_GENERATORS_LIST, index, removedGenericGenerator);
- }
-
- public void removeGenericGenerator(GenericGenerator generator) {
- removeGenericGenerator(this.genericGenerators.indexOf(generator));
- }
-
- protected void removeGenericGenerator_(JavaGenericGenerator generator) {
- removeItemFromList(generator, this.genericGenerators, GENERIC_GENERATORS_LIST);
- }
-
- protected void initializeGenericGenerators() {
- for (ListIterator<NestableAnnotation> stream = this.javaResourcePersistentType.supportingAnnotations(GenericGeneratorAnnotation.ANNOTATION_NAME, GenericGeneratorsAnnotation.ANNOTATION_NAME); stream.hasNext(); ) {
- this.genericGenerators.add(buildGenericGenerator((GenericGeneratorAnnotation) stream.next()));
- }
- }
-
- protected JavaGenericGenerator buildGenericGenerator(GenericGeneratorAnnotation genericGeneratorResource) {
- JavaGenericGenerator generator = getJpaFactory().buildJavaGenericGenerator(this);
- generator.initialize(genericGeneratorResource);
- return generator;
- }
-
- @Override
- protected void addGeneratorsTo(ArrayList<JavaGenerator> generators) {
- super.addGeneratorsTo(generators);
- for (JavaGenericGenerator genericGenerator : genericGenerators) {
- generators.add(genericGenerator);
- }
- }
-
- protected void updateGenericGenerators() {
- ListIterator<JavaGenericGenerator> genericGenerators = genericGenerators();
- ListIterator<NestableAnnotation> resourceGenericGenerators = this.javaResourcePersistentType.supportingAnnotations(GenericGeneratorAnnotation.ANNOTATION_NAME, GenericGeneratorsAnnotation.ANNOTATION_NAME);
-
- while (genericGenerators.hasNext()) {
- JavaGenericGenerator genericGenerator = genericGenerators.next();
- if (resourceGenericGenerators.hasNext()) {
- genericGenerator.update((GenericGeneratorAnnotation) resourceGenericGenerators.next());
- }
- else {
- removeGenericGenerator_(genericGenerator);
- }
- }
-
- while (resourceGenericGenerators.hasNext()) {
- addGenericGenerator(buildGenericGenerator((GenericGeneratorAnnotation) resourceGenericGenerators.next()));
- }
- }
- // ********************* NamedQuery **************
- public ListIterator<HibernateNamedQuery> hibernateNamedQueries() {
- return new CloneListIterator<HibernateNamedQuery>(this.hibernateNamedQueries);
- }
-
- public int hibernateNamedQueriesSize() {
- return this.hibernateNamedQueries.size();
- }
-
- protected void initializeHibernateNamedQueries() {
- for (ListIterator<NestableAnnotation> stream = this.javaResourcePersistentType.supportingAnnotations(HibernateNamedQueryAnnotation.ANNOTATION_NAME, HibernateNamedQueriesAnnotation.ANNOTATION_NAME); stream.hasNext(); ) {
- this.hibernateNamedQueries.add(buildHibernateNamedQuery((HibernateNamedQueryAnnotation) stream.next()));
- }
- }
-
- protected HibernateNamedQuery buildHibernateNamedQuery(HibernateNamedQueryAnnotation namedQueryResource) {
- HibernateNamedQuery hibernateNamedQuery = getJpaFactory().buildHibernateNamedQuery(this);
- hibernateNamedQuery.initialize(namedQueryResource);
- return hibernateNamedQuery;
- }
-
- protected void updateHibernateNamedQueries() {
- ListIterator<HibernateNamedQuery> queries = hibernateNamedQueries();
- ListIterator<NestableAnnotation> resourceNamedQueries = this.javaResourcePersistentType.supportingAnnotations(HibernateNamedQueryAnnotation.ANNOTATION_NAME, HibernateNamedQueriesAnnotation.ANNOTATION_NAME);
-
- while (queries.hasNext()) {
- HibernateNamedQuery hibernateNamedQuery = queries.next();
- if (resourceNamedQueries.hasNext()) {
- hibernateNamedQuery.update((HibernateNamedQueryAnnotation) resourceNamedQueries.next());
- }
- else {
- removeHibernateNamedQuery_(hibernateNamedQuery);
- }
- }
-
- while (resourceNamedQueries.hasNext()) {
- addHibernateNamedQuery(buildHibernateNamedQuery((HibernateNamedQueryAnnotation) resourceNamedQueries.next()));
- }
- }
-
- public HibernateNamedQuery addHibernateNamedQuery(int index) {
- HibernateNamedQuery hibernateNamedQuery = getJpaFactory().buildHibernateNamedQuery(this);
- this.hibernateNamedQueries.add(index, hibernateNamedQuery);
- HibernateNamedQueryAnnotation hibernateNamedQueryAnnotation = (HibernateNamedQueryAnnotation) this.javaResourcePersistentType
- .addSupportingAnnotation(index, HibernateNamedQueryAnnotation.ANNOTATION_NAME, HibernateNamedQueriesAnnotation.ANNOTATION_NAME);
- hibernateNamedQuery.initialize(hibernateNamedQueryAnnotation);
- fireItemAdded(HIBERNATE_NAMED_QUERIES_LIST, index, hibernateNamedQuery);
- return hibernateNamedQuery;
- }
-
- protected void addHibernateNamedQuery(int index, HibernateNamedQuery hibernateNamedQuery) {
- addItemToList(index, hibernateNamedQuery, this.hibernateNamedQueries, HIBERNATE_NAMED_QUERIES_LIST);
- }
-
- protected void addHibernateNamedQuery(HibernateNamedQuery hibernateNamedQuery) {
- this.addHibernateNamedQuery(this.hibernateNamedQueries.size(), hibernateNamedQuery);
- }
-
- public void removeHibernateNamedQuery(HibernateNamedQuery hibernateNamedQuery) {
- removeHibernateNamedQuery(this.hibernateNamedQueries.indexOf(hibernateNamedQuery));
- }
-
- public void removeHibernateNamedQuery(int index) {
- HibernateNamedQuery removedHibernateNamedQuery = this.hibernateNamedQueries.remove(index);
- this.javaResourcePersistentType.removeSupportingAnnotation(index, HibernateNamedQueryAnnotation.ANNOTATION_NAME, HibernateNamedQueriesAnnotation.ANNOTATION_NAME);
- fireItemRemoved(HIBERNATE_NAMED_QUERIES_LIST, index, removedHibernateNamedQuery);
- }
-
- protected void removeHibernateNamedQuery_(HibernateNamedQuery hibernateNamedQuery) {
- removeItemFromList(hibernateNamedQuery, this.hibernateNamedQueries, HIBERNATE_NAMED_QUERIES_LIST);
- }
-
- public void moveHibernateNamedQuery(int targetIndex, int sourceIndex) {
- CollectionTools.move(this.hibernateNamedQueries, targetIndex, sourceIndex);
- this.javaResourcePersistentType.moveSupportingAnnotation(targetIndex, sourceIndex, HibernateNamedQueriesAnnotation.ANNOTATION_NAME);
- fireItemMoved(HIBERNATE_NAMED_QUERIES_LIST, targetIndex, sourceIndex);
- }
-
- // ********************* NamedNativeQuery **************
- public ListIterator<HibernateNamedNativeQuery> hibernateNamedNativeQueries() {
- return new CloneListIterator<HibernateNamedNativeQuery>(this.hibernateNamedNativeQueries);
- }
-
- public int hibernateNamedNativeQueriesSize() {
- return this.hibernateNamedNativeQueries.size();
- }
-
- protected void initializeHibernateNamedNativeQueries() {
- for (ListIterator<NestableAnnotation> stream = this.javaResourcePersistentType.supportingAnnotations(HibernateNamedNativeQueryAnnotation.ANNOTATION_NAME, HibernateNamedNativeQueriesAnnotation.ANNOTATION_NAME); stream.hasNext(); ) {
- this.hibernateNamedNativeQueries.add(buildHibernateNamedNativeQuery((HibernateNamedNativeQueryAnnotation) stream.next()));
- }
- }
-
- protected HibernateNamedNativeQuery buildHibernateNamedNativeQuery(HibernateNamedNativeQueryAnnotation namedQueryResource) {
- HibernateNamedNativeQuery hibernateNamedNativeQuery = getJpaFactory().buildHibernateNamedNativeQuery(this);
- hibernateNamedNativeQuery.initialize(namedQueryResource);
- return hibernateNamedNativeQuery;
- }
-
- protected void updateHibernateNamedNativeQueries() {
- ListIterator<HibernateNamedNativeQuery> queries = hibernateNamedNativeQueries();
- ListIterator<NestableAnnotation> resourceNamedNativeQueries = this.javaResourcePersistentType.supportingAnnotations(HibernateNamedNativeQueryAnnotation.ANNOTATION_NAME, HibernateNamedNativeQueriesAnnotation.ANNOTATION_NAME);
-
- while (queries.hasNext()) {
- HibernateNamedNativeQuery hibernateNamedNativeQuery = queries.next();
- if (resourceNamedNativeQueries.hasNext()) {
- hibernateNamedNativeQuery.update((HibernateNamedNativeQueryAnnotation) resourceNamedNativeQueries.next());
- }
- else {
- removeHibernateNamedNativeQuery_(hibernateNamedNativeQuery);
- }
- }
-
- while (resourceNamedNativeQueries.hasNext()) {
- Object test = resourceNamedNativeQueries.next();
- if (!(test instanceof HibernateNamedNativeQueryAnnotation)){
- System.out.println("error!");//$NON-NLS-1$
- }
- addHibernateNamedNativeQuery(buildHibernateNamedNativeQuery((HibernateNamedNativeQueryAnnotation) test));
- }
- }
-
- public HibernateNamedNativeQuery addHibernateNamedNativeQuery(int index) {
- HibernateNamedNativeQuery hibernateNamedNativeQuery = getJpaFactory().buildHibernateNamedNativeQuery(this);
- this.hibernateNamedNativeQueries.add(index, hibernateNamedNativeQuery);
- HibernateNamedNativeQueryAnnotation hibernateNamedNativeQueryAnnotation = (HibernateNamedNativeQueryAnnotation) this.javaResourcePersistentType
- .addSupportingAnnotation(index, HibernateNamedNativeQueryAnnotation.ANNOTATION_NAME, HibernateNamedNativeQueriesAnnotation.ANNOTATION_NAME);
- hibernateNamedNativeQuery.initialize(hibernateNamedNativeQueryAnnotation);
- fireItemAdded(HIBERNATE_NAMED_NATIVE_QUERIES_LIST, index, hibernateNamedNativeQuery);
- return hibernateNamedNativeQuery;
- }
-
- protected void addHibernateNamedNativeQuery(int index, HibernateNamedNativeQuery hibernateNamedNativeQuery) {
- addItemToList(index, hibernateNamedNativeQuery, this.hibernateNamedNativeQueries, HIBERNATE_NAMED_NATIVE_QUERIES_LIST);
- }
-
- protected void addHibernateNamedNativeQuery(HibernateNamedNativeQuery hibernateNamedNativeQuery) {
- this.addHibernateNamedNativeQuery(this.hibernateNamedNativeQueries.size(), hibernateNamedNativeQuery);
- }
-
- public void removeHibernateNamedNativeQuery(HibernateNamedNativeQuery hibernateNamedNativeQuery) {
- removeHibernateNamedNativeQuery(this.hibernateNamedNativeQueries.indexOf(hibernateNamedNativeQuery));
- }
-
- public void removeHibernateNamedNativeQuery(int index) {
- HibernateNamedNativeQuery removedHibernateNamedNativeQuery = this.hibernateNamedNativeQueries.remove(index);
- this.javaResourcePersistentType.removeSupportingAnnotation(index, HibernateNamedNativeQueryAnnotation.ANNOTATION_NAME, HibernateNamedNativeQueriesAnnotation.ANNOTATION_NAME);
- fireItemRemoved(HIBERNATE_NAMED_NATIVE_QUERIES_LIST, index, removedHibernateNamedNativeQuery);
- }
-
- protected void removeHibernateNamedNativeQuery_(HibernateNamedNativeQuery hibernateNamedNativeQuery) {
- removeItemFromList(hibernateNamedNativeQuery, this.hibernateNamedNativeQueries, HIBERNATE_NAMED_NATIVE_QUERIES_LIST);
- }
-
- public void moveHibernateNamedNativeQuery(int targetIndex, int sourceIndex) {
- CollectionTools.move(this.hibernateNamedNativeQueries, targetIndex, sourceIndex);
- this.javaResourcePersistentType.moveSupportingAnnotation(targetIndex, sourceIndex, HibernateNamedNativeQueriesAnnotation.ANNOTATION_NAME);
- fireItemMoved(HIBERNATE_NAMED_NATIVE_QUERIES_LIST, targetIndex, sourceIndex);
- }
-
- // ************************* validation ***********************
- @Override
- public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
- super.validate(messages, reporter, astRoot);
- validateGenericGenerator(messages, reporter, astRoot);
- }
-
- protected void validateGenericGenerator(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
- for (JavaGenericGenerator genericGenerator : genericGenerators) {
- genericGenerator.validate(messages, reporter, astRoot);
- }
- }
-
- @Override
- public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter,
- CompilationUnit astRoot) {
- Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot);
- if (result != null) {
- return result;
- }
- for (JavaGenericGenerator genericGenerator : genericGenerators) {
- result = genericGenerator.javaCompletionProposals(pos, filter, astRoot);
- if (result != null) {
- return result;
- }
- }
- return null;
- }
}
Copied: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntityImpl.java (from rev 16747, trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java)
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntityImpl.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntityImpl.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -0,0 +1,400 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.context.java.JavaGenerator;
+import org.eclipse.jpt.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.core.context.java.JavaQuery;
+import org.eclipse.jpt.core.internal.context.java.AbstractJavaEntity;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.core.resource.java.NestableAnnotation;
+import org.eclipse.jpt.utility.Filter;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
+import org.eclipse.jpt.utility.internal.iterators.CloneListIterator;
+import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.jboss.tools.hibernate.jpt.core.internal.HibernateJpaFactory;
+import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.DiscriminatorFormulaAnnotation;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.GenericGeneratorAnnotation;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.GenericGeneratorsAnnotation;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedNativeQueriesAnnotation;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedNativeQueryAnnotation;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedQueriesAnnotation;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedQueryAnnotation;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class HibernateJavaEntityImpl extends AbstractJavaEntity
+implements HibernateJavaEntity {
+
+ protected JavaDiscriminatorFormula discriminatorFormula;
+
+ protected final List<JavaGenericGenerator> genericGenerators;
+
+ protected final List<HibernateNamedQuery> hibernateNamedQueries;
+
+ protected final List<HibernateNamedNativeQuery> hibernateNamedNativeQueries;
+
+ public HibernateJavaEntityImpl(JavaPersistentType parent) {
+ super(parent);
+ this.discriminatorFormula = getJpaFactory().buildJavaDiscriminatorFormula(this);
+ this.genericGenerators = new ArrayList<JavaGenericGenerator>();
+ this.hibernateNamedQueries = new ArrayList<HibernateNamedQuery>();
+ this.hibernateNamedNativeQueries = new ArrayList<HibernateNamedNativeQuery>();
+ }
+
+ @Override
+ public void initialize(JavaResourcePersistentType resourcePersistentType) {
+ super.initialize(resourcePersistentType);
+ this.discriminatorFormula.initialize(getDiscriminatorFormulaResource(resourcePersistentType));
+ this.initializeGenericGenerators();
+ this.initializeHibernateNamedQueries();
+ this.initializeHibernateNamedNativeQueries();
+ }
+
+ @Override
+ public void update(JavaResourcePersistentType resourcePersistentType) {
+ super.update(resourcePersistentType);
+ this.updateDiscriminatorFormula();
+ this.updateGenericGenerators();
+ this.updateHibernateNamedQueries();
+ this.updateHibernateNamedNativeQueries();
+ }
+
+ protected HibernateJpaFactory getJpaFactory() {
+ return (HibernateJpaFactory) this.getJpaPlatform().getJpaFactory();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterator<JavaQuery> queries() {
+ return new CompositeIterator<JavaQuery>(
+ super.queries(),
+ this.hibernateNamedQueries(),
+ this.hibernateNamedNativeQueries());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Iterator<String> correspondingAnnotationNames() {
+ return new CompositeIterator<String>(
+ new ArrayIterator<String>(
+ Hibernate.GENERIC_GENERATOR,
+ Hibernate.GENERIC_GENERATORS,
+ Hibernate.NAMED_QUERY,
+ Hibernate.NAMED_QUERIES,
+ Hibernate.NAMED_NATIVE_QUERY,
+ Hibernate.NAMED_NATIVE_QUERIES,
+ Hibernate.DISCRIMINATOR_FORMULA),
+ super.correspondingAnnotationNames());
+ }
+
+ // ********************* DiscriminatorFormula **************
+
+ public JavaDiscriminatorFormula getDiscriminatorFormula() {
+ return this.discriminatorFormula;
+ }
+
+ private void updateDiscriminatorFormula() {
+ getDiscriminatorFormula().update(getDiscriminatorFormulaResource(this.javaResourcePersistentType));
+ }
+
+ public DiscriminatorFormulaAnnotation getDiscriminatorFormulaResource(JavaResourcePersistentType resourcePersistentType) {
+ return (DiscriminatorFormulaAnnotation) resourcePersistentType.getNonNullSupportingAnnotation(DiscriminatorFormulaAnnotation.ANNOTATION_NAME);
+ }
+
+ // ********************* GenericGenerators **************
+
+ public GenericGenerator addGenericGenerator(int index) {
+ JavaGenericGenerator newGenericGenerator = getJpaFactory().buildJavaGenericGenerator(this);
+ this.genericGenerators.add(newGenericGenerator);
+ GenericGeneratorAnnotation genericGeneratorAnnotation = (GenericGeneratorAnnotation)this.javaResourcePersistentType
+ .addSupportingAnnotation(index, GenericGeneratorAnnotation.ANNOTATION_NAME, GenericGeneratorsAnnotation.ANNOTATION_NAME);
+ newGenericGenerator.initialize(genericGeneratorAnnotation);
+ fireItemAdded(GENERIC_GENERATORS_LIST, index, newGenericGenerator);
+ return newGenericGenerator;
+ }
+
+ protected void addGenericGenerator(JavaGenericGenerator genericGenerator) {
+ this.addGenericGenerator(genericGeneratorsSize(), genericGenerator);
+ }
+
+ protected void addGenericGenerator(int index, JavaGenericGenerator genericGenerator) {
+ addItemToList(index, genericGenerator, this.genericGenerators, GENERIC_GENERATORS_LIST);
+ }
+
+ @SuppressWarnings("unchecked")
+ public ListIterator<JavaGenericGenerator> genericGenerators() {
+ return new CloneListIterator<JavaGenericGenerator>(genericGenerators);
+ }
+
+ public int genericGeneratorsSize() {
+ return this.genericGenerators.size();
+ }
+
+ public void moveGenericGenerator(int targetIndex, int sourceIndex) {
+ CollectionTools.move(this.genericGenerators, targetIndex, sourceIndex);
+ this.javaResourcePersistentType.moveSupportingAnnotation(targetIndex, sourceIndex, GenericGeneratorAnnotation.ANNOTATION_NAME);
+ fireItemMoved(GENERIC_GENERATORS_LIST, targetIndex, sourceIndex);
+ }
+
+ public void removeGenericGenerator(int index) {
+ JavaGenericGenerator removedGenericGenerator = this.genericGenerators.remove(index);
+ this.javaResourcePersistentType.removeSupportingAnnotation(index, GenericGeneratorAnnotation.ANNOTATION_NAME, GenericGeneratorsAnnotation.ANNOTATION_NAME);
+ fireItemRemoved(GENERIC_GENERATORS_LIST, index, removedGenericGenerator);
+ }
+
+ public void removeGenericGenerator(GenericGenerator generator) {
+ removeGenericGenerator(this.genericGenerators.indexOf(generator));
+ }
+
+ protected void removeGenericGenerator_(JavaGenericGenerator generator) {
+ removeItemFromList(generator, this.genericGenerators, GENERIC_GENERATORS_LIST);
+ }
+
+ protected void initializeGenericGenerators() {
+ for (ListIterator<NestableAnnotation> stream = this.javaResourcePersistentType.supportingAnnotations(GenericGeneratorAnnotation.ANNOTATION_NAME, GenericGeneratorsAnnotation.ANNOTATION_NAME); stream.hasNext(); ) {
+ this.genericGenerators.add(buildGenericGenerator((GenericGeneratorAnnotation) stream.next()));
+ }
+ }
+
+ protected JavaGenericGenerator buildGenericGenerator(GenericGeneratorAnnotation genericGeneratorResource) {
+ JavaGenericGenerator generator = getJpaFactory().buildJavaGenericGenerator(this);
+ generator.initialize(genericGeneratorResource);
+ return generator;
+ }
+
+ @Override
+ protected void addGeneratorsTo(ArrayList<JavaGenerator> generators) {
+ super.addGeneratorsTo(generators);
+ for (JavaGenericGenerator genericGenerator : genericGenerators) {
+ generators.add(genericGenerator);
+ }
+ }
+
+ protected void updateGenericGenerators() {
+ ListIterator<JavaGenericGenerator> genericGenerators = genericGenerators();
+ ListIterator<NestableAnnotation> resourceGenericGenerators = this.javaResourcePersistentType.supportingAnnotations(GenericGeneratorAnnotation.ANNOTATION_NAME, GenericGeneratorsAnnotation.ANNOTATION_NAME);
+
+ while (genericGenerators.hasNext()) {
+ JavaGenericGenerator genericGenerator = genericGenerators.next();
+ if (resourceGenericGenerators.hasNext()) {
+ genericGenerator.update((GenericGeneratorAnnotation) resourceGenericGenerators.next());
+ }
+ else {
+ removeGenericGenerator_(genericGenerator);
+ }
+ }
+
+ while (resourceGenericGenerators.hasNext()) {
+ addGenericGenerator(buildGenericGenerator((GenericGeneratorAnnotation) resourceGenericGenerators.next()));
+ }
+ }
+ // ********************* NamedQuery **************
+ public ListIterator<HibernateNamedQuery> hibernateNamedQueries() {
+ return new CloneListIterator<HibernateNamedQuery>(this.hibernateNamedQueries);
+ }
+
+ public int hibernateNamedQueriesSize() {
+ return this.hibernateNamedQueries.size();
+ }
+
+ protected void initializeHibernateNamedQueries() {
+ for (ListIterator<NestableAnnotation> stream = this.javaResourcePersistentType.supportingAnnotations(HibernateNamedQueryAnnotation.ANNOTATION_NAME, HibernateNamedQueriesAnnotation.ANNOTATION_NAME); stream.hasNext(); ) {
+ this.hibernateNamedQueries.add(buildHibernateNamedQuery((HibernateNamedQueryAnnotation) stream.next()));
+ }
+ }
+
+ protected HibernateNamedQuery buildHibernateNamedQuery(HibernateNamedQueryAnnotation namedQueryResource) {
+ HibernateNamedQuery hibernateNamedQuery = getJpaFactory().buildHibernateNamedQuery(this);
+ hibernateNamedQuery.initialize(namedQueryResource);
+ return hibernateNamedQuery;
+ }
+
+ protected void updateHibernateNamedQueries() {
+ ListIterator<HibernateNamedQuery> queries = hibernateNamedQueries();
+ ListIterator<NestableAnnotation> resourceNamedQueries = this.javaResourcePersistentType.supportingAnnotations(HibernateNamedQueryAnnotation.ANNOTATION_NAME, HibernateNamedQueriesAnnotation.ANNOTATION_NAME);
+
+ while (queries.hasNext()) {
+ HibernateNamedQuery hibernateNamedQuery = queries.next();
+ if (resourceNamedQueries.hasNext()) {
+ hibernateNamedQuery.update((HibernateNamedQueryAnnotation) resourceNamedQueries.next());
+ }
+ else {
+ removeHibernateNamedQuery_(hibernateNamedQuery);
+ }
+ }
+
+ while (resourceNamedQueries.hasNext()) {
+ addHibernateNamedQuery(buildHibernateNamedQuery((HibernateNamedQueryAnnotation) resourceNamedQueries.next()));
+ }
+ }
+
+ public HibernateNamedQuery addHibernateNamedQuery(int index) {
+ HibernateNamedQuery hibernateNamedQuery = getJpaFactory().buildHibernateNamedQuery(this);
+ this.hibernateNamedQueries.add(index, hibernateNamedQuery);
+ HibernateNamedQueryAnnotation hibernateNamedQueryAnnotation = (HibernateNamedQueryAnnotation) this.javaResourcePersistentType
+ .addSupportingAnnotation(index, HibernateNamedQueryAnnotation.ANNOTATION_NAME, HibernateNamedQueriesAnnotation.ANNOTATION_NAME);
+ hibernateNamedQuery.initialize(hibernateNamedQueryAnnotation);
+ fireItemAdded(HIBERNATE_NAMED_QUERIES_LIST, index, hibernateNamedQuery);
+ return hibernateNamedQuery;
+ }
+
+ protected void addHibernateNamedQuery(int index, HibernateNamedQuery hibernateNamedQuery) {
+ addItemToList(index, hibernateNamedQuery, this.hibernateNamedQueries, HIBERNATE_NAMED_QUERIES_LIST);
+ }
+
+ protected void addHibernateNamedQuery(HibernateNamedQuery hibernateNamedQuery) {
+ this.addHibernateNamedQuery(this.hibernateNamedQueries.size(), hibernateNamedQuery);
+ }
+
+ public void removeHibernateNamedQuery(HibernateNamedQuery hibernateNamedQuery) {
+ removeHibernateNamedQuery(this.hibernateNamedQueries.indexOf(hibernateNamedQuery));
+ }
+
+ public void removeHibernateNamedQuery(int index) {
+ HibernateNamedQuery removedHibernateNamedQuery = this.hibernateNamedQueries.remove(index);
+ this.javaResourcePersistentType.removeSupportingAnnotation(index, HibernateNamedQueryAnnotation.ANNOTATION_NAME, HibernateNamedQueriesAnnotation.ANNOTATION_NAME);
+ fireItemRemoved(HIBERNATE_NAMED_QUERIES_LIST, index, removedHibernateNamedQuery);
+ }
+
+ protected void removeHibernateNamedQuery_(HibernateNamedQuery hibernateNamedQuery) {
+ removeItemFromList(hibernateNamedQuery, this.hibernateNamedQueries, HIBERNATE_NAMED_QUERIES_LIST);
+ }
+
+ public void moveHibernateNamedQuery(int targetIndex, int sourceIndex) {
+ CollectionTools.move(this.hibernateNamedQueries, targetIndex, sourceIndex);
+ this.javaResourcePersistentType.moveSupportingAnnotation(targetIndex, sourceIndex, HibernateNamedQueriesAnnotation.ANNOTATION_NAME);
+ fireItemMoved(HIBERNATE_NAMED_QUERIES_LIST, targetIndex, sourceIndex);
+ }
+
+ // ********************* NamedNativeQuery **************
+ public ListIterator<HibernateNamedNativeQuery> hibernateNamedNativeQueries() {
+ return new CloneListIterator<HibernateNamedNativeQuery>(this.hibernateNamedNativeQueries);
+ }
+
+ public int hibernateNamedNativeQueriesSize() {
+ return this.hibernateNamedNativeQueries.size();
+ }
+
+ protected void initializeHibernateNamedNativeQueries() {
+ for (ListIterator<NestableAnnotation> stream = this.javaResourcePersistentType.supportingAnnotations(HibernateNamedNativeQueryAnnotation.ANNOTATION_NAME, HibernateNamedNativeQueriesAnnotation.ANNOTATION_NAME); stream.hasNext(); ) {
+ this.hibernateNamedNativeQueries.add(buildHibernateNamedNativeQuery((HibernateNamedNativeQueryAnnotation) stream.next()));
+ }
+ }
+
+ protected HibernateNamedNativeQuery buildHibernateNamedNativeQuery(HibernateNamedNativeQueryAnnotation namedQueryResource) {
+ HibernateNamedNativeQuery hibernateNamedNativeQuery = getJpaFactory().buildHibernateNamedNativeQuery(this);
+ hibernateNamedNativeQuery.initialize(namedQueryResource);
+ return hibernateNamedNativeQuery;
+ }
+
+ protected void updateHibernateNamedNativeQueries() {
+ ListIterator<HibernateNamedNativeQuery> queries = hibernateNamedNativeQueries();
+ ListIterator<NestableAnnotation> resourceNamedNativeQueries = this.javaResourcePersistentType.supportingAnnotations(HibernateNamedNativeQueryAnnotation.ANNOTATION_NAME, HibernateNamedNativeQueriesAnnotation.ANNOTATION_NAME);
+
+ while (queries.hasNext()) {
+ HibernateNamedNativeQuery hibernateNamedNativeQuery = queries.next();
+ if (resourceNamedNativeQueries.hasNext()) {
+ hibernateNamedNativeQuery.update((HibernateNamedNativeQueryAnnotation) resourceNamedNativeQueries.next());
+ }
+ else {
+ removeHibernateNamedNativeQuery_(hibernateNamedNativeQuery);
+ }
+ }
+
+ while (resourceNamedNativeQueries.hasNext()) {
+ Object test = resourceNamedNativeQueries.next();
+ if (!(test instanceof HibernateNamedNativeQueryAnnotation)){
+ System.out.println("error!");//$NON-NLS-1$
+ }
+ addHibernateNamedNativeQuery(buildHibernateNamedNativeQuery((HibernateNamedNativeQueryAnnotation) test));
+ }
+ }
+
+ public HibernateNamedNativeQuery addHibernateNamedNativeQuery(int index) {
+ HibernateNamedNativeQuery hibernateNamedNativeQuery = getJpaFactory().buildHibernateNamedNativeQuery(this);
+ this.hibernateNamedNativeQueries.add(index, hibernateNamedNativeQuery);
+ HibernateNamedNativeQueryAnnotation hibernateNamedNativeQueryAnnotation = (HibernateNamedNativeQueryAnnotation) this.javaResourcePersistentType
+ .addSupportingAnnotation(index, HibernateNamedNativeQueryAnnotation.ANNOTATION_NAME, HibernateNamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ hibernateNamedNativeQuery.initialize(hibernateNamedNativeQueryAnnotation);
+ fireItemAdded(HIBERNATE_NAMED_NATIVE_QUERIES_LIST, index, hibernateNamedNativeQuery);
+ return hibernateNamedNativeQuery;
+ }
+
+ protected void addHibernateNamedNativeQuery(int index, HibernateNamedNativeQuery hibernateNamedNativeQuery) {
+ addItemToList(index, hibernateNamedNativeQuery, this.hibernateNamedNativeQueries, HIBERNATE_NAMED_NATIVE_QUERIES_LIST);
+ }
+
+ protected void addHibernateNamedNativeQuery(HibernateNamedNativeQuery hibernateNamedNativeQuery) {
+ this.addHibernateNamedNativeQuery(this.hibernateNamedNativeQueries.size(), hibernateNamedNativeQuery);
+ }
+
+ public void removeHibernateNamedNativeQuery(HibernateNamedNativeQuery hibernateNamedNativeQuery) {
+ removeHibernateNamedNativeQuery(this.hibernateNamedNativeQueries.indexOf(hibernateNamedNativeQuery));
+ }
+
+ public void removeHibernateNamedNativeQuery(int index) {
+ HibernateNamedNativeQuery removedHibernateNamedNativeQuery = this.hibernateNamedNativeQueries.remove(index);
+ this.javaResourcePersistentType.removeSupportingAnnotation(index, HibernateNamedNativeQueryAnnotation.ANNOTATION_NAME, HibernateNamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ fireItemRemoved(HIBERNATE_NAMED_NATIVE_QUERIES_LIST, index, removedHibernateNamedNativeQuery);
+ }
+
+ protected void removeHibernateNamedNativeQuery_(HibernateNamedNativeQuery hibernateNamedNativeQuery) {
+ removeItemFromList(hibernateNamedNativeQuery, this.hibernateNamedNativeQueries, HIBERNATE_NAMED_NATIVE_QUERIES_LIST);
+ }
+
+ public void moveHibernateNamedNativeQuery(int targetIndex, int sourceIndex) {
+ CollectionTools.move(this.hibernateNamedNativeQueries, targetIndex, sourceIndex);
+ this.javaResourcePersistentType.moveSupportingAnnotation(targetIndex, sourceIndex, HibernateNamedNativeQueriesAnnotation.ANNOTATION_NAME);
+ fireItemMoved(HIBERNATE_NAMED_NATIVE_QUERIES_LIST, targetIndex, sourceIndex);
+ }
+
+ // ************************* validation ***********************
+ @Override
+ public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
+ super.validate(messages, reporter, astRoot);
+ validateGenericGenerator(messages, reporter, astRoot);
+ }
+
+ protected void validateGenericGenerator(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
+ for (JavaGenericGenerator genericGenerator : genericGenerators) {
+ genericGenerator.validate(messages, reporter, astRoot);
+ }
+ }
+
+ @Override
+ public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter,
+ CompilationUnit astRoot) {
+ Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot);
+ if (result != null) {
+ return result;
+ }
+ for (JavaGenericGenerator genericGenerator : genericGenerators) {
+ result = genericGenerator.javaCompletionProposals(pos, filter, astRoot);
+ if (result != null) {
+ return result;
+ }
+ }
+ return null;
+ }
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormula.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormula.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormula.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.DiscriminatorFormulaAnnotation;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface JavaDiscriminatorFormula extends DiscriminatorFormula {
+
+ void initialize(DiscriminatorFormulaAnnotation dfResource);
+
+ /**
+ * Update the JavaParameter context model object to match the DiscriminatorFormulaAnnotation
+ * resource model object. see {@link org.eclipse.jpt.core.JpaProject#update()}
+ */
+ void update(DiscriminatorFormulaAnnotation dfResource);
+}
Property changes on: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormula.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormulaImpl.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormulaImpl.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormulaImpl.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.context.JpaContextNode;
+import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.DiscriminatorFormulaAnnotation;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class JavaDiscriminatorFormulaImpl extends AbstractJavaJpaContextNode implements JavaDiscriminatorFormula {
+
+ protected String value;
+
+ protected DiscriminatorFormulaAnnotation dfResource;
+
+ public JavaDiscriminatorFormulaImpl(JpaContextNode parent) {
+ super(parent);
+ }
+
+ public void initialize(DiscriminatorFormulaAnnotation dfResource) {
+ this.dfResource = dfResource;
+ this.value = dfResource.getValue();
+ }
+
+ public void update(DiscriminatorFormulaAnnotation dfResource) {
+ this.dfResource = dfResource;
+ this.setValue(dfResource.getValue());
+ }
+
+ //******************* value *********************
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setValue(String newValue) {
+ String oldValue = this.value;
+ this.value = newValue;
+ this.dfResource.setValue(newValue);
+ firePropertyChanged(Parameter.VALUE_PROPERTY, oldValue, newValue);
+ }
+
+
+ public TextRange getValidationTextRange(CompilationUnit astRoot) {
+ return this.dfResource.getTextRange(astRoot);
+ }
+
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.value);
+ }
+}
Property changes on: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormulaImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/DiscriminatorFormulaAnnotation.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/DiscriminatorFormulaAnnotation.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/DiscriminatorFormulaAnnotation.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface DiscriminatorFormulaAnnotation extends Annotation {
+ String ANNOTATION_NAME = Hibernate.DISCRIMINATOR_FORMULA;
+
+ /**
+ * Corresponds to the 'value' element of the DiscriminatorFormulaAnnotation annotation.
+ * Return null if the element does not exist in the annotation
+ */
+ String getValue();
+ String VALUE_PROPERTY = Hibernate.DISCRIMINATOR_FORMULA__VALUE;
+
+ /**
+ * Corresponds to the 'value' element of the DiscriminatorFormulaAnnotation annotation.
+ * Setting to null will remove the element.
+ */
+ void setValue(String value);
+
+ /**
+ * Return the {@link TextRange} for the 'value' element.
+ */
+ TextRange getValueTextRange(CompilationUnit astRoot);
+}
Property changes on: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/DiscriminatorFormulaAnnotation.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/DiscriminatorFormulaAnnotationImpl.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/DiscriminatorFormulaAnnotationImpl.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/DiscriminatorFormulaAnnotationImpl.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -0,0 +1,135 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.resource.java;
+
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.source.SourceAnnotation;
+import org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.Member;
+import org.eclipse.jpt.core.utility.jdt.Type;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class DiscriminatorFormulaAnnotationImpl extends SourceAnnotation<Type> implements
+ DiscriminatorFormulaAnnotation {
+
+ public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private static final DeclarationAnnotationElementAdapter<String> VALUE_ADAPTER = buildValueAdapter(DECLARATION_ANNOTATION_ADAPTER);
+ private final AnnotationElementAdapter<String> valueAdapter;
+ private String value;
+
+ protected DiscriminatorFormulaAnnotationImpl(JavaResourceNode parent, Type type) {
+ super(parent, type, DECLARATION_ANNOTATION_ADAPTER);
+ this.valueAdapter = this.buildAdapter(VALUE_ADAPTER);
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.value = this.buildValue(astRoot);
+ }
+
+ public void update(CompilationUnit astRoot) {
+ this.setValue(this.buildValue(astRoot));
+ }
+
+ // ***** value
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ if (this.attributeValueHasNotChanged(this.value, value)) {
+ return;
+ }
+ String old = this.value;
+ this.value = value;
+ this.valueAdapter.setValue(value);
+ this.firePropertyChanged(VALUE_PROPERTY, old, value);
+ }
+
+ private String buildValue(CompilationUnit astRoot) {
+ return this.valueAdapter.getValue(astRoot);
+ }
+
+ public TextRange getValueTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(VALUE_ADAPTER, astRoot);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ AnnotationElementAdapter<String> buildAdapter(DeclarationAnnotationElementAdapter<String> daea) {
+ return new ShortCircuitAnnotationElementAdapter<String>(this.member, daea);
+ }
+
+ private static DeclarationAnnotationElementAdapter<String> buildValueAdapter(DeclarationAnnotationAdapter adapter) {
+ return ConversionDeclarationAnnotationElementAdapter.forStrings(adapter, VALUE_PROPERTY);
+ }
+
+
+ public static class DiscriminatorFormulaAnnotationDefinition implements AnnotationDefinition
+ {
+ // singleton
+ private static final DiscriminatorFormulaAnnotationDefinition INSTANCE = new DiscriminatorFormulaAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static AnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure non-instantiability.
+ */
+ private DiscriminatorFormulaAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member type) {
+ return new DiscriminatorFormulaAnnotationImpl(parent, (Type) type);
+ }
+
+ public Annotation buildNullAnnotation(JavaResourcePersistentMember parent, Type type) {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getAnnotationName() {
+ return DiscriminatorFormulaAnnotation.ANNOTATION_NAME;
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember arg0,
+ IAnnotation arg1) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) {
+ return new NullDiscriminatorFormulaAnnotation((JavaResourcePersistentType) parent);
+ }
+
+ }
+
+}
Property changes on: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/DiscriminatorFormulaAnnotationImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/NullDiscriminatorFormulaAnnotation.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/NullDiscriminatorFormulaAnnotation.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/NullDiscriminatorFormulaAnnotation.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.resource.java;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.NullAnnotation;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.core.utility.TextRange;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class NullDiscriminatorFormulaAnnotation extends NullAnnotation implements
+ DiscriminatorFormulaAnnotation {
+
+ public NullDiscriminatorFormulaAnnotation(JavaResourcePersistentType parent) {
+ super(parent);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ @Override
+ protected DiscriminatorFormulaAnnotation buildSupportingAnnotation() {
+ return (DiscriminatorFormulaAnnotation) super.buildSupportingAnnotation();
+ }
+
+ // ***** value
+ public String getValue() {
+ return null;
+ }
+
+ public void setValue(String value) {
+ if (value != null) {
+ this.buildSupportingAnnotation().setValue(value);
+ }
+ }
+
+ public TextRange getValueTextRange(CompilationUnit astRoot) {
+ return null;
+ }
+
+}
Property changes on: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/NullDiscriminatorFormulaAnnotation.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/ParameterAnnotation.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/ParameterAnnotation.java 2009-07-29 13:24:09 UTC (rev 16873)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/ParameterAnnotation.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -28,7 +28,7 @@
/**
* Return the {@link TextRange} for the 'name' element. If the element
- * does not exist return the {@link TextRange} for the QueryHint annotation.
+ * does not exist return the {@link TextRange} for the ParameterAnnotation annotation.
*/
TextRange getNameTextRange(CompilationUnit astRoot);
@@ -48,7 +48,7 @@
/**
* Return the {@link TextRange} for the 'value' element. If the element
- * does not exist return the {@link TextRange} for the QueryHint annotation.
+ * does not exist return the {@link TextRange} for the ParameterAnnotation annotation.
*/
TextRange getValueTextRange(CompilationUnit astRoot);
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateAbstractInheritanceComposite.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateAbstractInheritanceComposite.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateAbstractInheritanceComposite.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -0,0 +1,296 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 Oracle. 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:
+ * Oracle - initial API and implementation
+ * Code copied from org.eclipse.jpt.ui.internal.mappings.details.AbstractInheritanceComposite
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.ui.internal.java.details;
+
+import java.util.Collection;
+
+import org.eclipse.jpt.core.context.Entity;
+import org.eclipse.jpt.core.context.InheritanceType;
+import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
+import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages;
+import org.eclipse.jpt.ui.internal.mappings.db.ColumnCombo;
+import org.eclipse.jpt.ui.internal.mappings.details.AbstractEntityComposite;
+import org.eclipse.jpt.ui.internal.mappings.details.AbstractInheritanceComposite;
+import org.eclipse.jpt.ui.internal.util.ControlEnabler;
+import org.eclipse.jpt.ui.internal.widgets.EnumFormComboViewer;
+import org.eclipse.jpt.ui.internal.widgets.FormPane;
+import org.eclipse.jpt.utility.internal.StringConverter;
+import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
+import org.eclipse.jpt.utility.internal.model.value.PropertyListValueModelAdapter;
+import org.eclipse.jpt.utility.model.value.ListValueModel;
+import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.jboss.tools.hibernate.jpt.core.internal.context.HibernateEntity;
+
+/**
+ * Here the layout of this pane:
+ * <pre>
+ * -----------------------------------------------------------------------------
+ * | ---------------------------------------------------- |
+ * | Strategy: | EnumComboViewer |v| |
+ * | ---------------------------------------------------- |
+ * | ---------------------------------------------------- |
+ * | Value: | I |v| |
+ * | ---------------------------------------------------- |
+ * | |
+ * | > Discriminator Column |
+ * | |
+ * | ---------------------------------------------------- |
+ * | Name: | ColumnCombo |v| |
+ * | ---------------------------------------------------- |
+ * | ---------------------------------------------------- |
+ * | Formula: | Text |v| |
+ * | ---------------------------------------------------- |
+ * | ---------------------------------------------------- |
+ * | Type: | EnumComboViewer |v| |
+ * | ---------------------------------------------------- |
+ * | ---------------------------------------------------- |
+ * | Column Definition: | I | |
+ * | ---------------------------------------------------- |
+ * | ------------- |
+ * | Length: | I |I| |
+ * | ------------- |
+ * | ------------------------------------------------------------------------- |
+ * | | | |
+ * | | PrimaryKeyJoinColumnsComposite | |
+ * | | | |
+ * | ------------------------------------------------------------------------- |
+ * -----------------------------------------------------------------------------</pre>
+ *
+ * @see Entity
+ * @see AbstractEntityComposite - The parent container
+ * @see ColumnCombo
+ * @see EnumComboViewer
+ * @see PrimaryKeyJoinColumnsComposite
+ *
+ * @version 2.0
+ * @since 2.0
+ */
+@SuppressWarnings("nls")
+public abstract class HibernateAbstractInheritanceComposite<T extends HibernateEntity> extends FormPane<T> {
+
+ /**
+ * A key used to represent the default value, this is required to convert
+ * the selected item from a combo to <code>null</code>. This key is most
+ * likely never typed the user and it will help to convert the value to
+ * <code>null</code> when it's time to set the new selected value into the
+ * model.
+ */
+ protected static String DEFAULT_KEY = "?!#!?#?#?default?#?!#?!#?";
+
+ protected static String NONE_KEY = "?!#!?#?#?none?#?!#?!#?";
+
+ /**
+ * Creates a new <code>InheritanceComposite</code>.
+ *
+ * @param parentPane The parent container of this one
+ * @param parent The parent container
+ */
+ public HibernateAbstractInheritanceComposite(FormPane<? extends T> parentPane,
+ Composite parent) {
+
+ super(parentPane, parent, false);
+ }
+
+ @Override
+ protected void initializeLayout(Composite container) {
+
+ int groupBoxMargin = getGroupBoxMargin();
+
+ Composite subPane = addSubPane(
+ container, 0, groupBoxMargin, 0, groupBoxMargin
+ );
+
+ // Strategy widgets
+ addLabeledComposite(
+ subPane,
+ JptUiMappingsMessages.InheritanceComposite_strategy,
+ addStrategyCombo(subPane),
+ JpaHelpContextIds.ENTITY_INHERITANCE_STRATEGY
+ );
+
+ // Discrinator Value widgets
+ CCombo discriminatorValueCombo = addEditableCCombo(
+ subPane,
+ buildDiscriminatorValueListHolder(),
+ buildDiscriminatorValueHolder(),
+ buildDiscriminatorValueConverter()
+ );
+ Label discriminatorValueLabel = addLabel(
+ subPane,
+ JptUiMappingsMessages.InheritanceComposite_discriminatorValue
+ );
+ addLabeledComposite(
+ subPane,
+ discriminatorValueLabel,
+ discriminatorValueCombo.getParent(),
+ null,
+ JpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_VALUE
+ );
+
+ new ControlEnabler(buildDiscriminatorValueEnabledHolder(), discriminatorValueCombo, discriminatorValueLabel);
+
+ new HibernateDiscriminatorColumnComposite<HibernateEntity>(this, container);
+
+ // Primary Key Join Columns widgets
+ addPrimaryKeyJoinColumnsComposite(addSubPane(container, 5));
+ }
+
+ protected WritablePropertyValueModel<Boolean> buildDiscriminatorValueEnabledHolder() {
+ return new PropertyAspectAdapter<Entity, Boolean>(getSubjectHolder(), Entity.SPECIFIED_DISCRIMINATOR_VALUE_IS_ALLOWED_PROPERTY) {
+ @Override
+ protected Boolean buildValue_() {
+ return Boolean.valueOf(this.subject.specifiedDiscriminatorValueIsAllowed());
+ }
+ };
+ }
+
+ private ListValueModel<String> buildDefaultDiscriminatorListValueHolder() {
+ return new PropertyListValueModelAdapter<String>(
+ buildDefaultDiscriminatorValueHolder()
+ );
+ }
+
+ private WritablePropertyValueModel<String> buildDefaultDiscriminatorValueHolder() {
+ return new PropertyAspectAdapter<Entity, String>(getSubjectHolder(), Entity.DEFAULT_DISCRIMINATOR_VALUE_PROPERTY, Entity.DISCRIMINATOR_VALUE_IS_UNDEFINED_PROPERTY) {
+ @Override
+ protected String buildValue_() {
+ String value = this.subject.getDefaultDiscriminatorValue();
+ if (value == null && this.subject.discriminatorValueIsUndefined()) {
+ return NONE_KEY;
+ }
+
+ if (value == null) {
+ value = DEFAULT_KEY;
+ }
+ else {
+ value = DEFAULT_KEY + value;
+ }
+
+ return value;
+ }
+ };
+ }
+
+ private StringConverter<String> buildDiscriminatorValueConverter() {
+ return new StringConverter<String>() {
+ public String convertToString(String value) {
+
+ if (getSubject() == null) {
+ return null;
+ }
+
+ if (value == null) {
+ value = getSubject().getDefaultDiscriminatorValue();
+ if (value == null && getSubject().discriminatorValueIsUndefined()) {
+ value = NONE_KEY;
+ }
+ else {
+ value = (value != null) ?
+ DEFAULT_KEY + value
+ :
+ DEFAULT_KEY;
+ }
+ }
+ if (value.startsWith(DEFAULT_KEY)) {
+ String defaultName = value.substring(DEFAULT_KEY.length());
+
+ if (defaultName.length() > 0) {
+ value = NLS.bind(
+ JptUiMappingsMessages.DefaultWithOneParam,
+ defaultName
+ );
+ }
+ else {
+ value = JptUiMappingsMessages.ProviderDefault;
+ }
+ }
+ if (value.startsWith(NONE_KEY)) {
+ value = JptUiMappingsMessages.NoneSelected;
+ }
+ return value;
+ }
+ };
+ }
+
+ private WritablePropertyValueModel<String> buildDiscriminatorValueHolder() {
+ return new PropertyAspectAdapter<Entity, String>(getSubjectHolder(), Entity.SPECIFIED_DISCRIMINATOR_VALUE_PROPERTY) {
+ @Override
+ protected String buildValue_() {
+ return this.subject.getSpecifiedDiscriminatorValue();
+ }
+
+ @Override
+ protected void setValue_(String value) {
+
+ // Convert the default value or an empty string to null
+ if ((value != null) &&
+ ((value.length() == 0) || value.startsWith(DEFAULT_KEY) || value.startsWith(NONE_KEY))) {
+
+ value = null;
+ }
+
+ this.subject.setSpecifiedDiscriminatorValue(value);
+ }
+ };
+ }
+
+ private ListValueModel<String> buildDiscriminatorValueListHolder() {
+ return buildDefaultDiscriminatorListValueHolder();
+ }
+
+ private EnumFormComboViewer<Entity, InheritanceType> addStrategyCombo(Composite container) {
+
+ return new EnumFormComboViewer<Entity, InheritanceType>(this, container) {
+
+ @Override
+ protected void addPropertyNames(Collection<String> propertyNames) {
+ super.addPropertyNames(propertyNames);
+ propertyNames.add(Entity.DEFAULT_INHERITANCE_STRATEGY_PROPERTY);
+ propertyNames.add(Entity.SPECIFIED_INHERITANCE_STRATEGY_PROPERTY);
+ }
+
+ @Override
+ protected InheritanceType[] getChoices() {
+ return InheritanceType.values();
+ }
+
+ @Override
+ protected InheritanceType getDefaultValue() {
+ return getSubject().getDefaultInheritanceStrategy();
+ }
+
+ @Override
+ protected String displayString(InheritanceType value) {
+ return buildDisplayString(
+ JptUiMappingsMessages.class,
+ AbstractInheritanceComposite.class,
+ value
+ );
+ }
+
+ @Override
+ protected InheritanceType getValue() {
+ return getSubject().getSpecifiedInheritanceStrategy();
+ }
+
+ @Override
+ protected void setValue(InheritanceType value) {
+ getSubject().setSpecifiedInheritanceStrategy(value);
+ }
+ };
+ }
+
+ protected abstract void addPrimaryKeyJoinColumnsComposite(Composite container);
+}
\ No newline at end of file
Property changes on: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateAbstractInheritanceComposite.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateDiscriminatorColumnComposite.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateDiscriminatorColumnComposite.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateDiscriminatorColumnComposite.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -0,0 +1,424 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.ui.internal.java.details;
+
+import java.util.Collection;
+
+import org.eclipse.jpt.core.context.DiscriminatorColumn;
+import org.eclipse.jpt.core.context.DiscriminatorType;
+import org.eclipse.jpt.core.context.Entity;
+import org.eclipse.jpt.core.context.NamedColumn;
+import org.eclipse.jpt.db.Table;
+import org.eclipse.jpt.ui.internal.JpaHelpContextIds;
+import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages;
+import org.eclipse.jpt.ui.internal.mappings.db.ColumnCombo;
+import org.eclipse.jpt.ui.internal.mappings.details.AbstractEntityComposite;
+import org.eclipse.jpt.ui.internal.mappings.details.DiscriminatorColumnComposite;
+import org.eclipse.jpt.ui.internal.util.LabeledControlUpdater;
+import org.eclipse.jpt.ui.internal.util.LabeledLabel;
+import org.eclipse.jpt.ui.internal.util.PaneEnabler;
+import org.eclipse.jpt.ui.internal.widgets.EnumFormComboViewer;
+import org.eclipse.jpt.ui.internal.widgets.FormPane;
+import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter;
+import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel;
+import org.eclipse.jpt.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Spinner;
+import org.jboss.tools.hibernate.jpt.core.internal.context.HibernateEntity;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.DiscriminatorFormula;
+import org.jboss.tools.hibernate.jpt.ui.internal.mapping.details.HibernateUIMappingMessages;
+
+/**
+ * Here the layout of this pane:
+ * <pre>
+ * -----------------------------------------------------------------------------
+ * | > Discriminator Column |
+ * | |
+ * | ---------------------------------------------------- |
+ * | Name: | ColumnCombo |v| |
+ * | ---------------------------------------------------- |
+ * | ---------------------------------------------------- |
+ * | Formula: | Text |v| |
+ * | ---------------------------------------------------- |
+ * | ---------------------------------------------------- |
+ * | Type: | EnumComboViewer |v| |
+ * | ---------------------------------------------------- |
+ * | > Details
+ * | ---------------------------------------------------- |
+ * | Column Definition: | I | |
+ * | ---------------------------------------------------- |
+ * | ------------- |
+ * | Length: | I |I| |
+ * | ------------- |
+ * -----------------------------------------------------------------------------</pre>
+ *
+ * @see Entity
+ * @see AbstractEntityComposite - The parent container
+ * @see ColumnCombo
+ * @see EnumComboViewer
+ * @see PrimaryKeyJoinColumnsComposite
+ *
+ * @version 2.0
+ * @since 2.0
+ */
+public class HibernateDiscriminatorColumnComposite <T extends HibernateEntity> extends FormPane<T> {
+
+ /**
+ * Creates a new <code>InheritanceComposite</code>.
+ *
+ * @param parentPane The parent container of this one
+ * @param parent The parent container
+ */
+ public HibernateDiscriminatorColumnComposite(FormPane<? extends T> parentPane,
+ Composite parent) {
+
+ super(parentPane, parent, false);
+ }
+
+ @Override
+ protected void initializeLayout(Composite container) {
+ // Discriminator Column sub-pane
+ Composite discriminatorColumnContainer = addTitledGroup(
+ addSubPane(container, 10),
+ JptUiMappingsMessages.InheritanceComposite_discriminatorColumnGroupBox
+ );
+
+ PropertyValueModel<DiscriminatorColumn> discriminatorColumnHolder =
+ buildDiscriminatorColumnHolder();
+
+ // Name widgets
+ addLabeledComposite(
+ discriminatorColumnContainer,
+ JptUiMappingsMessages.DiscriminatorColumnComposite_name,
+ addDiscriminatorColumnCombo(container, discriminatorColumnHolder),
+ JpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_COLUMN
+ );
+
+ // Formula widgets
+ addLabeledMultiLineText(
+ discriminatorColumnContainer,
+ HibernateUIMappingMessages.HibernateDiscriminatorColumnComposite_formula,
+ buildDiscriminatorFormulaHolder(),
+ 2,
+ null//TODO help
+ );
+
+ // Discriminator Type widgets
+ addLabeledComposite(
+ discriminatorColumnContainer,
+ JptUiMappingsMessages.DiscriminatorColumnComposite_discriminatorType,
+ addDiscriminatorTypeCombo(container, discriminatorColumnHolder),
+ JpaHelpContextIds.ENTITY_INHERITANCE_DISCRIMINATOR_TYPE
+ );
+
+ container = addCollapsableSubSection(
+ discriminatorColumnContainer,
+ JptUiMappingsMessages.InheritanceComposite_detailsGroupBox,
+ new SimplePropertyValueModel<Boolean>(Boolean.FALSE)
+ );
+
+ new DetailsComposite(this, discriminatorColumnHolder, addSubPane(container, 0, 16));
+
+ new PaneEnabler(buildDiscriminatorColumnEnabledHolder(), this);
+ }
+
+
+ private ColumnCombo<DiscriminatorColumn> addDiscriminatorColumnCombo(
+ Composite container,
+ PropertyValueModel<DiscriminatorColumn> discriminatorColumnHolder) {
+
+ return new ColumnCombo<DiscriminatorColumn>(
+ this,
+ discriminatorColumnHolder,
+ container)
+ {
+
+ @Override
+ protected void addPropertyNames(Collection<String> propertyNames) {
+ super.addPropertyNames(propertyNames);
+ propertyNames.add(NamedColumn.SPECIFIED_NAME_PROPERTY);
+ propertyNames.add(NamedColumn.DEFAULT_NAME_PROPERTY);
+ }
+
+ @Override
+ protected String getDefaultValue() {
+ return getSubject().getDefaultName();
+ }
+
+ @Override
+ protected void setValue(String value) {
+ getSubject().setSpecifiedName(value);
+ }
+
+ @Override
+ protected Table getDbTable_() {
+ return getSubject().getDbTable();
+ }
+
+ @Override
+ protected String getValue() {
+ return getSubject().getSpecifiedName();
+ }
+
+ @Override
+ protected String buildNullDefaultValueEntry() {
+ return JptUiMappingsMessages.NoneSelected;
+ }
+ };
+ }
+
+
+ private PropertyValueModel<DiscriminatorColumn> buildDiscriminatorColumnHolder() {
+ return new PropertyAspectAdapter<Entity, DiscriminatorColumn>(getSubjectHolder()) {
+ @Override
+ protected DiscriminatorColumn buildValue_() {
+ return this.subject.getDiscriminatorColumn();
+ }
+ };
+ }
+
+
+ private WritablePropertyValueModel<String> buildDiscriminatorFormulaHolder() {
+ return new PropertyAspectAdapter<HibernateEntity, String>(getSubjectHolder(), DiscriminatorFormula.VALUE_PROPERTY) {
+ @Override
+ protected String buildValue_() {
+ return this.subject.getDiscriminatorFormula().getValue();
+ }
+
+ @Override
+ protected void setValue_(String value) {
+ this.subject.getDiscriminatorFormula().setValue(value);
+ }
+ };
+ }
+
+ private EnumFormComboViewer<DiscriminatorColumn, DiscriminatorType> addDiscriminatorTypeCombo(
+ Composite container,
+ PropertyValueModel<DiscriminatorColumn> discriminatorColumnHolder) {
+
+ return new EnumFormComboViewer<DiscriminatorColumn, DiscriminatorType>(
+ this,
+ discriminatorColumnHolder,
+ container)
+ {
+ @Override
+ protected void addPropertyNames(Collection<String> propertyNames) {
+ super.addPropertyNames(propertyNames);
+ propertyNames.add(DiscriminatorColumn.DEFAULT_DISCRIMINATOR_TYPE_PROPERTY);
+ propertyNames.add(DiscriminatorColumn.SPECIFIED_DISCRIMINATOR_TYPE_PROPERTY);
+ }
+
+ @Override
+ protected DiscriminatorType[] getChoices() {
+ return DiscriminatorType.values();
+ }
+
+ @Override
+ protected DiscriminatorType getDefaultValue() {
+ return getSubject().getDefaultDiscriminatorType();
+ }
+
+ @Override
+ protected String displayString(DiscriminatorType value) {
+ return buildDisplayString(
+ JptUiMappingsMessages.class,
+ DiscriminatorColumnComposite.class,
+ value
+ );
+ }
+
+ @Override
+ protected String nullDisplayString() {
+ return JptUiMappingsMessages.NoneSelected;
+ }
+
+ @Override
+ protected DiscriminatorType getValue() {
+ return getSubject().getSpecifiedDiscriminatorType();
+ }
+
+ @Override
+ protected void setValue(DiscriminatorType value) {
+ getSubject().setSpecifiedDiscriminatorType(value);
+ }
+ };
+ }
+
+ protected WritablePropertyValueModel<Boolean> buildDiscriminatorColumnEnabledHolder() {
+ return new PropertyAspectAdapter<Entity, Boolean>(getSubjectHolder(), Entity.SPECIFIED_DISCRIMINATOR_COLUMN_IS_ALLOWED_PROPERTY) {
+ @Override
+ protected Boolean buildValue_() {
+ return Boolean.valueOf(this.subject.specifiedDiscriminatorColumnIsAllowed());
+ }
+ };
+ }
+
+ protected class DetailsComposite extends FormPane<DiscriminatorColumn> {
+ public DetailsComposite(FormPane<?> parentPane,
+ PropertyValueModel<? extends DiscriminatorColumn> subjectHolder,
+ Composite parent) {
+
+ super(parentPane, subjectHolder, parent, false);
+ }
+
+ @Override
+ protected void initializeLayout(Composite container) {
+ // Length widgets
+ Spinner lengthSpinner = addLabeledSpinner(
+ container,
+ JptUiMappingsMessages.ColumnComposite_length,
+ buildLengthHolder(),
+ -1,
+ -1,
+ Integer.MAX_VALUE,
+ addDefaultLengthLabel(container),
+ JpaHelpContextIds.MAPPING_COLUMN_LENGTH
+ );
+
+ updateGridData(container, lengthSpinner);
+
+ // Column Definition widgets
+ addLabeledText(
+ container,
+ JptUiMappingsMessages.ColumnComposite_columnDefinition,
+ buildColumnDefinitionHolder(getSubjectHolder())
+ );
+ }
+
+ private WritablePropertyValueModel<Integer> buildLengthHolder() {
+
+ return new PropertyAspectAdapter<DiscriminatorColumn, Integer>(getSubjectHolder(), DiscriminatorColumn.SPECIFIED_LENGTH_PROPERTY) {
+ @Override
+ protected Integer buildValue_() {
+ return this.subject.getSpecifiedLength();
+ }
+
+ @Override
+ protected void setValue_(Integer value) {
+ if (value.intValue() == -1) {
+ value = null;
+ }
+ this.subject.setSpecifiedLength(value);
+ }
+ };
+ }
+
+ private Control addDefaultLengthLabel(Composite container) {
+
+ Label label = addLabel(
+ container,
+ JptUiMappingsMessages.DefaultEmpty
+ );
+
+ new LabeledControlUpdater(
+ new LabeledLabel(label),
+ buildDefaultLengthLabelHolder()
+ );
+
+ return label;
+ }
+
+ private PropertyValueModel<String> buildDefaultLengthLabelHolder() {
+
+ return new TransformationPropertyValueModel<Integer, String>(buildDefaultLengthHolder()) {
+
+ @Override
+ protected String transform(Integer value) {
+
+ int defaultValue = (getSubject() != null) ? getSubject().getDefaultLength() :
+ DiscriminatorColumn.DEFAULT_LENGTH;
+
+ return NLS.bind(
+ JptUiMappingsMessages.DefaultWithOneParam,
+ Integer.valueOf(defaultValue)
+ );
+ }
+ };
+ }
+
+ private WritablePropertyValueModel<Integer> buildDefaultLengthHolder() {
+ return new PropertyAspectAdapter<DiscriminatorColumn, Integer>(getSubjectHolder(), DiscriminatorColumn.DEFAULT_LENGTH_PROPERTY) {
+ @Override
+ protected Integer buildValue_() {
+ return Integer.valueOf(this.subject.getDefaultLength());
+ }
+
+ @Override
+ protected synchronized void subjectChanged() {
+ Object oldValue = this.getValue();
+ super.subjectChanged();
+ Object newValue = this.getValue();
+
+ // Make sure the default value is appended to the text
+ if (oldValue == newValue && newValue == null) {
+ this.fireAspectChange(Integer.valueOf(Integer.MIN_VALUE), newValue);
+ }
+ }
+ };
+ }
+
+ private WritablePropertyValueModel<String> buildColumnDefinitionHolder(PropertyValueModel<DiscriminatorColumn> discriminatorColumnHolder) {
+
+ return new PropertyAspectAdapter<DiscriminatorColumn, String>(discriminatorColumnHolder, NamedColumn.COLUMN_DEFINITION_PROPERTY) {
+ @Override
+ protected String buildValue_() {
+ return this.subject.getColumnDefinition();
+ }
+
+ @Override
+ protected void setValue_(String value) {
+ if (value.length() == 0) {
+ value = null;
+ }
+ this.subject.setColumnDefinition(value);
+ }
+ };
+ }
+
+ /**
+ * Changes the layout of the given container by changing which widget will
+ * grab the excess of horizontal space. By default, the center control grabs
+ * the excess space, we change it to be the right control.
+ *
+ * @param container The container containing the controls needing their
+ * <code>GridData</code> to be modified from the default values
+ * @param spinner The spinner that got created
+ */
+ private void updateGridData(Composite container, Spinner spinner) {
+
+ // It is possible the spinner's parent is not the container of the
+ // label, spinner and right control (a pane is sometimes required for
+ // painting the spinner's border)
+ Composite paneContainer = spinner.getParent();
+
+ while (container != paneContainer.getParent()) {
+ paneContainer = paneContainer.getParent();
+ }
+
+ Control[] controls = paneContainer.getChildren();
+
+ GridData gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = false;
+ gridData.horizontalAlignment = GridData.BEGINNING;
+ controls[1].setLayoutData(gridData);
+
+ controls[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ removeAlignRight(controls[2]);
+ }
+
+ }
+}
\ No newline at end of file
Property changes on: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateDiscriminatorColumnComposite.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateJavaEntityComposite.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateJavaEntityComposite.java 2009-07-29 13:24:09 UTC (rev 16873)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateJavaEntityComposite.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -10,13 +10,13 @@
******************************************************************************/
package org.jboss.tools.hibernate.jpt.ui.internal.java.details;
-import org.eclipse.jpt.core.context.java.JavaEntity;
import org.eclipse.jpt.ui.WidgetFactory;
import org.eclipse.jpt.ui.internal.java.details.JavaEntityComposite;
import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages;
import org.eclipse.jpt.ui.internal.widgets.Pane;
import org.eclipse.jpt.utility.model.value.PropertyValueModel;
import org.eclipse.swt.widgets.Composite;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaEntity;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateQueryContainer;
import org.jboss.tools.hibernate.jpt.ui.internal.mapping.details.HibernateGeneratorsComposite;
import org.jboss.tools.hibernate.jpt.ui.internal.mapping.details.HibernateQueriesComposite;
@@ -25,14 +25,14 @@
* @author Dmitry Geraskov
*
*/
-public class HibernateJavaEntityComposite<HibernateJavaEntity> extends JavaEntityComposite {
+public class HibernateJavaEntityComposite extends JavaEntityComposite {
/**
* @param subjectHolder
* @param parent
* @param widgetFactory
*/
- public HibernateJavaEntityComposite(PropertyValueModel<? extends JavaEntity> subjectHolder,
+ public HibernateJavaEntityComposite(PropertyValueModel<? extends HibernateJavaEntity> subjectHolder,
Composite parent, WidgetFactory widgetFactory) {
super(subjectHolder, parent, widgetFactory);
}
@@ -57,5 +57,10 @@
new HibernateGeneratorsComposite(this, container);
}
+
+ @Override
+ protected void addInheritanceComposite(Composite container) {
+ new HibernateJavaInheritanceComposite(this, container);
+ }
}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateJavaInheritanceComposite.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateJavaInheritanceComposite.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateJavaInheritanceComposite.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.ui.internal.java.details;
+
+import org.eclipse.jpt.core.context.java.JavaEntity;
+import org.eclipse.jpt.ui.internal.java.details.JavaPrimaryKeyJoinColumnsComposite;
+import org.eclipse.jpt.ui.internal.widgets.FormPane;
+import org.eclipse.swt.widgets.Composite;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaEntity;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class HibernateJavaInheritanceComposite extends HibernateAbstractInheritanceComposite<HibernateJavaEntity> {
+
+ @SuppressWarnings("unchecked")
+ public HibernateJavaInheritanceComposite(FormPane<? extends JavaEntity> parentPane,
+ Composite parent) {
+ super((FormPane<? extends HibernateJavaEntity>) parentPane, parent);
+ }
+
+ protected void addPrimaryKeyJoinColumnsComposite(Composite container) {
+ new JavaPrimaryKeyJoinColumnsComposite(this, container);
+ }
+}
Property changes on: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/java/details/HibernateJavaInheritanceComposite.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/mapping/details/HibernateUIMappingMessages.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/mapping/details/HibernateUIMappingMessages.java 2009-07-29 13:24:09 UTC (rev 16873)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/mapping/details/HibernateUIMappingMessages.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -43,6 +43,7 @@
public static String NameStateObject_nameAlreadyExists;
public static String HibernateIdMappingComposite_genericGeneratorSection;
public static String HibernateIdMappingComposite_genericGeneratorCheckBox;
+ public static String HibernateDiscriminatorColumnComposite_formula;
private HibernateUIMappingMessages() {}
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/mapping/details/messages.properties
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/mapping/details/messages.properties 2009-07-29 13:24:09 UTC (rev 16873)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/mapping/details/messages.properties 2009-07-29 14:14:03 UTC (rev 16874)
@@ -20,4 +20,5 @@
NameStateObject_nameMustBeSpecified=A name must be specified
NameStateObject_nameAlreadyExists=The name already exists.
HibernateIdMappingComposite_genericGeneratorSection=Generic Generator
-HibernateIdMappingComposite_genericGeneratorCheckBox=Generic generator
\ No newline at end of file
+HibernateIdMappingComposite_genericGeneratorCheckBox=Generic generator
+HibernateDiscriminatorColumnComposite_formula=Formula:
\ No newline at end of file
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/platform/HibernateJpaUiFactory.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/platform/HibernateJpaUiFactory.java 2009-07-29 13:24:09 UTC (rev 16873)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/platform/HibernateJpaUiFactory.java 2009-07-29 14:14:03 UTC (rev 16874)
@@ -70,10 +70,11 @@
return new HibernateIdMappingComposite((PropertyValueModel<? extends HibernateJavaIdMapping>) subjectHolder, parent, widgetFactory);
}
+ @SuppressWarnings("unchecked")
@Override
public JpaComposite createJavaEntityComposite(PropertyValueModel<JavaEntity> subjectHolder,
Composite parent, WidgetFactory widgetFactory) {
- return new HibernateJavaEntityComposite<HibernateJavaEntity>(subjectHolder, parent, widgetFactory);
+ return new HibernateJavaEntityComposite((PropertyValueModel<? extends HibernateJavaEntity>) subjectHolder, parent, widgetFactory);
}
private PropertyValueModel<BasicHibernateProperties> buildBasicHolder(
15 years, 5 months
JBoss Tools SVN: r16873 - in trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp: outline and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2009-07-29 09:24:09 -0400 (Wed, 29 Jul 2009)
New Revision: 16873
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPDialogContentProposalProvider.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPDialogCellEditor.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4675
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPDialogContentProposalProvider.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPDialogContentProposalProvider.java 2009-07-29 13:17:32 UTC (rev 16872)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPDialogContentProposalProvider.java 2009-07-29 13:24:09 UTC (rev 16873)
@@ -11,6 +11,7 @@
package org.jboss.tools.jst.jsp.contentassist;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Properties;
@@ -18,9 +19,12 @@
import org.eclipse.jface.fieldassist.IContentProposal;
import org.eclipse.jface.fieldassist.IContentProposalProvider;
import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jst.jsp.ui.internal.contentassist.JSPContentAssistProcessor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceCompletionProposal;
+import org.eclipse.wst.sse.ui.internal.util.Sorter;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
import org.jboss.tools.common.el.core.model.ELInstance;
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
@@ -86,11 +90,25 @@
public IContentProposal[] getProposals(String contents, int position) {
List<IContentProposal> result = new ArrayList<IContentProposal>();
+ if(contents.indexOf('{') < 0) {
+ KbQuery kbQuery = createKbQuery(Type.ATTRIBUTE_VALUE, contents, contents, position, false);
+ TextProposal[] proposals = PageProcessor.getInstance().getProposals(kbQuery, pageContext);
+ if(proposals != null) for (TextProposal textProposal: proposals) {
+ String displayString = textProposal.getReplacementString();
+ int cursorPosition = /*replacementOffset + */ textProposal.getReplacementString().length();
+
+ Image image = textProposal.getImage();
+
+ IContentProposal proposal = //new ContentProposal(replacementString, replacementOffset, replacementLength, cursorPosition, image, displayString, contextInformation, additionalProposalInfo, relevance);
+ new ContentProposal(textProposal.getReplacementString(), cursorPosition, displayString, displayString);
+ result.add(proposal);
+ }
+ }
TextRegion prefix = getELPrefix(contents, position);
if (prefix == null || !prefix.isELStarted()) {
IContentProposal proposal = new ContentProposal("#{}", 0, "#{}", JstUIMessages.JSPDialogContentProposalProvider_NewELExpression); //$NON-NLS-1$ //$NON-NLS-2$
result.add(proposal);
- return result.toArray(new IContentProposal[0]);
+ return toSortedUniqueArray(result);
}
String matchString = "#{" + prefix.getText(); //$NON-NLS-1$
String query = matchString;
@@ -128,10 +146,72 @@
IContentProposal proposal = new ContentProposal("}", 0, "}", JstUIMessages.JSPDialogContentProposalProvider_CloseELExpression); //$NON-NLS-1$ //$NON-NLS-2$
result.add(proposal);
}
-
- return result.toArray(new IContentProposal[0]);
+ return toSortedUniqueArray(result);
}
+ public IContentProposal[] makeUnique(IContentProposal[] proposals) {
+ HashSet<String> present = new HashSet<String>();
+ HashSet<String> info = new HashSet<String>();
+ ArrayList<IContentProposal> unique= new ArrayList<IContentProposal>();
+
+ for (int i = 0; proposals != null && i < proposals.length; i++) {
+ String infoUnquoted = proposals[i].getContent();
+ if (infoUnquoted != null) {
+ if (infoUnquoted.startsWith("\""))
+ infoUnquoted = infoUnquoted.substring(1);
+ if (infoUnquoted.endsWith("\""))
+ infoUnquoted = infoUnquoted.substring(0, infoUnquoted.length() - 1);
+ infoUnquoted = infoUnquoted.trim();
+ }
+ if (!present.contains(proposals[i].getLabel())) {
+ present.add(proposals[i].getLabel());
+ if (infoUnquoted != null && infoUnquoted.length() > 0) {
+ if (!info.contains(infoUnquoted)) {
+ info.add(infoUnquoted);
+ } else {
+ // Do not add proposals with the same info
+ continue;
+ }
+ }
+ unique.add(proposals[i]);
+ }
+ }
+
+ present.clear();
+ return unique.toArray(new IContentProposal[unique.size()]);
+ }
+
+ IContentProposal[] toSortedUniqueArray(List<IContentProposal> result) {
+ IContentProposal[] resultArray = result.toArray(new IContentProposal[0]);
+ if(resultArray.length < 2) return resultArray;
+ Object[] sorted = createSorter().sort(resultArray);
+ System.arraycopy(sorted, 0, resultArray, 0, sorted.length);
+ resultArray = makeUnique(resultArray);
+ return resultArray;
+ }
+
+ protected Sorter createSorter() {
+ return new Sorter() {
+ public boolean compare(Object proposal1, Object proposal2) {
+
+ int pr1 = Integer.MIN_VALUE;
+ int pr2 = Integer.MIN_VALUE;
+
+ IContentProposal p1 = (IContentProposal)proposal1;
+ IContentProposal p2 = (IContentProposal)proposal2;
+
+ if (pr1 == pr2) {
+ String str1 = (p1.getLabel() == null ? "" : p1.getLabel()); //$NON-NLS-1$
+ String str2 = (p2.getLabel() == null ? "" : p2.getLabel()); //$NON-NLS-1$
+ return str2.compareTo(str1) > 0;
+ }
+
+ return (pr1 > pr2);
+ }
+ };
+ }
+
+
class ContentProposal implements IContentProposal {
String content;
int pos;
@@ -209,7 +289,8 @@
kbQuery.setParent(attributeName);
kbQuery.setMask(true);
kbQuery.setType(type);
- kbQuery.setOffset(pos);
+// kbQuery.setOffset(pos);
+ kbQuery.setOffset(offset);
kbQuery.setValue(query);
kbQuery.setStringQuery(stringQuery);
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPDialogCellEditor.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPDialogCellEditor.java 2009-07-29 13:17:32 UTC (rev 16872)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPDialogCellEditor.java 2009-07-29 13:24:09 UTC (rev 16873)
@@ -45,8 +45,7 @@
public class JSPDialogCellEditor extends DialogCellEditorEx implements ExtendedCellEditorProvider.StoppableCellEditor {
Properties context;
- // ValueHelper valueHelper;
-// ContentAssistHandler handler = null;
+ JSPDialogContentProposalProvider cpp;
boolean hasProposals = false;
/**
@@ -81,7 +80,9 @@
return;
}
- JSPDialogContentProposalProvider cpp = new JSPDialogContentProposalProvider();
+ if(cpp == null) {
+ cpp = new JSPDialogContentProposalProvider();
+ }
cpp.setContext(context);
IContentProposal[] ps = cpp.getProposals("#{}", 2); //$NON-NLS-1$
hasProposals = ((ps != null) && (ps.length > 0));
@@ -179,7 +180,7 @@
protected void addContentAssist(Text text) {
IControlContentAdapter controlAdapter = new TextContentAdapter();
- JSPDialogContentProposalProvider cpp = new JSPDialogContentProposalProvider();
+ cpp = new JSPDialogContentProposalProvider();
cpp.setContext(context);
ContentProposalAdapter adapter = new ContentProposalAdapter(
15 years, 5 months
JBoss Tools SVN: r16872 - workspace/yzhishko/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test.
by jbosstools-commits@lists.jboss.org
Author: yzhishko
Date: 2009-07-29 09:17:32 -0400 (Wed, 29 Jul 2009)
New Revision: 16872
Modified:
workspace/yzhishko/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/TestDomUtil.java
Log:
Method to clear \r symbols what comes from xulrunner.64 in #comments nodes was added.
Modified: workspace/yzhishko/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/TestDomUtil.java
===================================================================
--- workspace/yzhishko/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/TestDomUtil.java 2009-07-29 13:16:46 UTC (rev 16871)
+++ workspace/yzhishko/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/TestDomUtil.java 2009-07-29 13:17:32 UTC (rev 16872)
@@ -135,13 +135,30 @@
+ vpeNode.getNodeName() + "\"but must be \"" //$NON-NLS-1$
+ modelNode.getNodeName() + "\""); //$NON-NLS-1$
}
- if ((modelNode.getNodeValue() != null)
- && (!modelNode.getNodeValue().trim().equalsIgnoreCase(
- vpeNode.getNodeValue().trim()))) {
- throw new ComparisonException("value of " + vpeNode.getNodeName() //$NON-NLS-1$
- + " is \"" + vpeNode.getNodeValue().trim() //$NON-NLS-1$
- + "\" but must be \"" + modelNode.getNodeValue().trim() //$NON-NLS-1$
- + "\""); //$NON-NLS-1$
+
+ if ("#comment".equals(vpeNode.getNodeName())){
+ String vpeNodeValue = vpeNode.getNodeValue();
+ try {
+ vpeNodeValue = clearStringFromRSymbols(vpeNodeValue);
+ } catch (Exception e) {
+ }
+ if ((modelNode.getNodeValue() != null)
+ && (!modelNode.getNodeValue().trim().equalsIgnoreCase(
+ vpeNodeValue.trim()))) {
+ throw new ComparisonException("value of " + vpeNode.getNodeName() //$NON-NLS-1$
+ + " is \"" + vpeNodeValue.trim() //$NON-NLS-1$
+ + "\" but must be \"" + modelNode.getNodeValue().trim() //$NON-NLS-1$
+ + "\""); //$NON-NLS-1$
+ }
+ } else {
+ if ((modelNode.getNodeValue() != null)
+ && (!modelNode.getNodeValue().trim().equalsIgnoreCase(
+ vpeNode.getNodeValue().trim()))) {
+ throw new ComparisonException("value of " + vpeNode.getNodeName() //$NON-NLS-1$
+ + " is \"" + vpeNode.getNodeValue().trim() //$NON-NLS-1$
+ + "\" but must be \"" + modelNode.getNodeValue().trim() //$NON-NLS-1$
+ + "\""); //$NON-NLS-1$
+ }
}
// compare node's attributes
if (modelNode.getNodeType() == Node.ELEMENT_NODE) {
@@ -275,5 +292,16 @@
}
}
-
+
+ private static String clearStringFromRSymbols(String string){
+ int index = string.indexOf("\r");
+ while (index!=-1) {
+ String stringAfterSymbol = string.substring(index+1);
+ String stringBeforeSymbol = string.substring(0,index);
+ string = stringBeforeSymbol.concat(stringAfterSymbol);
+ index = string.indexOf("\r");
+ }
+ return string;
+ }
+
}
15 years, 5 months
JBoss Tools SVN: r16871 - in trunk/seam: tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: dazarov
Date: 2009-07-29 09:16:46 -0400 (Wed, 29 Jul 2009)
New Revision: 16871
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamComponentRefactoringTest.java
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamContextVariableRefactoringTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-1077
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java 2009-07-29 12:43:46 UTC (rev 16870)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProcessor.java 2009-07-29 13:16:46 UTC (rev 16871)
@@ -699,8 +699,8 @@
for (IProject project : projects) {
ISeamProject sProject = SeamCorePlugin.getSeamProject(project, true);
if(sProject != null){
- findAnnotations(sProject, BijectedAttributeType.OUT, ISeamXmlComponentDeclaration.NAME/*SeamAnnotations.OUT_ANNOTATION_TYPE*/);
- findAnnotations(sProject, BijectedAttributeType.DATA_BINDER, ISeamXmlComponentDeclaration.NAME/*SeamAnnotations.DATA_MODEL_ANNOTATION_TYPE*/);
+ findAnnotations(sProject, BijectedAttributeType.OUT, SeamAnnotations.OUT_ANNOTATION_TYPE);
+ findAnnotations(sProject, BijectedAttributeType.DATA_BINDER, SeamAnnotations.DATA_MODEL_ANNOTATION_TYPE);
findFactories(sProject);
}
}
Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamComponentRefactoringTest.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamComponentRefactoringTest.java 2009-07-29 12:43:46 UTC (rev 16870)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamComponentRefactoringTest.java 2009-07-29 13:16:46 UTC (rev 16871)
@@ -94,7 +94,7 @@
}
private void renameComponent(ISeamProject seamProject, String componentName, String newName, List<TestChangeStructure> changeList, boolean fromJar) throws CoreException{
- JobUtils.waitForIdle(2000);
+ JobUtils.waitForIdle(3000);
// Test before renaming
ISeamComponent component = seamProject.getComponent(componentName);
Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamContextVariableRefactoringTest.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamContextVariableRefactoringTest.java 2009-07-29 12:43:46 UTC (rev 16870)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamContextVariableRefactoringTest.java 2009-07-29 13:16:46 UTC (rev 16871)
@@ -174,11 +174,11 @@
renameContextVariable(seamEjbProject, "/WebContent/out.jsp", "aaa", "bbb", list);
}
- public void t_estSeamContextVariable_Out2_Rename() throws CoreException {
+ public void testSeamContextVariable_Out2_Rename() throws CoreException {
ArrayList<TestChangeStructure> list = new ArrayList<TestChangeStructure>();
TestChangeStructure structure = new TestChangeStructure(ejbProject.getProject(), "/ejbModule/org/domain/"+warProjectName+"/session/TestContextVariableOut.java");
- TestTextChange change = new TestTextChange(528, 5, "\"eee\"");
+ TestTextChange change = new TestTextChange(516, 5, "\"eee\"");
structure.addTextChange(change);
list.add(structure);
@@ -206,16 +206,16 @@
renameContextVariable(seamEjbProject, "/WebContent/datamodel.jsp", "data", "dada", list);
}
- public void t_estSeamContextVariable_DataModel2_Rename() throws CoreException {
+ public void testSeamContextVariable_DataModel2_Rename() throws CoreException {
ArrayList<TestChangeStructure> list = new ArrayList<TestChangeStructure>();
TestChangeStructure structure = new TestChangeStructure(ejbProject.getProject(), "/ejbModule/org/domain/"+warProjectName+"/session/TestContextVariableDataModel.java");
- TestTextChange change = new TestTextChange(528, 7, "\"modal\"");
+ TestTextChange change = new TestTextChange(551, 7, "\"modal\"");
structure.addTextChange(change);
list.add(structure);
structure = new TestChangeStructure(warProject, "/WebContent/datamodel.jsp");
- change = new TestTextChange(283, 5, "modal");
+ change = new TestTextChange(284, 5, "modal");
structure.addTextChange(change);
list.add(structure);
15 years, 5 months
JBoss Tools SVN: r16870 - trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2009-07-29 08:43:46 -0400 (Wed, 29 Jul 2009)
New Revision: 16870
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamPromptingProvider.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4675
TODO comment removed
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamPromptingProvider.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamPromptingProvider.java 2009-07-29 12:42:30 UTC (rev 16869)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamPromptingProvider.java 2009-07-29 12:43:46 UTC (rev 16870)
@@ -58,7 +58,6 @@
list.addAll(set);
return list;
} else if(MEMBERS.equals(id)) {
- //TODO either refactor or remove this class
try {
List<TextProposal> proposals = engine.getCompletions(f, null, prefix, prefix.length(), false, new ArrayList<Var>());
List<String> suggestions = new ArrayList<String>();
15 years, 5 months
JBoss Tools SVN: r16869 - trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2009-07-29 08:42:30 -0400 (Wed, 29 Jul 2009)
New Revision: 16869
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPTreeDialog.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4675
Selection in tree on double mouse click added.
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPTreeDialog.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPTreeDialog.java 2009-07-29 12:41:41 UTC (rev 16868)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/outline/JSPTreeDialog.java 2009-07-29 12:42:30 UTC (rev 16869)
@@ -114,6 +114,13 @@
}
}
});
+ treeViewer.addDoubleClickListener(new IDoubleClickListener(){
+ public void doubleClick(DoubleClickEvent event) {
+ if(getCommandBar().isEnabled(OK)) {
+ action(OK);
+ }
+ }
+ });
return treeViewer.getControl();
}
15 years, 5 months