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();
- }
-
-}